-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·74 lines (56 loc) · 2.04 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
#******************************************************************************
# File: Makefile
# Created: 2019-10-16
# Updated: 2019-12-03
# Copyright (c) 2019 Aaron Oman (GrooveStomp)
# 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 -lm
CFLAGS += -std=c11 -pedantic -Wall -D_GNU_SOURCE
SRC_DEP =
SRC = $(wildcard *.c)
OBJFILES = $(patsubst %.c,%.o,$(SRC))
LINTFILES= $(patsubst %.c,__%.c,$(SRC)) $(patsubst %.c,_%.c,$(SRC))
RELDIR = release
RELOBJ = $(addprefix $(RELDIR)/,$(OBJFILES))
RELEXE = $(RELDIR)/gsnes
RELFLG = -O3
DBGDIR = debug
DBGOBJ = $(addprefix $(DBGDIR)/,$(OBJFILES))
DBGEXE = $(DBGDIR)/gsnes
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 test
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