-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakefile
157 lines (130 loc) · 5.5 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
146
147
148
149
150
151
152
153
154
155
156
157
# Set the compiler to Clang.
CC=clang++
# The linker.
LINK=ld
# The output name of the static library:
ST_NAME=libTile2d.a
# The output nmame of the dynamic library:
DY_NAME=libTile2d.so
# The source directory.
SRC_DIR=src/
# The header directory.
HDR_DIR=include/
# The shader source directory.
SDR_DIR=shaders/
# The scripts directory.
SCRIPTS=scripts/
# The build directory.
BLD_DIR=bin/
# The library file output directory.
LIB_DIR=lib/
# The test code directory.
TST_DIR=./
# The build options variable, to be used to specify debug flags through make.
DBFLAGS=''
# Compilation flags. Specifies to only compile (and not to link), as well as
# a custom include directory of HDR_DIR.
CFLAGS= -c -g -I $(HDR_DIR) $(subst T2D_, -D T2D_,$(strip $(DBFLAGS)))
# Linking flags to make sure everything is bound up tight.
LFLAGS= -lglfw -lGL -lGLU -lpng -lGLEW -lm -lz -ldl
# The source files to be built.
FILES=$(BLD_DIR)Asset.o $(BLD_DIR)AssetManager.o \
$(BLD_DIR)Texture.o $(BLD_DIR)ShaderUniform.o \
$(BLD_DIR)Shader.o $(BLD_DIR)Camera.o \
$(BLD_DIR)Framebuffer.o $(BLD_DIR)Renderer.o \
$(BLD_DIR)Window.o $(BLD_DIR)BasicMatrix.o \
$(BLD_DIR)Tile.o $(BLD_DIR)BGTile.o \
$(BLD_DIR)SceneTile.o $(BLD_DIR)AnimTile.o \
$(BLD_DIR)DefTile.o $(BLD_DIR)FwdTile.o \
$(BLD_DIR)RenderQueue.o
# The shader source files to consolidate.
SHADER_FILES=$(HDR_DIR)shader_source.h \
$(SDR_DIR)bg_tile_shader.vert $(SDR_DIR)bg_tile_shader.frag \
$(SDR_DIR)scene_tile_shader.vert $(SDR_DIR)scene_tile_shader.frag \
$(SDR_DIR)anim_tile_shader.vert $(SDR_DIR)anim_tile_shader.frag \
$(SDR_DIR)final_pass_shader.vert $(SDR_DIR)final_pass_shader.frag
all:
@echo ""
@echo "Welcome to the Tile2D makefile!"
@echo ""
@echo "** Building **"
@echo "This makes a static or shared library, or a pile of .o files."
@echo "Please run again with one of the rules below:"
@echo ""
@echo "clean - Clears out the build directory \"$(BLD_DIR)\""
@echo "OBJ_FILES - Compiles Tile2D into .o files. For those who enjoy linking."
@echo "STATIC - Compiles Tile2D into a static library called \"$(ST_NAME)\"."
@echo "DYNAMIC - Compiles Tile2D into a dynamic library named \"$(DY_NAME)\""
@echo "help - Displays this help dialog."
@echo ""
@echo "Example: "
@echo "> make STATIC"
@echo ""
@echo "** Ddebugging and profiling **"
@echo "To enable profiling and debug options, clean your Tile2D build with \"clean\""
@echo "then build with your choice of rule, specifying any combination of the following"
@echo "options as DBFLAGS."
@echo ""
@echo "T2D_PER_TILE_STATS: - Prints information about each Tile drawn, when drawn."
@echo "T2D_PER_FRAME_STATS - Prints draw-times for the various passes every frame."
@echo "T2D_SHADER_UNI_INFO - Displays uniforms variables seen and parsed by the parser."
@echo "T2D_SHADER_LOADING_STATS - Use to verify shader loading. Keep an eye on line counts."
@echo "T2D_TEX_LOADING_STATS - Displays statistics about loaded textures."
@echo "T2D_WINDOW_INFO - Displays info about the window during creation and change."
@echo ""
@echo "Example: "
@echo "> make clean"
@echo "> make DYNAMIC DBFLAGS='T2D_PER_TILE_STATS T2D_PER_FRAME_STATS'"
@echo ""
@echo "** Testing **"
@echo "To test, build all or one of the examples, then run them. If they run, then"
@echo "things are all okay."
@echo ""
# Simply prints the help info displayed by the all target.
help: all
# Cleans the build directory and deletes it.
clean:
@echo "Cleaning out and deleting build directory \"$(BLD_DIR)\"."
@rm -r -f $(BLD_DIR)
@echo "Cleaning out and deleting library directory \"$(LIB_DIR)\"."
@rm -r -f $(LIB_DIR)
@echo "Done cleaning."
# Creates the build directory if it doesn't exist.
setup_build_dir:
@echo $(subst T2D_, -D T2D_,$(strip $(DBFLAGS)))
@echo "Creating build directory \"$(BLD_DIR)\"."
@mkdir -p $(BLD_DIR)
@echo "Done creating build directory."
# Creates the library output directory if it doesn't exist.
setup_library_dir:
@echo "Creating library directory \"$(LIB_DIR)\"."
@mkdir -p $(LIB_DIR)
@echo "Done creating library directory."
# Compiles the shader source code files.
SHADERS:
@echo "Consolidating shaders into header file named \"shader_source.h\""
@rm -f $(HDR_DIR)shader_source.h
@python $(SCRIPTS)glsl-to-header.py $(SHADER_FILES)
# Compiles all of Tile2D's source into .o files.
OBJ_FILES_MESSAGE: setup_build_dir
@echo "Compiling PIC object files and placing them in the $(BLD_DIR) directory."
# An implicit (suffix) rule to build any file in the SRC and HDR directories, into the BLD directory.
$(BLD_DIR)%.o: $(SRC_DIR)%.cpp $(HDR_DIR)%.h
@echo " -$<"
@$(CC) $(CFLAGS) $< -o $@ -fPIC
# A shortcut rule for the above.
%.o: $(BLD_DIR)%.o
OBJ_FILES: SHADERS OBJ_FILES_MESSAGE $(FILES)
@echo "Done creating object files. Note: some may not have been recompiled."
# Compiles all of Tile2D into object files then archives them into a
# static library.
STATIC: setup_library_dir OBJ_FILES
@echo "Using ar to create static library in \"$(LIB_DIR)\" preserving original timestamps."
@ar rc $(BLD_DIR)$(ST_NAME) $(FILES) -o -v
@echo "Done archiving."
# Compiles Tile2D and links it up with its dependencies (you better have them)
# into a dynamic library.
DYNAMIC: setup_library_dir OBJ_FILES
@echo "Creating shared library \"$(DY_NAME)\" in \"$(LIB_DIR)\"."
@$(CC) -shared $(FILES) -o $(LIB_DIR)$(DY_NAME)
@echo "Done creating shared library."