-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
145 lines (111 loc) · 3.78 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Common configuration variables
BUILDDIR = build
RELEASEDIR = release
EXECUTABLE = demo
CC = gcc
STRIP = strip --strip-all
EXTRA_CFLAGS = -MMD -std=c99 -Wall -Wextra -Wpedantic -Wno-unused-parameter -I$(BUILDDIR)/include -L$(BUILDDIR)/lib
SOURCEDIR = src
SOURCES = $(wildcard $(SOURCEDIR)/*.c)
LIBRARIES = $(patsubst %,$(BUILDDIR)/%, lib/librocket.a include/stb_vorbis.c include/cgltf.h)
DEBUG ?= 1
# Add platform dependent build and linker flags
ifeq ($(findstring mingw,$(CC)),mingw)
# MinGW SDL2 and OpenGL
LDLIBS += $(shell /usr/x86_64-w64-mingw32/bin/sdl2-config --libs) -lglew32 -lopengl32
EXECUTABLE := $(EXECUTABLE).exe
else
# Linux SDL2
LDLIBS += $(shell $(BUILDDIR)/bin/sdl2-config --static-libs)
LIBRARIES += $(BUILDDIR)/lib/libSDL2.a
ifeq ($(GLES),1)
# Linux GLES
LDLIBS += -lGLESv2
EXTRA_CFLAGS += -DGLES
else
# Linux regular OpenGL (default)
LDLIBS += -lGL
EXTRA_CFLAGS += -DGL_GLEXT_PROTOTYPES
endif
endif
# Set debug and release build variables
ifeq ($(DEBUG),0)
OBJDIR = $(RELEASEDIR)
CFLAGS += -Os
EXTRA_CFLAGS += -DSYNC_PLAYER
LDLIBS += -lrocket-player
else
OBJDIR = $(BUILDDIR)
CFLAGS += -Og -g
EXTRA_CFLAGS += -DDEBUG
LDLIBS += -lrocket
endif
# Executable file system flags (self-contained, standalone executable)
ifeq ($(SELF_CONTAINED),1)
EXTRA_CFLAGS += -DSELF_CONTAINED -Wl,--wrap=fopen -Wl,--wrap=fseek -Wl,--wrap=rewind -Wl,--wrap=ftell -Wl,--wrap=feof -Wl,--wrap=ferror -Wl,--wrap=fread -Wl,--wrap=fgetc -Wl,--wrap=ungetc -Wl,--wrap=fclose
LIBRARIES += $(BUILDDIR)/include/data.c
endif
# Variables for output and intermediate artifacts
TARGET = $(OBJDIR)/$(EXECUTABLE)
OBJS = $(SOURCES:%.c=$(OBJDIR)/%.o)
DEPS = $(OBJS:%.o=%.d)
# Rule for linking the final executable
$(TARGET): $(OBJS)
@mkdir -p $(@D)
$(CC) -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ $(LDFLAGS) $(LDLIBS)
ifeq ($(DEBUG),0)
$(STRIP) $(TARGET)
else
$(MAKE) compile_commands.json
mkdir -p data/
endif
ifeq ($(findstring mingw,$(CC)),mingw)
cp /usr/x86_64-w64-mingw32/bin/SDL2.dll $(OBJDIR)
cp /usr/x86_64-w64-mingw32/bin/glew32.dll $(OBJDIR)
cp /usr/x86_64-w64-mingw32/bin/libssp-0.dll $(OBJDIR)
endif
# Include compiler-generated header dependencies
-include $(DEPS)
# Rule for compiling our C source files
$(OBJDIR)/%.o: %.c $(LIBRARIES)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
# Rule that checks for having fetched git submodules
lib/SDL/configure:
@echo Please run git submodule update --init first!
@echo Check README.md for details.
@exit 1
# Rule for building SDL2
$(BUILDDIR)/lib/libSDL2.a: | lib/SDL/configure
CC=$(CC) BUILDDIR=$(BUILDDIR) MAKE=$(MAKE) scripts/build_sdl2.sh
# Rule for building rocket libraries
$(BUILDDIR)/lib/librocket.a: | lib/SDL/configure
$(MAKE) -C lib/rocket lib/librocket.a lib/librocket-player.a CFLAGS="-Os" CC=$(CC)
@mkdir -p $(BUILDDIR)/lib $(BUILDDIR)/include
cp lib/rocket/lib/*.a $(BUILDDIR)/lib
cp lib/rocket/lib/*.h $(BUILDDIR)/include
# Rule for copying stb_vorbis.c to library include directory
$(BUILDDIR)/include/stb_vorbis.c: lib/stb/stb_vorbis.c
@mkdir -p $(BUILDDIR)/include
cp $^ $@
# Rule for copying cgltf.h to library include directory
$(BUILDDIR)/include/cgltf.h: lib/cgltf/cgltf.h
@mkdir -p $(BUILDDIR)/include
cp $^ $@
# Rule for generating build/include/data.c
$(BUILDDIR)/include/data.c: $(wildcard shaders/*) $(wildcard data/*)
@mkdir -p $(BUILDDIR)/include
scripts/mkfs.sh shaders/ data/ > $@
# Generate a compile_commands.json file for clangd, clang-tidy etc. devtools
compile_commands.json: $(SOURCES)
CC=$(CC) CFLAGS="$(CFLAGS) $(EXTRA_CFLAGS)" scripts/gen_compile_commands_json.sh $(SOURCEDIR) > $@
.PHONY: clean
clean:
rm -rf $(BUILDDIR) $(RELEASEDIR) compile_commands.json
rm -rf lib/rocket/lib/*.a
rm -rf lib/rocket/lib/*.o
$(MAKE) -C lib/SDL clean
.PHONY: run
# Compile and run the executable with 'make run'
run: $(TARGET)
./$(TARGET)