-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.mk
78 lines (57 loc) · 1.42 KB
/
common.mk
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
OPTFLAGS:=-O3 -ffast-math
ifeq ($(RELEASE),)
OPTFLAGS+=-g
else
OPTFLAGS+=-flto
endif
WARNINGS:=-Wall -Wextra -Wno-pointer-arith -Wno-unused-parameter
CFLAGS:=-std=c17 $(OPTFLAGS) $(WARNINGS)
LDFLAGS:=$(OPTFLAGS)
PREFIX?=/usr/local
INSTALL?=install
IFLAGS:=-D
all:
define decl
SRC_$1=$(patsubst %,./src/$1/%.c,$2)
OBJ_$1=$(patsubst %,./build/$1/%.o,$2)
all: ./build/$1
./build/$1:
@mkdir -p $$@
./build/$1/%.o: ./src/$1/%.c
$$(CC) -o $$@ -c $$< $$(CFLAGS) $$(CFLAGS_$1)
endef
define exec
all: ./build/$1/$1
install-exec: ./build/$1/$1
uninstall-exec: $$(PREFIX)/bin/$1
./build/$1/$1: $(OBJ_$1) $2
$$(CC) -o $$@ $$^ $$(LDFLAGS) $$(LDFLAGS_$1)
endef
define lib
all: ./build/$1/$1.ar ./build/$1/$1.so
install-lib: ./build/$1/$1.ar ./build/$1/$1.so
uninstall-lib: $$(PREFIX)/lib/$1.ar $$(PREFIX)/lib/$1.so
./build/$1/$1.ar: $(OBJ_$1) $2
$(AR) rcs $$@ $$^ $$(LDFLAGS_$1)
./build/$1/$1.so: $(OBJ_$1) $2
$(CC) -fPIC -shared -o $$@ $$^ $$(LDFLAGS_$1)
endef
define dev
install-dev: $(patsubst %,./include/%.h,$1)
endef
clean:
rm -rf ./build/*
install-exec:
$(INSTALL) $(IFLAGS) -s $^ -t $(PREFIX)/bin
install-lib:
$(INSTALL) $(IFLAGS) $^ -t $(PREFIX)/lib
install-dev:
$(INSTALL) $(IFLAGS) $^ -t $(PREFIX)/include/$(PROJECT)
install: install-exec install-lib install-dev
uninstall-exec:
rm -rf $^
uninstall-lib:
rm -rf $^
uninstall-dev:
rm -rf $(PREFIX)/include/$(PROJECT)
uninstall: uninstall-exec uninstall-lib uninstall-dev