-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
49 lines (40 loc) · 1.22 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
CC=gcc
CFLAGS=-Wall -std=c11
LIBS=-lSDL2 -lSDL2_ttf -lm
INCLUDES=-I./
OBJ=obj
BIN=bin
SOURCES=$(shell find . -name '*.c' -not -path './plugins/*' -not -path './deps/*')
FILTER_SHARED_OBJS=obj/./main-shared.o obj/./driver/command.o
SHARED_OBJECTS=$(filter-out $(FILTER_SHARED_OBJS),$(addprefix $(OBJ)/,$(SOURCES:%.c=%-shared.o)))
DEPS=$(shell find . -name Makefile -printf '%h\n' | grep -v 'unittest' | grep -v '^.$$')
TARGET=hotreload
SHARED_TARGET=libdriver.so
.PHONY: all
all: command shared
.PHONY: command
command:
$(CC) -c -o obj/main.o main.c $(CFLAGS) $(INCLUDES)
$(CC) -c -o obj/command.o driver/command.c $(CFLAGS) $(INCLUDES)
$(CC) obj/main.o obj/command.o -O2 $(CFLAGS) $(LIBS) -o $(BIN)/$(TARGET)
.PHONY: shared
shared: $(SHARED_OBJECTS)
$(CC) -shared -fPIC $^ -O2 $(CFLAGS) $(LIBS) -o $(BIN)/$(SHARED_TARGET)
$(OBJ)/%-shared.o: %.c
@mkdir -p $(dir $@)
@mkdir -p $(BIN)
$(CC) -c -fPIC -o $@ $< $(CFLAGS) $(INCLUDES)
.PHONY: clean
clean:
@rm -rf $(OBJ)/* 2> /dev/null
@rm -f $(BIN)/* 2> /dev/null
.PHONY: clean_deps
clean_deps:
$(foreach dir, $(DEPS), $(shell cd $(dir) && $(MAKE) clean))
.PHONY: clean_all
clean_all: clean clean_deps
.PHONY: deps
deps:
@for i in $(DEPS); do\
cd $${i} && $(MAKE) && cd -;\
done