summaryrefslogtreecommitdiff
path: root/Makefile
blob: 097e2d8f9a18f8e301d1a1ac3cf6de64f5290f69 (plain)
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
CC = gcc
CFLAGS = -std=c99 -Wall -Wextra -Wshadow -Wswitch-enum -Wno-unused-parameter
LDFLAGS = $(SDL_LDFLAGS) -ldl -lm

SDL_CFLAGS := $(shell sdl2-config --cflags)
SDL_LDFLAGS := $(shell sdl2-config --libs)

override CFLAGS += $(SDL_CFLAGS)

SRC_FILES = platform_sdl.c game.c entity.c vector.c
SRC = $(addprefix src/, $(SRC_FILES))
EXE_FILE = ohsp

LIB_FILES = game.c entity.c vector.c
LIB = $(addprefix src/, $(LIB_FILES))
LIB_NAME = game.so

DBGDIR = debug
DBGEXE = $(DBGDIR)/$(EXE_FILE)
DBGLIB = $(DBGDIR)/$(LIB_NAME)
DBGLIBTMP = $(DBGLIB).tmp
DBGCFLAGS = -g -Og -Werror

RELDIR = release
RELEXE = $(RELDIR)/$(EXE_FILE)
RELLIB = $(RELDIR)/$(LIB_NAME)
RELLIBTMP = $(RELLIB).tmp
RELCFLAGS = -O2 -Os

.PHONY: all clean compile_debug compile_release debug lib_debug lib_release memcheck prep run todo

all: compile_debug compile_release

clean:
	rm -f $(RELDIR)/* $(DBGDIR)/*

compile_debug: prep lib_debug
	$(CC) $(CFLAGS) $(DBGCFLAGS) $(SRC) -o $(DBGEXE) $(LDFLAGS)

compile_release: prep lib_release
	$(CC) $(CFLAGS) $(RELCFLAGS) $(SRC) -o $(RELEXE) $(LDFLAGS)

debug: compile_debug
	gdb $(DBGEXE)

lib_debug:
	$(CC) $(CFLAGS) -fpic -shared $(DBGCFLAGS) $(LIB) -o $(DBGLIBTMP) $(LDFLAGS)
	mv $(DBGLIBTMP) $(DBGLIB)

lib_release:
	$(CC) $(CFLAGS) -fpic -shared $(RELCFLAGS) $(LIB) -o $(RELLIBTMP) $(LDFLAGS)
	mv $(RELLIBTMP) $(RELLIB)

memcheck: compile_debug
	valgrind --track-origins=yes ./$(DBGEXE)

prep:
	@mkdir -p $(DBGDIR) $(RELDIR)

run: compile_release
	./$(RELEXE)

todo:
	@grep -FIR --colour=never --ignore-case --line-number todo src/ \
	| sed -re  's/^([^:]+):[[:space:]]*(.*)/\1\x01\2/' \
	| sed -re  's/^([^:]+):[[:space:]]*(.*)/\1\x01\2/' \
	| column -s $$'\x01' -t