COREKIT_PATH = ./Corekit #path of corekit folder
FLAGS = -Wall -Werror -Wextra -g
INCLUDES = -I$(COREKIT_PATH)/includes #path of includes folder in corekit
%.o: %.c
cc $(FLAGS) $(INCLUDES) -c $< -o $@
$(NAME): $(OBJ)
$(MAKE) -sC $(COREKIT_PATH) #execute make in corekit folder in silent mode
cc $(FLAGS) $(INCLUDES) $(OBJ) -L$(COREKIT_PATH) -lcorekit -o $(NAME)
#-lcorekit: includes library name (libcorekit)
#-L$(COREKIT_PATH): link the specified directory to main compilation
clean:
@${MAKE} -C corekit clean
fclean: clean
@${MAKE} -C corekit fclean -s
In this example the project structure is:
.
├── main.c
├── makefile
├── corekit ▼
│ ├── Makefile
│ ├── README.md
│ ├── includes ►
│ └── src ►
The library (.a file) is called libcorekit.a beacause all the library during compilation must start with 'lib' prefix
$@ rename with target file name and in the directory of c original file
$< takes the firts prerequisite, so the c file
-c flag is used to generate .o file
%.o: %.c
@$(COMPILE) -c $< -Iincludes -o $@
-c $< means that the compiler should compile the source file specified by the first prerequisite without linking it, resulting in the generation of an object file
-Iincludes includes the 'includes' folder that contain all the headers that are to be included
R=\033[0m isn't a color but 's a control code to reset the text attributes to the default, including color.