-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
46 lines (32 loc) · 1.1 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
CFLAGS=-O2 -Ilib -rdynamic -pthread `pkg-config --cflags sdl2` $(OPTFLAGS)
LDLIBS=-ldl -lm `pkg-config --libs sdl2` $(OPTLIBS)
LIB_SOURCES=$(wildcard lib/**/*.c)
LIB_OBJECTS=$(patsubst %.c,%.o,$(LIB_SOURCES))
EXE_SOURCES=$(wildcard bin/*.c)
EXE_TARGETS=$(patsubst %.c,%,$(EXE_SOURCES))
MSC_SOURCES=$(wildcard lib/*.c)
MSC_OBJECTS=$(patsubst %.c,%.o,$(MSC_SOURCES))
EXAMPLES=$(wildcard examples/*.c)
SO_EXAMPLES=$(patsubst %.c,%.so,$(EXAMPLES))
TARGET=build/libcellhack.a
SO_TARGET=$(patsubst %.a,%.so,$(TARGET))
dev: CFLAGS+=-g -Wall -Wextra -O0 -DDEBUG
dev: all
all: $(TARGET) $(SO_TARGET) $(EXE_TARGETS) examples
examples: $(SO_EXAMPLES)
%.so: CFLAGS+=-fPIC --shared
%.so: %.c
gcc $(CFLAGS) -o $@ $*.c
$(EXE_TARGETS): build $(MSC_OBJECTS) $(TARGET)
$(CC) $(CFLAGS) -o $@ [email protected] $(MSC_OBJECTS) $(TARGET) $(LDLIBS)
$(TARGET): CFLAGS += -fPIC
$(TARGET): build $(LIB_OBJECTS)
ar rcs $@ $(LIB_OBJECTS)
ranlib $@
$(SO_TARGET): $(TARGET) $(LIB_OBJECTS)
$(CC) --shared -o $@ $(LIB_OBJECTS)
build:
@mkdir -p build
.PHONY:
clean:
rm -rf build $(TARGET) $(SO_TARGET) $(LIB_OBJECTS) $(EXE_TARGETS) $(SO_EXAMPLES)