-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
54 lines (44 loc) · 1.73 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
# Greatly inspired by this:
# https://stackoverflow.com/a/30142139
#
# Straightforward Makefile that builds everything into the BUILD_DIR, and
# recompiles only what is needed.
# Configurables
CC := clang
# Disable unused parameter warning since not everything is implemented yet
CFLAGS := -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function
BIN := megado-bin
BUILD_DIR := build
# For release and debug flags inserted by ./run.sh
CFLAGS += $(USER_FLAGS)
# Folders containing C files to compile
MODULES := megado megado/m68k test
# Submodule dependencies
INCLUDES := -I./ -Ideps/cimgui/ -Ideps/glfw/include\
-Ideps/glew/include -Ideps/json-c/include/json-c\
-D_REENTRANT -Ideps/sdl2/install/include/SDL2
LIBS := -lm -Ldeps/glew/build/lib -lGLEW -lGLU -lGL -Ldeps/cimgui/cimgui\
-l:cimgui.so -Ldeps/glfw/build/src -lglfw -Ldeps/json-c/lib -ljson-c\
-Ldeps/sdl2/install/lib -lSDL2
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# There can be only one main, and that is test/main.c
SRC := $(filter-out megado/m68k/main.c,$(foreach sdir,$(MODULES),$(wildcard $(sdir)/*.c)))
# Put all objects into the build dir, preserving the SRC hierarchy
OBJ := $(SRC:%.c=$(BUILD_DIR)/%.o)
# The .d files are generated by CC, used to rebuild objs whenever any dependency
# changes
DEP := $(OBJ:%.o=%.d)
# Default target: the main binary
$(BUILD_DIR)/$(BIN): $(OBJ)
# Create build directories on the way
@mkdir -p $(@D)
$(CC) $^ $(CFLAGS) $(LIBS) -o $@
# Include .d files built by the next rule
-include $(DEP)
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(@D)
# -MMD generates the .d dependencies on the go
$(CC) $< $(CFLAGS) $(INCLUDES) -MMD -c -o $@
.PHONY: clean
clean:
-rm --force $(BUILD_DIR)/$(BIN) $(OBJ) $(DEP)