-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
97 lines (74 loc) · 2.08 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
include conf.mk
ifndef DEBUG
DEBUG=yes
endif
ifeq ($(DEBUG), yes)
FLAGS+=-g
VERSION:=$(VERSION)-debug
else
WARNINGS+=error
FLAGS+=-O2
endif
DFLAGS=$(addprefix -D, $(DEFINES)) \
-DCOMPILETIME='$(shell date +"%Y-%m-%d %H:%M %z")' \
-DVERSION='$(VERSION)'
WFLAGS=$(addprefix -W, $(WARNINGS))
FLAGS+=$(WFLAGS) --std=$(STD) -pedantic -pthread -I$(INCDIR) -fPIC -fdiagnostics-color=always $(DFLAGS)
HFILES=$(addprefix $(INCDIR), $(addsuffix .h, $(FILES)))
CFILES=$(addprefix $(SRCDIR), $(addsuffix .c, $(FILES)))
OFILES=$(addprefix $(OBJDIR), $(addsuffix .o, $(FILES)))
ifeq ($(DEBUG), yes)
ERRPIPE=2>&1 | tee -a errs.txt || (less -R errs.txt && /bin/false)
else
ERRPIPE=
endif
DEPMATCH=^\S+\.o: $(SRCDIR)(\S+)\.c
DEPREPL=$(OBJDIR)\1\.o: $(SRCDIR)\1\.c
DEPCMD=sed -re "s/$(subst /,\\/,$(DEPMATCH))/$(subst /,\\/,$(DEPREPL))/"
$(DEPFILE): $(CFILES) $(HFILES)
@$(CC) -MM $(FLAGS) $^ | $(DEPCMD) > $@
@printf "Built dependencies\n"
$(OBJDIR)%.o: $(SRCDIR)%.c conf.mk
@mkdir -p $(@D)
@$(CC) -c $(FLAGS) $< -o $@ $(ERRPIPE)
@printf "Built $@\n"
$(BINDIR)edil: $(OFILES) $(SRCDIR)edil.c
@mkdir -p $(@D)
@$(CC) $(FLAGS) $^ -o $@ $(ERRPIPE)
@printf "Built $@\n"
all: deps $(BINDIR)edil
@if [ -s errs.txt ]; then cat errs.txt | less -R; rm errs.txt; fi
install: all
@cp $(BINDIR)edil $(INSTDIR)edil
@printf "Installed edil in $(INSTDIR)edil\n"
uninstall:
@rm -f $(INSTDIR)/edil
@printf "Uninstalled edil\n"
clean_err:
@rm -f errs.txt
clean_bin:
@rm -rf $(BINDIR)
@printf "Removed $(BINDIR)\n"
clean_obj:
@rm -rf $(OBJDIR)
@printf "Removed $(OBJDIR)\n"
clean_dep:
@rm -rf $(DEPDIR)
@printf "Removed $(DEPDIR)\n"
clean_docs:
@make -C doc clean
@make -C layouts clean
docs: all
@make -C doc all
@make -C layouts all
deps: $(DEPFILE)
clean: clean_err clean_bin clean_obj clean_dep
.PHONEY=deps all clean_err clean_bin clean_obj clean_dep clean install uninstall
.DEFAULT_GOAL=all
$(shell rm -f errs.txt)
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring deps,$(MAKECMDGOALS)))
$(info Including depenendencies ...)
include $(DEPFILE)
endif
endif