-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
62 lines (47 loc) · 1.3 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
libname := ramses
abi := 0
EXTRA_CFLAGS ?= -DNDEBUG
srcs := $(wildcard *.c)
srcs += $(wildcard translate/*.c)
srcs += $(wildcard map/*.c)
srcs += $(wildcard map/x86/*.c)
libfname := lib$(libname)
arsufx := .a
sosufx := .so
SYSLDFLAGS = -Wl,-soname,$(soname).$(abi)
arname := $(libfname)$(arsufx)
soname := $(libfname)$(sosufx)
OFLAGS := -O2
CPPFLAGS := -Iinclude -iquote .
CFLAGS := -std=c99 -Wall -Wpedantic -pedantic -fPIC $(OFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS)
LDFLAGS := -shared -Wall -Wpedantic -pedantic $(SYSLDFLAGS)
deps := $(patsubst %.c,%.d,$(srcs))
objs := $(patsubst %.c,%.o,$(srcs))
all: $(arname) $(soname)
# Static lib
$(arname): $(objs)
ar -rcs $@ $?
# Dynamic lib
$(soname): $(soname).$(abi)
ln -sf $< $@
$(soname).$(abi): $(objs)
$(CC) $(LDFLAGS) -o $@ $^
# Override built-in compile rule
%.o: %.c
$(CC) -c -o $@ $(CFLAGS) $<
# Dependency generation
%.d: %.c
@set -e; \
DIR=`dirname $<`; \
case "$$DIR" in \
"" | ".") $(CC) -MM -MG $(CPPFLAGS) $< | sed 's|\(.*\)\.o[ :]*|\1.o \1.d : |g' > $@;; \
*) $(CC) -MM -MG $(CPPFLAGS) $< | sed "s|\(.*\)\.o[ :]*|$$DIR/\1.o $$DIR/\1.d : |g" > $@;; \
esac
.PHONY: all clean cleanall
clean:
rm -f $(arname) $(soname) $(soname).$(abi) $(implib) $(objs)
rm -rf tools/__pycache__
rm -rf pyramses/__pycache__
cleanall: clean
rm -f $(deps)
include $(deps)