-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
83 lines (62 loc) · 2.24 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
80
81
82
83
#******************************************************************************
# File: Makefile
# Created: 2019-06-27
# Updated: 2019-08-04
# Author: Aaron Oman
# Notice: Creative Commons Attribution 4.0 International License (CC-BY 4.0)
#******************************************************************************
CC = /usr/bin/gcc
INC += $(shell sdl2-config --cflags)
HEADERS = $(wildcard *.h) $(wildcard external/*.h)
LIBS += $(shell sdl2-config --libs) -lSDL2main -lGL -lGLEW -lm -lpthread -lsoundio
CFLAGS += -std=c11 -pedantic -Wall -D_GNU_SOURCE
SRC_DEP = gfxinputthread.c threadsync.c timerthread.c
SRC = input.c main.c opcode.c sound.c system.c ui.c graphics.c
OBJFILES = $(patsubst %.c,%.o,$(SRC))
LINTFILES= $(patsubst %.c,__%.c,$(SRC)) $(patsubst %.c,_%.c,$(SRC))
RELDIR = release
RELOBJ = $(addprefix $(RELDIR)/,$(OBJFILES))
RELEXE = $(RELDIR)/chip8
RELFLG = -O3
DBGDIR = debug
DBGOBJ = $(addprefix $(DBGDIR)/,$(OBJFILES))
DBGEXE = $(DBGDIR)/chip8
DBGFLG = -g -Og
TSTDIR = test
TSTSRC = $(wildcard $(TSTDIR)/*.c)
TSTEXE = $(patsubst $(TSTDIR)/%.c,$(TSTDIR)/%,$(TSTSRC))
TSTLIB = $(LIBS) -ldl
TSTOBJ = $(filter-out $(TSTDIR)/main.o,$(addprefix $(TSTDIR)/,$(OBJFILES)))
DEFAULT_GOAL := $(release)
.PHONY: clean debug docs release splint test uno valgrind
release: $(RELEXE)
$(RELEXE): $(RELOBJ)
$(CC) -o $@ $^ $(LIBS)
$(RELDIR)/%.o: %.c $(HEADERS) $(SRC_DEP)
@mkdir -p $(@D)
$(CC) -c $*.c $(INC) $(CFLAGS) $(RELFLG) -o $@
debug: $(DBGEXE)
$(DBGEXE): $(DBGOBJ)
$(CC) -o $@ $^ $(LIBS)
$(DBGDIR)/%.o: %.c $(HEADERS) $(SRC_DEP)
@mkdir -p $(@D)
$(CC) -c $*.c $(INC) $(CFLAGS) $(DBGFLG) -o $@
test: $(TSTEXE)
$(TSTDIR)/%_test: $(TSTOBJ) $(TSTDIR)/%_test.o
$(CC) -o $@ $(TSTDIR)/$*_test.o $(filter-out $(TSTDIR)/$*.o,$(TSTOBJ)) $(TSTLIB)
$(TSTDIR)/%_test.o: $(HEADERS) $(TSTDIR)/gstest.h $(TSTDIR)/%_test.c
$(CC) -c $(TSTDIR)/$*_test.c $(INC) $(CFLAGS) $(DBGFLG) -o $@
$(TSTDIR)/%.o: %.c $(HEADERS)
$(CC) -c $*.c $(INC) $(CFLAGS) $(DBGFLG) -o $@
runtests: test
$(foreach exe,$(TSTEXE),./$(exe);)
clean:
rm -rf core debug release ${LINTFILES} ${DBGOBJ} ${RELOBJ} ${TSTOBJ} ${TSTEXE} cachegrind.out.* callgrind.out.*
docs:
doxygen .doxygen.conf
valgrind:
echo "valgrind"
splint:
splint ${INC} ${CFLAGS} ${SRC}
uno:
uno ${INC} ${SRC}