summaryrefslogtreecommitdiff
path: root/Makefile
blob: dc64c6b1686aecf153663b6a1978148c6010e57c (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
68
69
70
71
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#     Compilation Options
# Debug mode [yes/no] (allowing to debug the library via gdb):
DEBUG   ?= no
# Specify your favourite C compiler here:
COMPILE ?= gcc
# Are you on Windows?
WINDOWS ?= no


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#     Preparations
# Compile as ANSI C code:
CFLAGS   = -xc -ansi -Wall
# Debug and optimisation (as well as -static for valgrind) are not compatible:
ifeq '$(DEBUG)' 'yes'
CFLAGS  += -g -O0
else
CFLAGS  += -O2
endif
ifeq '$(WINDOWS)' 'yes'
LFLAGS   = -mwindows -lmingw32
endif
# Use SDL:
LFLAGS  += -lSDL2main -lSDL2 -lSDL2_ttf -lSDL2_mixer -lm

# Directories definitions:
BUILD    = build
SRCDIR   = src
# Game itself:
GAME     = takethis
# Determing needed object files:
MODULES  = $(foreach x,$(notdir $(wildcard $(SRCDIR)/*.c)),$(x:.c=))
HEADERS  = $(wildcard $(SRCDIR)/*.h)
SRC      = $(foreach i,$(MODULES:=.c),$(SRCDIR)/$(i))
OBJ      = $(foreach i,$(MODULES:=.o),$(BUILD)/$(i))
# Dependency file:
DEPS     = deps.mk


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#     Targets
.PHONY: all clean

all: $(BUILD) $(GAME)

clean:
	rm -f $(GAME) $(OBJ) $(DEPS)


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#     Compilation
ifneq '$(WINDOWS)' 'yes'
-include $(DEPS)
endif

# Packing object files into library:
$(GAME): $(OBJ)
	$(COMPILE) -o $@ $^ $(LFLAGS)

# Compile object files from corresponding source:
$(BUILD)/%.o: $(SRCDIR)/%.c
	$(COMPILE) $(CFLAGS) -c $< -o $@

# Create build directories, if no such:
$(BUILD):
	mkdir -p $@

# Generate dependency file, adding corresponding build prefixes:
$(DEPS): $(SRC) $(HEADERS)
	$(COMPILE) $(SRC) -MM | sed '/^ /!s#^#$(BUILD)/#' >$@