-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
79 lines (59 loc) · 1.67 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright (C) 2014-2016 Ben Kurtovic <[email protected]>
# Released under the terms of the MIT License. See LICENSE for details.
PROGRAM = crater
SOURCES = src
BUILD = build
DEVEXT = -dev
TESTS = cpu vdp psg asm dis integrate
CC = clang
FLAGS = -Wall -Wextra -pedantic -std=c11
CFLAGS = $(shell sdl2-config --cflags)
LIBS = $(shell sdl2-config --libs)
DFLAGS = -g
RFLAGS = -O2
MKDIR = mkdir -p
RM = rm -rf
ASM_UP = scripts/update_asm_instructions.py
SDRS = $(shell find $(SOURCES) -type d | xargs echo)
SRCS = $(filter-out %.inc.c,$(foreach d,. $(SDRS),$(wildcard $(addprefix $(d)/*,.c))))
OBJS = $(patsubst %.c,%.o,$(addprefix $(BUILD)/$(MODE)/,$(SRCS)))
DEPS = $(OBJS:%.o=%.d)
DIRS = $(sort $(dir $(OBJS)))
TCPS = $(addprefix test-,$(TESTS))
ifdef DEBUG
BNRY := $(PROGRAM)$(DEVEXT)
FLGS += $(DFLAGS) $(FLAGS)
MODE = debug
else
BNRY := $(PROGRAM)
FLGS += $(RFLAGS) $(FLAGS)
MODE = release
endif
export CC
export FLAGS
export RM
.PHONY: all clean test tests test-prereqs test-make-prereqs $(TCPS)
all: $(BNRY)
clean:
$(RM) $(BUILD) $(PROGRAM) $(PROGRAM)$(DEVEXT)
@$(MAKE) -C tests clean
$(DIRS):
$(MKDIR) $@
$(BNRY): $(OBJS)
$(CC) $(FLGS) $(LIBS) $(OBJS) -o $@
$(OBJS): | $(DIRS)
$(BUILD)/$(MODE)/%.o: %.c
$(CC) $(FLGS) $(CFLAGS) -MMD -MP -c $< -o $@
-include $(DEPS)
ASM_INST = $(SOURCES)/assembler/instructions
$(ASM_INST).inc.c: $(ASM_INST).yml $(ASM_UP)
python $(ASM_UP)
test-prereqs: $(PROGRAM)
@: # No-op; prevents make from cluttering output with "X is up to date"
test-make-prereqs:
@$(MAKE) test-prereqs DEBUG=
test: test-make-prereqs
@$(MAKE) -C tests -s all
tests: test
$(TCPS): test-make-prereqs
@$(MAKE) -C tests -s $(subst test-,,$@)