Skip to content

Commit

Permalink
Fixing makefile and removing unecessary files for graphical development
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromelocf committed Oct 29, 2024
1 parent a806f76 commit 7fbb313
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 283 deletions.
83 changes: 43 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,70 +1,73 @@
# Variables
NAME := cub3D

BUILD_DIR := build/
SOURCES_DIR := sources/
OBJECTS_DIR := objects/
HEADERS_DIR := includes/
LIBRARIES_DIR := libraries/
LIBFT_DIR := $(addprefix $(LIBRARIES_DIR), lib/)
LIBFT_FILE := libft.a
LIBFT_DIR := $(addprefix $(LIBRARIES_DIR), libft/)
MLX_DIR := $(addprefix $(LIBRARIES_DIR), mlx/)

# Flags
MAKE := make
MAKE_LIBS := $(MAKE) -sC
MAKE_LIBS := make -sC
CC := cc
CFLAGS := -Wall -Wextra -Werror -Wunreachable-code -Ofast -g3
MKDIR := mkdir -p
RM := rm -rf
CMAKE := cmake

# MLX42
MLX_FILE := libmlx42.a
LIB_MLX_FLAGS := -Iinclude -ldl -lglfw -pthread -lm
LIB_MLX_SRCS := MLX42/build/libmlx42.a
MLX_BUILD := $(addprefix $(MLX_DIR), $(BUILD_DIR))
MLX := $(addprefix $(MLX_BUILD), $(MLX_FILE))

# Sources
FILES := main

SOURCES := $(addprefix $(SOURCES_DIR), $(addsuffix .c, $(FILES)))
OBJECTS := $(addprefix $(OBJECTS_DIR), $(addsuffix .o, $(FILES)))
LIBFT := $(addprefix $(LIBFT_DIR), $(LIBFT_FILE))
LIBFT_HEADER := $(addprefix $(LIBFT_DIR), includes/libft.h)
HEADERS := -I $(HEADERS_DIR)

MESSAGE1 := "------------------Compiling cub3d Objects!-------------------"
MESSAGE2 := "---------------Objects Compiled Successfully!----------------"
MESSAGE3 := "-----------------.cub3d Compiled Successfully----------------"
LIBFT_FILE := libft.a
LIBFT := $(addprefix $(LIBFT_DIR), $(LIBFT_FILE))

# Rules
.PHONY: all clean fclean re bonus
MESSAGE1 := "-----------------.cub3d Compiled Successfully----------------"

all: $(NAME)
all: libraries $(NAME)

$(NAME): $(LIBFT) $(OBJECTS)
@ echo ' '
$(NAME): $(OBJECTS)
@ $(CC) $(CFLAGS) $(OBJECTS) $(LIBFT) $(MLX) $(MLX_FLAGS) -o $(NAME)
@ echo $(MESSAGE1)
@ echo ' '
@$(CC) $(CFLAGS) $^ $(LIBFT) -o $(NAME) $(INCLUDES) $(LFLAGS)
@ echo $(MESSAGE2)
@ echo ' '
@ echo $(MESSAGE3)
@ echo ' '

cleanlibft:
@$(MAKE_LIBS) $(LIBFT_DIR) clean
$(OBJECTS_DIR)%.o: $(SOURCES_DIR)%.c
@ $(MKDIR) $(OBJECTS_DIR)
@ $(CC) $(CFLAGS) -c $< -o $@

fcleanlibft:
@$(MAKE_LIBS) $(LIBFT_DIR) fclean
libraries : $(LIBFT) $(MLX)

clean: cleanlibft
@ rm -rf $(OBJECTS_DIR)
$(LIBFT):
@ $(MAKE_LIBS) $(LIBFT_DIR)

fclean: clean fcleanlibft
@$(RM) $(NAME)
$(MLX):
@ $(CMAKE) $(MLX_DIR) -B $(MLX_BUILD) && $(MAKE_LIBS) $(MLX_BUILD) -j4

re: fclean
@$(MAKE) -s
clean: cleanlibs
@ $(RM) $(OBJECTS_DIR)

bonus: all
cleanlibs: cleanmlx cleanlibft

$(OBJECTS_DIR)%.o: $(SOURCES_DIR)%.c
@$(MKDIR) $(OBJECTS_DIR)
@$(CC) $(CFLAGS) -c $< -o $@
cleanlibft:
@ $(MAKE_LIBS) $(LIBFT_DIR) clean

libraries: $(LIBFT)
cleanmlx:
@ $(RM) $(MLX_BUILD)

$(LIBFT):
@$(MAKE_LIBS) $(LIBFT_DIR)
fclean: clean
@ $(RM) $(NAME) $(LIBFT)

re: fclean all

bonus: all

# Rules
.PHONY: all clean fclean re bonus libraries
7 changes: 6 additions & 1 deletion includes/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef CUB3D_H
# define CUB3D_H

# include "../libraries/lib/libft.h"
# include "../libraries/libft/includes/libft.h"

# define MSG_ERROR "\033[1;41mError!\033[0m\n\033[0;31m"
# define MSG_LEN_ERROR 25
Expand All @@ -22,10 +22,14 @@
# define MSG_INV_EXEC "Invalid .cub map file\n"
# define MSG_INV_TEXTURES "Invalid texture configurations\n"
# define MSG_INV_COLORS "Invalid RGB colors configurations\n"
# define MSG_INV_ARG "Invalid arguments\n"

# define MSG_ERROR_EXIT "\033[0m\n"
# define MSG_LEN_ERROR_EXIT 5

# define FALSE 0
# define TRUE 1

typedef struct s_rgb_colors
{
char *floor_color;
Expand Down Expand Up @@ -56,5 +60,6 @@ int check_rgbs(char *rgbs);
int ft_atoi_cub(const char *nptr);
void remove_line_break(char **old_string);
void handle_error(const char *message);
void error_handler(int status, char *message, t_cub3d *cub3d);

#endif
61 changes: 0 additions & 61 deletions sources/cub3d_utils.c

This file was deleted.

14 changes: 2 additions & 12 deletions sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@

int main(int argc, char **argv)
{
// t_scene scene;
(void)argc;
(void)argv;
if (argc != 2)
handle_error(MSG_ARG_COUNT);
// load_scene(&scene, ++argv);
return (EXIT_SUCCESS);
}

void handle_error(const char *message)
{
write(STDERR_FILENO, MSG_ERROR, MSG_LEN_ERROR);
write(STDERR_FILENO, message, ft_strlen(message));
write(STDERR_FILENO, MSG_ERROR_EXIT, MSG_LEN_ERROR_EXIT);
exit(EXIT_FAILURE);
return (0);
}
49 changes: 0 additions & 49 deletions sources/validate_config.c

This file was deleted.

68 changes: 0 additions & 68 deletions sources/validate_rgb.c

This file was deleted.

Loading

0 comments on commit 7fbb313

Please sign in to comment.