-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmakefile
More file actions
98 lines (82 loc) · 2.42 KB
/
makefile
File metadata and controls
98 lines (82 loc) · 2.42 KB
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
98
CC=gcc
OPT=-O2
GPROF=#-pg
GDB=#-g
W= \
-Warray-bounds\
-Wfloat-equal\
-Wimplicit\
-Wmaybe-uninitialized\
-Wmissing-braces\
-Wparentheses\
-Wsequence-point\
-Wtype-limits\
-Wundef\
-Wuninitialized\
-Wmisleading-indentation\
-Wempty-body\
-Wmemset-elt-size\
-Wduplicated-branches\
-Wswitch-unreachable\
-Wunused\
-Wunused-but-set-variable\
-Wunused-parameter\
-Winline\
-Wunsafe-loop-optimizations\
-Wno-format\
-Wswitch\
-Wdangling-pointer\
#-W -Wall\
-Wconversion\
-Wsign-compare\
-Wjump-misses-init\
#-Werror\
export VERSION_FLAGS=-DGIT_HASH="\"$(shell git rev-parse HEAD 2> /dev/null || echo --)\""\
-DGIT_BRANCH="\"$(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo --)\""\
-DBUILD_USER="\"$(USER)@$(HOSTNAME)\""\
-DBUILD_DIRECTORY="\"$(PWD)\""
OS := $(shell uname)
ifeq ($(OS),Darwin)
SONAME := install_name,@rpath/
else
SONAME := soname,
endif
X11DIR= $(shell pkg-config --libs-only-L x11 xpm) # for macOS
CFLAGS= -c -std=gnu11 $(OPT) $(GPROF) $(W) $(GDB)
OFLAGS= -lm $(GPROF) -lX11 -lXpm $(X11DIR)
SRCDIR=src
OBJDIR=obj
PICDIR=obj-pic
SRCDIRS=$(shell find $(SRCDIR) -type d)
INCL=$(SRCDIRS:%=-I./%)
INCL+=$(shell pkg-config --cflags-only-I x11 xpm) # for macOS
allsrc=$(shell find $(SRCDIR) -type f -name '*.c')
allobj=$(allsrc:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
allpic=$(allsrc:$(SRCDIR)/%.c=$(PICDIR)/%.o)
allmmd=$(shell find $(OBJDIR) -type f -name '*.d')
OBJDIRS=$(SRCDIRS:$(SRCDIR)%=$(OBJDIR)%)
PICDIRS=$(SRCDIRS:$(SRCDIR)%=$(PICDIR)%)
_=$(shell for i in $(OBJDIRS) $(PICDIRS); do mkdir -p $$i ; done)
default : v
all : v v.so
v : $(allobj)
$(CC) $^ -o $@ $(OFLAGS)
v.so: $(allpic)
$(CC) $^ -shared -Wl,-$(SONAME)$@ $(OFLAGS) -o $@
$(OBJDIR)/%.o : $(SRCDIR)/%.c
$(CC) $(CFLAGS) $< -o $@ $(INCL) $(VERSION_FLAGS) -MMD -MT "$@ $(patsubst $(OBJDIR)%,$(PICDIR)%,$@)"
$(PICDIR)/%.o : $(SRCDIR)/%.c
$(CC) $(CFLAGS) -fPIC $< -o $@ $(INCL) $(VERSION_FLAGS) -MMD -MT "$(patsubst $(PICDIR)%,$(OBJDIR)%,$@) $@" -MF $(patsubst $(PICDIR)/%.o,$(OBJDIR)/%.d,$@)
clean:
rm -f $(allobj) $(allpic) v v.so
cleand:
rm -f $(allmmd)
cleantags:
rm -f ./.tags ./.types.vim
cleancheck:
rm -rf ./errors.xml ./cppcheck_html/
cleanall: clean cleand cleantags cleancheck
include $(allmmd)
cppcheck: cleancheck
-.github/cppcheck.bash 2> errors.xml
cppcheck-htmlreport --file=errors.xml --report-dir=cppcheck_html