summaryrefslogtreecommitdiff
path: root/Makefile
blob: d5c81663d923ab3aef5c58b3c6d735404a190a73 (plain) (blame)
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
84
85
86
87
compiler = gcc
tool_compiler = gcc
linker = gcc
cflags = -I./ -g -DDEBUG -Dplat_x11 -Dplat_x86 \
-Dplat_posix -Dallocation_default_alignment=8 \
-Wall -Wextra -pedantic -std=c90
lflags = -lX11 -lXi
int_dir = intermediate
data_dir = data
target = 3de
convmesh = convmesh
convtexture = convtexture
packassets = packassets
pack = pack

sources = \
	3de.c \
	asset.c \
	editor.c \
	gui.c \
	map.c \
	maths.c \
	memory.c \
	plat.c \
	player.c \
	rect.c \
	render.c \
	standard.c

objects = $(sources:%.c=%.o)

mesh_sources = \
	$(int_dir)/gun.glb \
	$(int_dir)/guy.glb

texture_sources = \
	$(int_dir)/brick.bmp \
	$(int_dir)/floorboards.bmp \
	$(int_dir)/floorboardsbot.bmp \
	$(int_dir)/gun.bmp \
	$(int_dir)/guy.bmp

meshes = $(mesh_sources:$(int_dir)/%.glb=$(data_dir)/%.msh)
textures = $(texture_sources:$(int_dir)/%.bmp=$(data_dir)/%.bc1)

all: $(target) $(pack)

$(objects): %.o : %.c
	$(compiler) -MMD -MF $(basename $@).d $(cflags) -o $@ -c $<

$(target): $(objects)
	$(linker) $(objects) -o $@ $(lflags)

$(meshes): $(data_dir)/%.msh : $(int_dir)/%.glb | $(convmesh) $(data_dir)
	./$(convmesh) $< $@

$(textures): $(data_dir)/%.bc1 : $(int_dir)/%.bmp | $(convtexture) $(data_dir)
	./$(convtexture) $< $@

$(convmesh): convmesh.c
	$(tool_compiler) -o $@ $<

$(convtexture): convtexture.c
	$(tool_compiler) $(cflags) -o $@ $< -lm

$(packassets): packassets.c
	$(tool_compiler) packassets.c $(cflags) -o $@

$(pack): $(packassets) $(meshes) $(textures)
	./$(packassets) \
		$(data_dir) \
		$(notdir $(meshes)) \
		$(notdir $(textures))

$(data_dir):
	mkdir -p $(data_dir)

clean:
	rm -f $(packassets)
	rm -f $(convmesh)
	rm -f $(convtexture)
	rm -rf data
	rm *.d
	rm *.o
	rm $(target)

-include $(sources:%.c=%.d)