Debian Codegraph @

src/makefile

raw symbols SCIP
1 ###############################################################################
2 # name: makefile
3 # desc: source compilation recipes for ChucK programming language
4 #
5 # use this makefile to build:
6 # * command-line executable chuck
7 # * webchuck modules: webchuck.wasm webchuck.js
8 #
9 # ChucK website: https://chuck.stanford.edu/
10 # source repository: https://github.com/ccrma/chuck/
11 ###############################################################################
12 # chuck core location
13 CK_CORE_DIR=core
14 # chuck (command line) host location
15 CK_HOST_DIR=host
16 # where to find RtAudio
17 RTAUDIO_DIR=RtAudio
18 # chuck version
19 CK_VERSION=1.5.5.8
20
21
22 ########################## DEFAULT MAKE TARGET ################################
23 # default target: print usage message and quit
24 current:
25 @echo "[chuck build]: please use one of the following configurations:"
26 @echo " make linux-alsa, make linux-jack, make linux-pulse, linux-all,"
27 @echo " make mac, make mac-ub, make web, make win32"
28
29
30 ############################ MAKE WEBCHUCK ####################################
31 # source for emscripten compilation
32 EMSCRIPTENSRCS=host-web/chuck_emscripten.cpp \
33 core/chuck.cpp core/chuck_absyn.cpp core/chuck_carrier.cpp \
34 core/chuck_compile.cpp core/chuck_dl.cpp core/chuck_emit.cpp \
35 core/chuck_errmsg.cpp core/chuck_frame.cpp core/chuck_globals.cpp \
36 core/chuck_instr.cpp core/chuck_io.cpp core/chuck_lang.cpp \
37 core/chuck_oo.cpp core/chuck_parse.cpp core/chuck_scan.cpp \
38 core/chuck_stats.cpp core/chuck_symbol.cpp core/chuck_table.cpp \
39 core/chuck_type.cpp core/chuck_ugen.cpp core/chuck_vm.cpp \
40 core/uana_extract.cpp core/uana_xform.cpp \
41 core/ugen_filter.cpp core/ugen_osc.cpp core/ugen_stk.cpp \
42 core/ugen_xxx.cpp core/ulib_ai.cpp core/ulib_doc.cpp \
43 core/ulib_machine.cpp core/ulib_math.cpp core/ulib_std.cpp \
44 core/util_buffers.cpp core/util_math.cpp core/util_platforms.cpp \
45 core/util_raw.c core/util_string.cpp core/util_xforms.c \
46 core/chuck_yacc.c core/util_sndfile.c
47
48 EMSCRIPTEN_POSTJS=host-web/chucknode-postjs.js
49
50 # make targets
51 .PHONY: emscripten web
52 emscripten: host-web/webchuck/js/webchuck.js
53 web: host-web/webchuck/js/webchuck.js
54 # recipe
55 host-web/webchuck/js/webchuck.js: $(EMSCRIPTENSRCS) $(EMSCRIPTEN_POSTJS)
56 emcc -O3 -s MAIN_MODULE=2 -s DISABLE_EXCEPTION_CATCHING=0 \
57 -D__DISABLE_MIDI__ -D__DISABLE_WATCHDOG__ -D__DISABLE_NETWORK__ \
58 -D__DISABLE_OTF_SERVER__ -D__ALTER_HID__ -D__DISABLE_HID__ \
59 -D__DISABLE_SERIAL__ -D__DISABLE_ASYNCH_IO__ -D__DISABLE_THREADS__ \
60 -D__DISABLE_KBHIT__ -D__DISABLE_PROMPTER__ -D__DISABLE_SHELL__ \
61 -D__CHUCK_USE_PLANAR_BUFFERS__ -D__OLDSCHOOL_RANDOM__ \
62 -Icore -Wformat=0 $(EMSCRIPTENSRCS) -o host-web/webchuck/js/webchuck.js \
63 -s EXPORTED_FUNCTIONS="['_malloc']" \
64 -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap", "getValue", "setValue", "addFunction", "removeFunction", "UTF8ToString", "stringToUTF8"]' \
65 -s LINKABLE=1 -s MODULARIZE=1 -s ALLOW_MEMORY_GROWTH=1 \
66 -s RESERVED_FUNCTION_POINTERS=50 -s FORCE_FILESYSTEM=1 \
67 -s --extern-post-js $(EMSCRIPTEN_POSTJS) \
68 -s 'EXPORT_NAME="ChucK"'
69
70 # whack-a-mole options for trying to build MAIN_MODULE=2 without LINKABLE=1
71 # -s EXPORTED_FUNCTIONS="['_malloc','_dlopen','___THREW__','___threwValue']" \
72 # force inclusion of all standard libs (doesn't seem to work)
73 # https://emscripten.org/docs/compiling/Dynamic-Linking.html
74 # EMCC_FORCE_STDLIBS=1
75
76 # -s EXPORT_ALL=1
77
78 ################################ PLATFORMS ####################################
79 # see ../README.md for more build instruction details
80 # https://github.com/ccrma/chuck#readme
81
82 # make targets
83 .PHONY: mac mac-ub osx linux-all linux linux-pulse linux-jack linux-alsa test
84 mac mac-ub osx linux-all linux linux-pulse linux-jack linux-alsa: chuck
85
86 win32:
87 @echo "for Windows build, see visual-studio/chuck.sln"
88 # make -f $(CK_CORE_DIR)/makefile.x/makefile.win32
89
90
91 ########################### COMPILATION TOOLS #################################
92 # lexer
93 LEX=flex
94 # parser
95 YACC=bison
96 # c compiler
97 CC=gcc
98 # c++ compiler
99 CXX=g++
100 # linker
101 LD=$(CXX)
102
103
104 ############################# COMPILER FLAGS ##################################
105 # note: to compile with a specific c++ version, use the -std flag
106 # (e.g., -std=c++14, -std=c++17, -std=c++20, -std=c++23)
107 CFLAGS+=-I. -I$(CK_CORE_DIR) -I$(CK_CORE_DIR)/lo
108
109 # Code coverage
110
111 # enable chuck debug macros?
112 ifneq ($(COVERAGE_REPORT),)
113 CFLAGS+=-fprofile-arcs
114 CFLAGS+=-ftest-coverage
115 LDFLAGS+=-lgcov
116 LDFLAGS+=--coverage
117 endif
118
119 # track stats?
120 ifneq ($(CHUCK_STAT),)
121 CFLAGS+= -D__CHUCK_STAT_TRACK__
122 endif
123
124 # enable chuck debug macros?
125 ifneq ($(CHUCK_DEBUG),)
126 CFLAGS+= -g -D__CHUCK_DEBUG__
127 else
128 CFLAGS+= -O3
129 endif
130
131 # use 64-bit audio samples?
132 ifneq ($(USE_64_BIT_SAMPLE),)
133 CFLAGS+= -D__CHUCK_USE_64_BIT_SAMPLE__
134 endif
135
136 # strict error reporting?
137 ifneq ($(CHUCK_STRICT),)
138 CFLAGS+= -Wall
139 endif
140
141 # use X11? (Linux)
142 ifneq ($(USE_X11),)
143 CFLAGS+= -D__USE_X11__
144 LDFLAGS+= -lX11
145 endif
146
147 # ifneq ($(findstring arm,$(shell uname -m)),)
148 # some sort of arm platform- enable aggressive optimizations
149 # CFLAGS+= -ffast-math
150 # endif
151 # ge: commenting out; breaks Math.isinf() since it assumes all finite
152 # https://stackoverflow.com/questions/7420665/what-does-gccs-ffast-math-actually-do
153 # https://simonbyrne.github.io/notes/fastmath/
154
155
156 ######################## PLATFORM-SPECIFIC CONFIGS ############################
157
158 ifneq (,$(strip $(filter mac mac-ub osx bin-dist-mac,$(MAKECMDGOALS))))
159 include $(CK_CORE_DIR)/makefile.x/makefile.mac
160 endif
161
162 ifneq (,$(strip $(filter linux linux-all,$(MAKECMDGOALS))))
163 include $(CK_CORE_DIR)/makefile.x/makefile.linux
164 endif
165
166 ifneq (,$(strip $(filter linux-pulse,$(MAKECMDGOALS))))
167 include $(CK_CORE_DIR)/makefile.x/makefile.pulse
168 endif
169
170 ifneq (,$(strip $(filter linux-jack,$(MAKECMDGOALS))))
171 include $(CK_CORE_DIR)/makefile.x/makefile.jack
172 endif
173
174 ifneq (,$(strip $(filter linux-alsa,$(MAKECMDGOALS))))
175 include $(CK_CORE_DIR)/makefile.x/makefile.alsa
176 endif
177
178 # ifneq (,$(strip $(filter cygwin,$(MAKECMDGOALS))))
179 # include $(CK_CORE_DIR)/makefile.x/makefile.cygwin
180 # endif
181
182 # ifneq (,$(strip $(filter osx-rl,$(MAKECMDGOALS))))
183 # include $(CK_CORE_DIR)/makefile.x/makefile.rl
184 # endif
185
186
187 ########################## CHUCK CORE LIB TARGETS #############################
188 CXXOBJS_CORE+= chuck.o chuck_absyn.o chuck_parse.o chuck_errmsg.o \
189 chuck_frame.o chuck_symbol.o chuck_table.o \
190 chuck_vm.o chuck_instr.o chuck_scan.o chuck_type.o chuck_emit.o \
191 chuck_compile.o chuck_dl.o chuck_oo.o chuck_lang.o chuck_ugen.o \
192 chuck_otf.o chuck_stats.o chuck_shell.o chuck_io.o \
193 chuck_carrier.o chuck_globals.o hidio_sdl.o midiio_rtmidi.o \
194 rtmidi.o ugen_osc.o ugen_filter.o ugen_stk.o ugen_xxx.o ulib_ai.o \
195 ulib_doc.o ulib_machine.o ulib_math.o ulib_std.o ulib_opsc.o \
196 util_buffers.o util_console.o util_hid.o util_platforms.o \
197 util_opsc.o util_serial.o util_string.o util_thread.o \
198 uana_xform.o uana_extract.o
199 COBJS_CORE+= chuck.tab.o chuck.yy.o util_math.o util_network.o util_raw.o \
200 util_xforms.o
201 LO_COBJS_CORE+= lo/address.o lo/blob.o lo/bundle.o lo/message.o lo/method.o \
202 lo/pattern_match.o lo/send.o lo/server.o lo/server_thread.o lo/timetag.o
203
204
205 ############################ CHUCK HOST TARGETS ###############################
206 # host header include paths
207 CXXINC_HOST+= -I${RTAUDIO_DIR} -I${RTAUDIO_DIR}/include
208 # host source
209 CXXSRCS_HOST+= chuck_main.cpp chuck_audio.cpp chuck_console.cpp \
210 ${RTAUDIO_DIR}/RtAudio.cpp
211 # NB on some windows builds, ASIO src in RTAUDIO_DIR/include should be added
212
213
214 ############################ OBJECT FILE TARGETS ##############################
215 # host c++ object files
216 CXXOBJS_HOST=$(addprefix $(CK_HOST_DIR)/,$(CXXSRCS_HOST:.cpp=.o))
217 # c object files
218 COBJS=$(COBJS_HOST) $(addprefix $(CK_CORE_DIR)/,$(COBJS_CORE))
219 # c++ object files
220 CXXOBJS=$(CXXOBJS_HOST) $(addprefix $(CK_CORE_DIR)/,$(CXXOBJS_CORE))
221 # liblo object files
222 LO_COBJS=$(addprefix $(CK_CORE_DIR)/,$(LO_COBJS_CORE))
223 # libsndfile objects files (if compiling locally)
224 SF_COBJS=$(addprefix $(CK_CORE_DIR)/,$(SF_CSRCS:.c=.o))
225 # sum of object files
226 OBJS=$(COBJS) $(CXXOBJS) $(LO_COBJS) $(SF_COBJS)
227
228
229 ############################ ADDITIONAL FLAGS #################################
230 # for liblo headers
231 LO_CFLAGS=-DHAVE_CONFIG_H -I.
232
233 # remove -arch options
234 CFLAGSDEPEND=$(CFLAGS)
235
236 ifneq (,$(ARCHS))
237 ARCHOPTS=$(addprefix -arch ,$(ARCHS))
238 else
239 ARCHOPTS=
240 endif
241
242 # macOS universal binary
243 ifneq (,$(strip $(filter mac-ub,$(MAKECMDGOALS))))
244 ARCHOPTS=-arch arm64 -arch x86_64
245 ARCH_ARGS=MAC_UB=true
246 CFLAGS+=-D__MACOS_UB__
247 endif
248
249
250 ############################ DISTRIBUTION INFO ################################
251 # release notes
252 NOTES=AUTHORS DEVELOPERS INSTALL LICENSE.GPL LICENSE.MIT QUICKSTART README.md THANKS VERSIONS
253 # where to put the newly constructed distribution
254 DIST_DIR=chuck-$(CK_VERSION)
255 # root directory where the above is found
256 DIST_ROOT=..
257
258 # pull in dependency info for *existing* .o files
259 -include $(OBJS:.o=.d)
260
261
262 ############################# MAIN COMPILATION ################################
263 chuck-core:
264 @echo -------------
265 @echo [chuck-core]: compiling...
266 $(MAKE) $(MAKECMDGOALS) -C $(CK_CORE_DIR) $(ARCH_ARGS) CXXFLAGS="$(CXXFLAGS)"
267 @echo -------------
268
269 # host compiler flags
270 CFLAGS_HOST=${CFLAGS} -I${RTAUDIO_DIR}
271 CFLAGSDEPEND_HOST=${CFLAGSDEPEND} ${CFLAGS_HOST}
272
273 # compile chuck
274 chuck: chuck-core $(COBJS_HOST) $(CXXOBJS_HOST)
275 $(LD) -o chuck $(OBJS) $(LDFLAGS) $(ARCHOPTS)
276
277 # build receipt for host c objects
278 $(COBJS_HOST): %.o: %.c
279 $(CC) $(CFLAGS_HOST) $(ARCHOPTS) -c $< -o $@
280 @$(CC) -MM -MQ "$@" $(CFLAGSDEPEND_HOST) $< > $*.d
281
282 # build receipt for host c++ objects
283 $(CXXOBJS_HOST): %.o: %.cpp
284 $(CXX) $(CFLAGS_HOST) $(CXXFLAGS) $(ARCHOPTS) -c $< -o $@
285 @$(CXX) -MM -MQ "$@" $(CFLAGSDEPEND_HOST) $< > $*.d
286
287
288 ############################## RUN UNIT TEST ##################################
289 .PHONY: test
290 test:
291 @make -C test
292
293 ###################### GENERATE CODE COVERAGE REPORT ###########################
294 .PHONY: coverage
295 coverage: test
296 lcov --capture --directory . --output-file coverage.info
297 genhtml coverage.info --output-directory report
298
299
300 ####################### GENERATE API DOCUMENTATION ############################
301 .PHONY: doc ckdoc
302 doc ckdoc:
303 @make -C scripts/ckdoc
304
305
306 ############################### DISTRIBUTION ##################################
307 # distribution meta-targets
308 .PHONY: src-dist
309
310 # chuck source distribution
311 src-dist:
312 # clean out old dists (ASSUME: done from chuck)
313 rm -rf $(DIST_DIR) $(DIST_DIR){.tgz,.zip}
314 # create directories
315 mkdir $(DIST_DIR) $(DIST_DIR)/src $(DIST_DIR)/examples
316 # copy src
317 git archive HEAD src | tar -x -C $(DIST_DIR)
318 # rm -r $(DIST_DIR)/src/test
319 # copy examples
320 git archive HEAD examples | tar -x -C $(DIST_DIR)
321 # copy notes
322 cp $(addprefix ./,$(NOTES)) $(DIST_DIR)
323 # tar/gzip
324 tar czf $(DIST_DIR).tgz $(DIST_DIR)
325
326
327 ########################## MANUAL INSTALL ###################################
328 # manually install chuck
329 DESTDIR?=/usr/local/bin
330
331 install:
332 mkdir -p $(DESTDIR)
333 cp $(wildcard chuck chuck.exe) $(DESTDIR)/
334 chmod 755 $(DESTDIR)/$(wildcard chuck chuck.exe)
335
336 ifneq ($(CK_TARGET),)
337 .DEFAULT_GOAL:=$(CK_TARGET)
338 ifeq ($(MAKECMDGOALS),)
339 MAKECMDGOALS:=$(.DEFAULT_GOAL)
340 endif
341 endif
342
343
344 ############################## CLEAN UP #######################################
345 .PHONY: clean-src
346 clean-src:
347 @echo "removing compiled output..."
348 @rm -rf $(wildcard chuck chuck.exe) *.o *.d */*.{o,d} */*/*.{o,d} \
349 $(OBJS) $(patsubst %.o,%.d,$(OBJS))*~ $(CK_CORE_DIR)/chuck.output \
350 $(CK_CORE_DIR)/chuck.tab.h $(CK_CORE_DIR)/chuck.tab.c $(CK_CORE_DIR)/chuck.yy.c \
351 $(DIST_ROOT)/$(DIST_DIR) $(DIST_ROOT)/$(DIST_DIR){,.tgz,.zip} \
352 host-web/webchuck/js/webchuck.js host-web/webchuck/js/webchuck.wasm \
353 Release Debug \
354 @rf -rf report/ */*.gcov */*.gcda */*.gcno */*.info
355
356 .PHONY: clean
357 clean: clean-src
358 @make -C scripts/ckdoc clean
359 @make -C host-examples clean
360 @make -C test clean