-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·276 lines (230 loc) · 6.24 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
NAME = RT
# Compiler
CC = $(CC_$(OSFLAG))
CC_WIN = i686-w64-mingw32-gcc
CC_LIN = gcc
CC_MAC = gcc
# Compiler flags
CFLAGS = -Wall -Wextra -Werror $(CFLAGS_PLATFORM) -MMD -g
CFLAGS_PLATFORM = $(CFLAGS_$(OSFLAG))
CFLAGS_WIN = -mwindows -I./ -L./
CFLAGS_LIN = -Wno-unused-result #-fsanitize=address -ldl
CFLAGS_MAC =
# Linker (for embedding binary files inside the program)
LD = $(LD_$(OSFLAG))
LD_WIN = i686-w64-mingw32-ld -r -b binary
LD_LIN = ld -r -b binary
LD_MAC = ld -r -sectcreate __DATA __inc_ui_chr
# Libraries
LIBS = $(LIBFT) $(LIBSDL) $(OPENCL)
INCLUDE_DIRS = -I$(LFTDIR) $(SDLHDRS)
LIBFT = -L$(LFTDIR) -lft
LIBSDL = $(LIBSDL_$(OSFLAG))
LIBSDL_WIN = -L$(SDLDIR) -lSDL2
LIBSDL_LIN = -L$(SDLDIR) -lSDL2 -lm
LIBSDL_MAC = -L$(SDLDIR)/SDL2.framework/Versions/Current -F. -framework SDL2
# Directories that this Makefile will use
SRCDIR = ./src/
OBJDIR = ./obj/
INCDIR = ./inc/
LFTDIR = ./lib/libft/
SDLDIR = ./lib/
SDLHDRS = -I./lib/SDL2-2.0.9/include/ -I./lib/SDL2.framework/Headers/
# Set platform-specific variables
ifeq ($(OS),Windows_NT)
OSFLAG := WIN
LIBS += -L./ -lOpenCL
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OSFLAG := LIN
LIBS += -lOpenCL
#ifeq ($(PROC_TYPE),)
# CFLAGS += -m32
#else
# CFLAGS += -m64
#endif
# Check for Linux-AMD
ifdef AMDAPPSDKROOT
INC_DIRS =. $(AMDAPPSDKROOT)/include
ifeq ($(PROC_TYPE),)
LIB_DIRS = $(AMDAPPSDKROOT)/lib/x86
else
LIB_DIRS = $(AMDAPPSDKROOT)/lib/x86_64
endif
else
# Check for Linux-Nvidia
ifdef CUDA
INC_DIRS =. $(CUDA)/OpenCL/common/inc
endif
endif
endif
ifeq ($(UNAME_S),Darwin)
OSFLAG := MAC
CFLAGS += -DMAC
OPENCL := -framework OpenCL
endif
endif
# List of C header files
HDRS = $(LFTDIR)libft.h \
rt.h \
assets.h \
$(SRCDIR)debug.h \
$(SRCDIR)config.h \
$(SRCDIR)event.h \
$(SRCDIR)ui.h \
$(SRCDIR)rt_cl.h \
$(SRCDIR)rt_scene.h \
$(SRCDIR)rt_random.h \
# List of C source code files
SRCS = main.c \
init_sdl.c \
opencl_init.c \
opencl_utils.c \
opencl_memory.c \
opencl_kernels.c \
opencl_get_error_str.c \
opencl_render.c \
opencl_render_mem.c \
debug.c \
config.c \
config_ini.c \
config_access.c \
event.c \
event_window.c \
event_mouse.c \
event_key.c \
rt_get_str_scene.c \
rt_get_str_object.c \
rt_get_img_texture.c \
rt_file.c \
rt_open.c \
rt_open_util.c \
rt_open_read_materials.c \
rt_open_read_properties.c \
rt_open_read_textures.c \
rt_open_read_vectors.c \
rt_save.c \
rt_auto_build_scene.c \
rt_auto_build_scene_util.c \
rt_auto_build_cornellbox.c \
rt_random.c \
rt_random_util.c \
rt_scene.c \
rt_object.c \
camera.c \
update_window.c \
ui.c \
ui_init.c \
ui_init_mac.c \
ui_menu_file.c \
ui_menu_file_extra.c \
ui_menu_edit.c \
ui_render.c \
ui_render_util.c \
ui_render_util_rect.c \
ui_render_canvas.c \
ui_mouse.c \
ui_mouse_menu.c \
ui_mouse_objectlist.c \
ui_mouse_objectlist_enums.c \
ui_render_objectlist.c \
ui_control_numberbox_float.c \
ui_control_numberbox_int.c \
ui_control_textbox.c \
ui_scrollbar.c \
ui_prompt.c \
cl_float3_util.c
SRCDIR_CL = $(SRCDIR)ocl/
# List of OpenCL source code files. ORDER MATTERS: FILES ARE CONCATENATED THEN READ.
SRCS_CL = rt_cl_scene.h.cl \
rt_cl_linear_algebra.cl \
rt_cl_random.cl \
rt_cl_materials.cl \
rt_cl_sphere.cl \
rt_cl_primitives_2d.cl \
rt_cl_cylinder.cl \
rt_cl_infcone.cl \
rt_cl_cone.cl \
rt_cl_cube.cl \
rt_cl_paraboloid.cl \
rt_cl_hyperboloid.cl \
rt_cl_debug.cl \
rt_cl_build_scene.cl \
rt_cl_perlin_noise.cl \
rt_cl_patterns.cl \
rt_cl_texture.cl \
rt_cl_render.cl
# List of asset files to be embedded within the program
INCS = ui.chr
# define colors for terminal output
RESET = "\033[0m"
RED = "\033[0;31m"
GREEN = "\033[0;32m"
# define object list and dependency files (.d)
OBJS = ${SRCS:%.c=$(OBJDIR)%.o}
DEPENDS = ${OBJS:.o=.d}
all: libraries $(NAME)
$(OBJS): | objdir
$(NAME): $(OBJS) $(HDRS) assets.o concat.cl
@printf "Compiling program: "$@" -> "
@$(CC) $(CFLAGS) $(OBJS) assets.o -o $@ $(LIBS)
@if [ $(OSFLAG) = "MAC" ]; then \
install_name_tool -change @rpath/SDL2.framework/Versions/A/SDL2 @executable_path/SDL2.framework/Versions/A/SDL2 $@; \
fi
@printf $(GREEN)"OK!"$(RESET)"\n"
$(OBJDIR)%.o : $(SRCDIR)%.c $(HDRS)
@printf "Compiling file: "$@" -> "
@$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE_DIRS) -MF $(OBJDIR)$*.d
@printf $(GREEN)"OK!"$(RESET)"\n"
CL_FILES = $(addprefix $(SRCDIR_CL), $(SRCS_CL))
concat.cl: $(CL_FILES)
@export CL_LOG_ERRORS="stdout"
@printf "Concatenating .cl files: "$@" -> "
@cat $(CL_FILES) > $@
@printf $(GREEN)"OK!"$(RESET)"\n"
ASSET_FILES = $(addprefix $(INCDIR),$(INCS))
assets.o : $(ASSET_FILES)
@printf "Compiling assets: "$@" -> "
@if [ $(OSFLAG) = "MAC" ]; then \
gcc -c empty.c -o $@; \
$(LD) $(ASSET_FILES) $@ -o $@; \
else \
$(LD) $(ASSET_FILES) -o $@; \
fi
@printf $(GREEN)"OK!"$(RESET)"\n"
objdir:
@mkdir -p $(OBJDIR)
libraries:
@make -C $(LFTDIR) all
clean:
@make -C $(LFTDIR) clean
@printf "Deleting object files...\n"
@rm -f $(OBJS)
@rm -f log.txt
@rm -f config.ini
@rm -f assets.o
@rm -f concat.cl
fclean: clean
@make -C $(LFTDIR) fclean
@printf "Deleting program: "$(NAME)"\n"
@rm -f $(NAME)
rclean:
@make -C $(LFTDIR) rclean
@printf "Deleting obj folder...\n"
@rm -rf $(OBJDIR)
re: fclean all
replace:
@sed -i -e "s|$(old)|$(new)|g" $(addprefix $(SRCDIR), $(SRCS)) $(addprefix $(HDRDIR), $(HDRS))
@printf "Replaced all instances of \'"$(old)"\' with \'"$(new)"\'.\n"
rename:
@sed -i -e "s|\<$(old)\>|$(new)|g" $(addprefix $(SRCDIR), $(SRCS)) $(addprefix $(HDRDIR), $(HDRS))
@printf "Renamed all words matching \'"$(old)"\' with \'"$(new)"\'.\n"
PREPROCESSED = ${SRCS:%.c=$(OBJDIR)%.c}
preprocessed: $(PREPROCESSED)
@printf "Outputting preprocessed code...\n"
$(OBJDIR)%.c : $(SRCDIR)%.c $(HDRS)
@printf "Preprocessing file: "$@" -> "
@$(CC) $(CFLAGS) -E $< -o $@
@printf $(GREEN)"OK!"$(RESET)"\n"
-include ${DEPENDS}