1#
2# FAUST compiler makefile
3#
4
5# start to determine the current platform
6system := $(shell uname -s)
7# normalizes MINGW versions
8system := $(shell echo $(system) | grep MINGW > /dev/null && echo MINGW || echo $(system))
9
10#===============================================================
11# output directories
12FAUSTDIR ?= faustdir
13IOSDIR   := iosdir
14VERSION := 2.37.3
15
16#===============================================================
17# current generator and backends
18CACHE  = $(FAUSTDIR)/CMakeCache.txt
19BCACHE = $(FAUSTDIR)/backends.txt
20TCACHE = $(FAUSTDIR)/targets.txt
21LCACHE = $(FAUSTDIR)/libsdir.txt
22ifeq ($(system),  MINGW)
23	GENERATOR ?= $(shell [ -f $(CACHE) ] && (grep CMAKE_GENERATOR:INTERNAL $(CACHE) | cut -d= -f2) || echo MSYS Makefiles)
24	NATIVEPACK = winpack
25else
26	PREFIX ?= /usr/local
27	GENERATOR ?= $(shell [ -f $(CACHE) ] && (grep CMAKE_GENERATOR:INTERNAL $(CACHE) | cut -d= -f2) || echo Unix Makefiles)
28endif
29DESTDIR ?=
30
31ifeq ($(system),  MINGW)
32	NATIVEPACK = winpack
33else ifeq ($(system),  Darwin)
34	NATIVEPACK = macpack
35else
36	NATIVEPACK = linuxpack
37endif
38DESTDIR ?=
39
40
41.PHONY: faust install uninstall osc http package wasmglue
42
43MAKE ?= make
44
45WORKLET ?= no
46WORKLETOPT = "-DWORKLET=off"
47ifeq ($(WORKLET), on)
48WORKLETOPT = "-DWORKLET=on"
49endif
50
51CMAKEOPT ?= -DCMAKE_BUILD_TYPE=Release $(WORKLETOPT)
52BUILDOPT ?= --config Release
53
54#CMAKEOPT ?= -DCMAKE_BUILD_TYPE=Debug $(WORKLETOPT)
55#BUILDOPT ?= --config Debug
56
57#===============================================================
58# options
59BACKENDS ?= $(shell [ -f $(BCACHE) ] && (grep BACKENDS $(BCACHE) | cut -d= -f2) || echo regular.cmake)
60TARGETS  ?= $(shell [ -f $(TCACHE) ] && (grep TARGETS $(TCACHE) | cut -d= -f2) || echo regular.cmake)
61LIBSDIR  ?= $(shell [ -f $(LCACHE) ] && (grep LIBSDIR $(LCACHE) | cut -d= -f2) || echo lib)
62EMCC 	 ?= emcc
63
64#===============================================================
65ifeq ($(GENERATOR), Xcode)
66	PROJ = $(FAUSTDIR)/faust.xcodeproj
67endif
68ifneq (,$(findstring Makefile, $(GENERATOR)))
69	PROJ = $(FAUSTDIR)/Makefile
70endif
71ifneq (,$(findstring Visual Studio,$(GENERATOR)))
72	PROJ = $(FAUSTDIR)/faust.sln
73endif
74
75#===============================================================
76# main targets
77all: $(PROJ)
78	cmake --build $(FAUSTDIR) $(BUILDOPT)
79
80full:
81	$(MAKE) cmake BACKENDS=all.cmake TARGETS=all.cmake
82	cmake --build $(FAUSTDIR) $(BUILDOPT)
83
84clean:
85	cmake --build $(FAUSTDIR) --target clean
86
87distclean:
88	rm -rf $(FAUSTDIR)
89
90
91#===============================================================
92help:
93	@echo "-------- FAUST compiler makefile --------"
94	@echo "Available targets are:"
95	@echo " 'all' (default) : builds the current targets (as defined by your targets setup)."
96	@echo " 'full'          : builds the all targets with all backends."
97	@echo
98	@echo "Targets that require specific setup (see TARGETS option):"
99	@echo " 'faust' 	 : builds the Faust compiler."
100	@echo " 'osc'        : builds the static Faust OSC libraries"
101	@echo " 'http'       : builds the static Faust HTTPD libraries"
102	@echo " 'staticlib'  : builds the libfaust library in static mode."
103	@echo " 'dynamiclib' : builds the libfaust library in dynamic mode."
104	@echo " 'oscdynamic' : builds the OSC library in dynamic mode."
105	@echo " 'httpdynamic': builds the HTTPD library in dynamic mode."
106	@echo " 'oscandroid' : builds the OSC library for Android."
107	@echo " 'ioslib'     : builds the libfaust static lib for iOS (makes use of the ios.cmake backend)"
108	@echo
109	@echo "Cleaning:"
110	@echo " 'clean'      : removes the output of the 'all' targets"
111	@echo " 'distclean'  : removes the 'FAUSTDIR' folder ($(FAUSTDIR)) but preserves the bin and lib folders"
112	@echo
113	@echo "Targets excluded from all:"
114	@echo " 'wasmlib'    : builds libfaust as a WebAssembly library"
115	@echo " 'wasmglue'   : builds the WebAssembly glue library."
116	@echo
117	@echo "Available options:"
118	@echo "  FAUSTDIR=<dir>              : the compilation directory. Default to '$(FAUSTDIR)'"
119	@echo "  LIBSDIR                     : the libraries destination directory, default: $(LIBSDIR)"
120	@echo "  GENERATOR=<a cmake generator>: see cmake -h. Default to '$(GENERATOR)'"
121	@echo "  CMAKEOPT=<cmake options>    : pass options to cmake for project generation."
122	@echo "  BUILDOPT=<cmake options>    : pass options to cmake at build time (default to $(BUILDOPT))."
123	@echo "  BACKENDS=<backends file>    : see 'Backends' below"
124	@echo "  TARGETS=<targets file>      : see 'Targets' below"
125	@echo "  WORKLET                     : Compile wasm glue library for worklet (default is off)"
126	@echo
127	@echo "Backends:"
128	@echo "  the Faust backends currently included are described in the '$(BACKENDS)' file"
129	@echo "  you can freely customize this file or use another file with the BACKENDS option"
130	@echo
131	@echo "Targets:"
132	@echo "  the targets currently included are described in the '$(TARGETS)' file"
133	@echo "  you can freely customize this file or use another file with the TARGETS option"
134	@echo
135	@echo "Utilities targets:"
136	@echo " 'cmake'      : regenerate the project using the current config"
137	@echo " 'universal'  : [MacOSX] set the universal binaries option ON."
138	@echo " 'native'     : [MacOSX] set the universal binaries option OFF."
139	@echo " 'verbose'    : turn the verbose makefile option ON."
140	@echo " 'silent'     : turn the verbose makefile option OFF."
141	@echo " 'jsscripts'  : to rebuild javascript resources (from architecture/httpdlib)."
142	@echo
143	@echo "Installation targets:"
144	@echo " 'install'    : install faust to the target directory (default to $(DESTDIR)$(PREFIX)),"
145	@echo " 'uninstall'  : remove previously installed files,"
146	@echo "Installation options:"
147	@echo " 'DESTDIR'    : the destination directory,"
148	@echo " 'PREFIX'     : the destination prefix,"
149	@echo "  Note that when using a relative path, it is relative to FAUSTDIR ($(FAUSTDIR))"
150	@echo "------ see also the README.md file ------"
151	@echo
152	@echo "Packaging targets:"
153	@echo " 'package'    : build a Faust package for the current platform"
154	@echo " 'release'    : build a Faust release (MacOS only)"
155	@echo "                includes faust, faustgen and dist packages"
156
157
158faust: $(PROJ)
159	cmake --build $(FAUSTDIR) --target faust $(BUILDOPT)
160
161osc: $(PROJ)
162	cmake --build $(FAUSTDIR) --target oscstatic $(BUILDOPT)
163
164oscdynamic: $(PROJ)
165	cmake --build $(FAUSTDIR) --target oscdynamic $(BUILDOPT)
166
167oscandroid: $(PROJ)
168	cd ../architecture/osclib/android/&& ndk-build
169
170http: $(PROJ)
171	cmake --build $(FAUSTDIR) --target httpstatic $(BUILDOPT)
172
173httpdynamic: $(PROJ)
174	cmake --build $(FAUSTDIR) --target httpdynamic $(BUILDOPT)
175
176jsscripts:
177	$(MAKE) -C ../architecture/httpdlib/src/hexa
178
179#===============================================================
180# packaging
181#===============================================================
182# don't change the PACK variable, files are put at first hierarchy level
183PACK := package/Faust-$(VERSION)
184package:
185	$(MAKE) $(NATIVEPACK)
186
187winpack:
188	cd $(FAUSTDIR) && cmake -DUSE_LLVM_CONFIG=off -DPACK=on -C ../bakckends/most.cmake -C ../targets/most.cmake ..
189	$(MAKE)
190	cd $(FAUSTDIR) && cpack -G NSIS64
191	mv $(FAUSTDIR)/Faust-*.exe .
192
193macpack: package/README.html
194	-[ -d $(PACK) ] && rm -rf $(PACK)
195	$(MAKE) cmake BACKENDs=all.cmake TARGETS=all.cmake  CMAKEOPT="-DDEPLOYMENT_TARGET=on"
196	$(MAKE) install PREFIX=../$(PACK)/Faust-$(VERSION)
197	$(MAKE) mactools FAUSTDIR=../../build/$(PACK)/Faust-$(VERSION)
198	cp package/INSTALL.html $(PACK)
199	cp package/README.html $(PACK)
200	hdiutil create Faust-$(VERSION).dmg -fs HFS+ -srcfolder $(PACK) -format UDBZ -ov
201
202mactools:
203	$(MAKE) -C ../tools/benchmark FAUST=$(FAUSTDIR)/bin/faust TARGETS="dynamic-faust faustbench-llvm"
204	$(MAKE) -C ../tools/benchmark install PREFIX=$(FAUSTDIR) FAUST=$(FAUSTDIR)/bin/faust TARGETS="dynamic-faust faustbench-llvm"
205
206linuxpack:
207	@echo Linux packaging not implemented.
208
209package/README.html: ../README.md
210	echo "<!DOCTYPE html><html><xmp>" > package/README.html
211	cat ../README.md >> package/README.html
212	echo "</xmp>" >> package/README.html
213	echo "<script src=http://strapdownjs.com/v/0.2/strapdown.js></script>" >> package/README.html
214	echo "</html>" >> package/README.html
215
216
217#===============================================================
218# release
219#===============================================================
220FAUSTLIVE ?=../../faustlive
221release: FAUSTGEN=../embedded/faustgen
222release: APATH=$(shell pwd)
223release:
224	git pull --rebase
225	@echo "################## Building faust package ###################"
226	$(MAKE) cmake BACKENDS=all.cmake TARGETS=all.cmake CMAKEOPT="-DDEPLOYMENT_TARGET=on"
227	$(MAKE) all
228	$(MAKE) package
229	@[ -d Release-$(VERSION) ] || mkdir Release-$(VERSION)
230	rm -rf Release-$(VERSION)/*
231	cp Faust-$(VERSION).dmg Release-$(VERSION)
232	$(MAKE) install PREFIX=$(HOME)/Faust-$(VERSION)
233	@echo "################## Building faust src distribution ###################"
234	$(MAKE) -C .. dist
235	mv ../faust-$(VERSION).tar.gz Release-$(VERSION)
236	$(MAKE) faustgen
237	$(MAKE) faustlive
238
239faustgen:
240	@echo "################## Building faustgen package ###################"
241	$(MAKE) -C $(FAUSTGEN) clean
242	$(MAKE) -C $(FAUSTGEN) FAUST=$(HOME)/Faust-$(VERSION)/bin/faust
243	$(MAKE) -C $(FAUSTGEN) package
244	cp $(FAUSTGEN)/package/*.dmg Release-$(VERSION)
245
246faustlive: APATH=$(shell pwd)
247faustlive:
248	@echo "################## Building faustlive package ###################"
249	$(MAKE) -C $(FAUSTLIVE)/Build release FAUST=$(HOME)/Faust-$(VERSION)/bin/faust DEST=$(APATH)/Release-$(VERSION)
250
251
252#===============================================================
253# building universal binaries on macos
254#===============================================================
255universal: $(FAUSTDIR)
256	cd $(FAUSTDIR) && cmake -DUNIVERSAL=ON ..
257
258native: $(FAUSTDIR)
259	cd $(FAUSTDIR) && cmake -DUNIVERSAL=OFF ..
260
261
262#===============================================================
263# building libraries
264#===============================================================
265staticlib: $(PROJ)
266	cmake --build $(FAUSTDIR) --target staticlib $(BUILDOPT)
267
268dynamiclib: $(PROJ)
269	cmake --build $(FAUSTDIR) --target dynamiclib $(BUILDOPT)
270
271
272#===============================================================
273# building libfaust.a for ios
274#===============================================================
275ioslib: $(IOSDIR) $(IOSDIR)/faust.xcodeproj
276	cmake --build $(IOSDIR) --target staticlib $(BUILDOPT)
277	cmake --build $(IOSDIR) --target oscstatic $(BUILDOPT)
278
279$(IOSDIR)/faust.xcodeproj: CMakeLists.txt backends/ios.cmake
280	cd $(IOSDIR) && cmake -C ../backends/ios.cmake ..  -DINCLUDE_STATIC=on -DINCLUDE_HTTP=off -G Xcode
281
282
283#===============================================================
284# misc targets
285#===============================================================
286$(FAUSTDIR):
287	mkdir $(FAUSTDIR)
288
289$(IOSDIR):
290	mkdir $(IOSDIR)
291
292$(PROJ):
293	$(MAKE) cmake
294
295verbose: $(FAUSTDIR)
296	cd $(FAUSTDIR) && cmake -DCMAKE_VERBOSE_MAKEFILE=ON ..
297
298silent: $(FAUSTDIR)
299	cd $(FAUSTDIR) && cmake -DCMAKE_VERBOSE_MAKEFILE=OFF ..
300
301cmake: $(FAUSTDIR)
302	cd $(FAUSTDIR) && cmake -C ../backends/$(BACKENDS) -C ../targets/$(TARGETS) $(CMAKEOPT) -DLIBSDIR=$(LIBSDIR) -G '$(GENERATOR)' ..
303	@echo BACKENDS=$(BACKENDS) > $(BCACHE)
304	@echo TARGETS=$(TARGETS) > $(TCACHE)
305	@echo LIBSDIR=$(LIBSDIR) > $(LCACHE)
306
307
308#===============================================================
309# building faust with emscripten
310#===============================================================
311wasmlib: $(FAUSTDIR) $(FAUSTDIR)/Makefile
312	@$(MAKE) checkemcc
313	mkdir -p wasm-libraries && cp ../libraries/*.lib ../libraries/old/*.lib wasm-libraries
314	cmake --build $(FAUSTDIR) --target wasmlib $(BUILDOPT)
315	rm -rf wasm-libraries
316
317wasmglue: $(FAUSTDIR) $(FAUSTDIR)/Makefile
318	@$(MAKE) checkemcc
319	cmake --build $(FAUSTDIR) --target wasmglue $(BUILDOPT)
320
321checkemcc:
322	@which $(EMCC) > /dev/null || (echo "### emcc must be available from your PATH."; false;)
323
324
325#===============================================================
326# faust install
327#===============================================================
328installLog := $(FAUSTDIR)/install_manifest.txt
329install:
330	if test -d ../.git; then git submodule update --init; fi
331	cd $(FAUSTDIR) && cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX)
332	cmake  --build $(FAUSTDIR) --target install
333
334uninstall: $(installLog)
335	$(shell cat $(installLog) | xargs rm -f)
336	rm -f $(installLog)
337
338#===============================================================
339undefined:
340	$(error System is undefined, not target available)
341