mirror of
https://github.com/Hizenberg469/Makefile-tutorial.git
synced 2026-04-19 22:02:24 +03:00
51 lines
1.2 KiB
Makefile
51 lines
1.2 KiB
Makefile
BINARY=bin
|
|
CODEDIRS=. lib
|
|
INCDIRS=. ./include/ # can be list
|
|
|
|
CC=gcc
|
|
OPT=-O0
|
|
#generate files that encode make rules for the .h dependencies
|
|
DEPFLAGS=-MP -MD
|
|
#automatically add the -I onto each include directory
|
|
CFLAGS=-Wall -Wextra -g $(foreach D,$(INCDIRS),-I$(D)) $(OPT) $(DEPFLAGS)
|
|
|
|
# for-style iteration (foreach) and regular expression completions (wildcard)
|
|
CFILES=$(foreach D, $(CODEDIRS),$(wildcard $(D)/*.c))
|
|
# regular expression replacement
|
|
OBJECTS=$(patsubst %.c,%.o,$(CFILES))
|
|
DEPFILES=$(patsubst %.c,%.d,$(CFILES))
|
|
|
|
all: $(BINARY)
|
|
|
|
$(BINARY): $(OBJECTS)
|
|
$(CC) -o $@ $^
|
|
|
|
all: $(BINARY)
|
|
|
|
$(BINARY): $(OBJECTS)
|
|
$(CC) -o $@ $^
|
|
|
|
# only want the .c file dependency here, thus $< instead of $^.
|
|
#
|
|
%.o:%.c
|
|
$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
clean:
|
|
rm -rf $(BINARY) $(OBJECTS) $(DEPFILES)
|
|
|
|
# shell commands are a set of keystrokes away
|
|
distribute: clean
|
|
tar zcvf dist.tgz *
|
|
|
|
# @ silences the printing of the command
|
|
# $(info ...) prints output
|
|
diff:
|
|
$(info The status of the repository, and the volume of per-file changes:)
|
|
@git status
|
|
@git diff --stat
|
|
|
|
# include the dependencies
|
|
-include $(DEPFILES)
|
|
|
|
# add .PHONY so that the non-targetfile - rules work even if a file with the same name exists.
|
|
.PHONY: all clean distribute diff |