You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 10KB

8 years ago
8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. RACK_DIR ?= .
  2. EDITION := Free
  3. VERSION_MAJOR := 2
  4. VERSION := $(shell jq -r .version Core.json)
  5. FLAGS += -Iinclude -Idep/include
  6. include arch.mk
  7. # Sources and build flags
  8. SOURCES += dep/nanovg/src/nanovg.c
  9. SOURCES += dep/osdialog/osdialog.c
  10. SOURCES += dep/oui-blendish/blendish.c
  11. SOURCES += dep/pffft/pffft.c dep/pffft/fftpack.c
  12. SOURCES += dep/tinyexpr/tinyexpr.c
  13. SOURCES += $(wildcard src/*.c src/*/*.c)
  14. SOURCES += $(wildcard src/*.cpp src/*/*.cpp)
  15. build/src/common.cpp.o: FLAGS += -D_APP_VERSION=$(VERSION)
  16. build/dep/tinyexpr/tinyexpr.c.o: FLAGS += -DTE_POW_FROM_RIGHT -DTE_NAT_LOG
  17. FLAGS += -fPIC
  18. LDFLAGS += -shared
  19. ifdef ARCH_LIN
  20. SED := sed -i
  21. TARGET := libRack.so
  22. SOURCES += dep/osdialog/osdialog_zenity.c
  23. # This prevents static variables in the DSO (dynamic shared object) from being preserved after dlclose().
  24. # I don't really understand the side effects (see GCC manual), but so far tests are positive.
  25. FLAGS += -fno-gnu-unique
  26. LDFLAGS += -Wl,--whole-archive
  27. LDFLAGS += -static-libstdc++ -static-libgcc
  28. LDFLAGS += dep/lib/libGLEW.a dep/lib/libglfw3.a dep/lib/libjansson.a dep/lib/libcurl.a dep/lib/libssl.a dep/lib/libcrypto.a dep/lib/libarchive.a dep/lib/libzstd.a dep/lib/libspeexdsp.a dep/lib/libsamplerate.a dep/lib/librtmidi.a dep/lib/librtaudio.a
  29. LDFLAGS += -Wl,--no-whole-archive
  30. LDFLAGS += -lpthread -lGL -ldl -lX11 -lasound -ljack -lpulse -lpulse-simple
  31. endif
  32. ifdef ARCH_MAC
  33. SED := sed -i ''
  34. TARGET := libRack.dylib
  35. SOURCES += $(wildcard src/*.m src/*/*.m)
  36. SOURCES += $(wildcard src/*.mm src/*/*.mm)
  37. SOURCES += dep/osdialog/osdialog_mac.m
  38. LDFLAGS += -lpthread -ldl
  39. LDFLAGS += -framework SystemConfiguration -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -framework CoreAudio -framework CoreMIDI -framework AVFoundation
  40. LDFLAGS += -Wl,-all_load
  41. LDFLAGS += dep/lib/libGLEW.a dep/lib/libglfw3.a dep/lib/libjansson.a dep/lib/libcurl.a dep/lib/libssl.a dep/lib/libcrypto.a -Wl,-load_hidden,dep/lib/libarchive.a -Wl,-load_hidden,dep/lib/libzstd.a dep/lib/libspeexdsp.a dep/lib/libsamplerate.a -Wl,-load_hidden,dep/lib/librtmidi.a -Wl,-load_hidden,dep/lib/librtaudio.a
  42. endif
  43. ifdef ARCH_WIN
  44. SED := sed -i
  45. TARGET := libRack.dll
  46. SOURCES += dep/osdialog/osdialog_win.c
  47. LDFLAGS += -municode
  48. LDFLAGS += -Wl,--export-all-symbols
  49. LDFLAGS += -Wl,--out-implib,$(TARGET).a
  50. LDFLAGS += -Wl,-Bstatic -Wl,--whole-archive
  51. LDFLAGS += dep/lib/libglew32.a dep/lib/libglfw3.a dep/lib/libjansson.a dep/lib/libspeexdsp.a dep/lib/libsamplerate.a dep/lib/libarchive_static.a dep/lib/libzstd.a dep/lib/libcurl.a dep/lib/libssl.a dep/lib/libcrypto.a dep/lib/librtaudio.a dep/lib/librtmidi.a
  52. LDFLAGS += -Wl,-Bdynamic -Wl,--no-whole-archive
  53. LDFLAGS += -lpthread -lopengl32 -lgdi32 -lws2_32 -lcomdlg32 -lole32 -ldsound -lwinmm -lksuser -lshlwapi -lmfplat -lmfuuid -lwmcodecdspuuid -ldbghelp -lcrypt32
  54. endif
  55. # Some libraries aren't needed by plugins and might conflict with DAWs that load libRack, so make their symbols local to libRack instead of global (default).
  56. # --exclude-libs is unavailable on Apple ld
  57. ifndef ARCH_MAC
  58. LDFLAGS += -Wl,--exclude-libs,libzstd.a
  59. LDFLAGS += -Wl,--exclude-libs,libarchive.a
  60. LDFLAGS += -Wl,--exclude-libs,librtmidi.a
  61. LDFLAGS += -Wl,--exclude-libs,librtaudio.a
  62. endif
  63. include compile.mk
  64. # Standalone adapter
  65. STANDALONE_SOURCES += adapters/standalone.cpp
  66. ifdef ARCH_LIN
  67. STANDALONE_TARGET := Rack
  68. STANDALONE_LDFLAGS += -static-libstdc++ -static-libgcc
  69. STANDALONE_LDFLAGS += -Wl,-rpath=.
  70. endif
  71. ifdef ARCH_MAC
  72. STANDALONE_TARGET := Rack
  73. STANDALONE_LDFLAGS += -stdlib=libc++
  74. endif
  75. ifdef ARCH_WIN
  76. STANDALONE_TARGET := Rack.exe
  77. STANDALONE_LDFLAGS += -mwindows
  78. # 1MiB stack size to match MSVC
  79. STANDALONE_LDFLAGS += -Wl,--stack,0x100000
  80. STANDALONE_OBJECTS += build/Rack.res
  81. endif
  82. STANDALONE_OBJECTS += $(TARGET)
  83. $(STANDALONE_TARGET): $(STANDALONE_SOURCES) $(STANDALONE_OBJECTS)
  84. $(CXX) $(CXXFLAGS) -o $@ $^ $(STANDALONE_LDFLAGS)
  85. # Convenience targets
  86. all: $(TARGET) $(STANDALONE_TARGET)
  87. dep:
  88. $(MAKE) -C dep
  89. cleandep:
  90. $(MAKE) -C dep clean
  91. run: $(STANDALONE_TARGET)
  92. ./$< -d
  93. runr: $(STANDALONE_TARGET)
  94. ./$<
  95. debug: $(STANDALONE_TARGET)
  96. ifdef ARCH_MAC
  97. lldb -- ./$< -d
  98. endif
  99. ifdef ARCH_WIN
  100. gdb --args ./$< -d
  101. endif
  102. ifdef ARCH_LIN
  103. gdb --args ./$< -d
  104. endif
  105. perf: $(STANDALONE_TARGET)
  106. # Requires perf
  107. perf record --call-graph dwarf -o perf.data ./$< -d
  108. # Analyze with hotspot (https://github.com/KDAB/hotspot) for example
  109. hotspot perf.data
  110. rm perf.data
  111. valgrind: $(STANDALONE_TARGET)
  112. # --gen-suppressions=yes
  113. # --leak-check=full
  114. valgrind --suppressions=valgrind.supp ./$< -d
  115. clean:
  116. rm -rfv build dist $(TARGET) $(STANDALONE_TARGET) *.a
  117. # Windows resources
  118. build/%.res: %.rc
  119. ifdef ARCH_WIN
  120. windres $^ -O coff -o $@
  121. endif
  122. # Plugin helper
  123. plugins:
  124. ifdef CMD
  125. for f in plugins/*; do (cd "$$f" && $(CMD)); done
  126. else
  127. for f in plugins/*; do $(MAKE) -C "$$f"; done
  128. endif
  129. # The following targets are not supported for public use
  130. DIST_NAME = Rack$(EDITION)-$(VERSION)-$(ARCH_NAME)
  131. ifdef ARCH_MAC
  132. DIST_BUNDLE := VCV Rack $(VERSION_MAJOR) $(EDITION).app
  133. else
  134. DIST_DIR := Rack$(VERSION_MAJOR)$(EDITION)
  135. endif
  136. DIST_MD := $(wildcard *.md)
  137. DIST_HTML := $(patsubst %.md, build/%.html, $(DIST_MD))
  138. DIST_RES := res cacert.pem Core.json template.vcv LICENSE-GPLv3.txt $(DIST_HTML)
  139. DIST_SDK_DIR := Rack-SDK
  140. DIST_SDK = Rack-SDK-$(VERSION)-$(ARCH_NAME).zip
  141. dist: $(TARGET) $(STANDALONE_TARGET) $(DIST_HTML)
  142. mkdir -p dist
  143. ifdef ARCH_LIN
  144. mkdir -p dist/"$(DIST_DIR)"
  145. cp $(TARGET) dist/"$(DIST_DIR)"/
  146. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  147. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  148. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  149. # Manually check that no nonstandard shared libraries are linked
  150. ldd dist/"$(DIST_DIR)"/$(TARGET)
  151. ldd dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  152. # Copy resources
  153. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  154. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_DIR)"/
  155. endif
  156. ifdef ARCH_MAC
  157. mkdir -p dist/"$(DIST_BUNDLE)"
  158. mkdir -p dist/"$(DIST_BUNDLE)"/Contents
  159. mkdir -p dist/"$(DIST_BUNDLE)"/Contents/Resources
  160. mkdir -p dist/"$(DIST_BUNDLE)"/Contents/MacOS
  161. cp $(TARGET) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  162. cp $(STANDALONE_TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/
  163. $(STRIP) -S dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  164. $(STRIP) -S dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  165. install_name_tool -change $(TARGET) @executable_path/../Resources/$(TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  166. # Manually check that no nonstandard shared libraries are linked
  167. otool -L dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  168. otool -L dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  169. # Copy resources
  170. cp Info.plist dist/"$(DIST_BUNDLE)"/Contents/
  171. $(SED) 's/{VERSION}/$(VERSION)/g' dist/"$(DIST_BUNDLE)"/Contents/Info.plist
  172. cp -R icon.icns dist/"$(DIST_BUNDLE)"/Contents/Resources/
  173. cp -R $(DIST_RES) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  174. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_BUNDLE)"/Contents/Resources/
  175. endif
  176. ifdef ARCH_WIN
  177. mkdir -p dist/"$(DIST_DIR)"
  178. cp $(TARGET) dist/"$(DIST_DIR)"/
  179. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  180. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  181. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  182. # Copy resources
  183. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  184. cp /mingw64/bin/libwinpthread-1.dll dist/"$(DIST_DIR)"/
  185. cp /mingw64/bin/libstdc++-6.dll dist/"$(DIST_DIR)"/
  186. cp /mingw64/bin/libgcc_s_seh-1.dll dist/"$(DIST_DIR)"/
  187. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_DIR)"/
  188. endif
  189. sdk: $(DIST_HTML)
  190. mkdir -p dist/$(DIST_SDK_DIR)
  191. cp -R include *.mk helper.py $(DIST_HTML) dist/$(DIST_SDK_DIR)/
  192. mkdir -p dist/$(DIST_SDK_DIR)/dep
  193. cp -R dep/include dist/$(DIST_SDK_DIR)/dep/
  194. ifdef ARCH_LIN
  195. cp $(TARGET) dist/$(DIST_SDK_DIR)/
  196. $(STRIP) -s dist/$(DIST_SDK_DIR)/$(TARGET)
  197. endif
  198. ifdef ARCH_MAC
  199. cp $(TARGET) dist/$(DIST_SDK_DIR)/
  200. $(STRIP) -S dist/$(DIST_SDK_DIR)/$(TARGET)
  201. endif
  202. ifdef ARCH_WIN
  203. cp $(TARGET).a dist/$(DIST_SDK_DIR)/
  204. endif
  205. package:
  206. ifdef ARCH_LIN
  207. # Make ZIP
  208. cd dist && zip -q -9 -r $(DIST_NAME).zip "$(DIST_DIR)"
  209. endif
  210. ifdef ARCH_MAC
  211. # Clean up and sign bundle
  212. xattr -cr dist/"$(DIST_BUNDLE)"
  213. codesign --verbose --sign "Developer ID Application: Andrew Belt (V8SW9J626X)" --options runtime --entitlements Entitlements.plist --timestamp --deep dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET) dist/"$(DIST_BUNDLE)"
  214. codesign --verify --deep --strict --verbose=2 dist/"$(DIST_BUNDLE)"
  215. # Make standalone PKG
  216. mkdir -p dist/Component
  217. cp -R dist/"$(DIST_BUNDLE)" dist/Component/
  218. pkgbuild --identifier com.vcvrack.rack --component-plist Component.plist --root dist/Component --install-location /Applications dist/Component.pkg
  219. # Make PKG
  220. productbuild --distribution Distribution.xml --package-path dist dist/$(DIST_NAME).pkg
  221. productsign --sign "Developer ID Installer: Andrew Belt (V8SW9J626X)" dist/$(DIST_NAME).pkg dist/$(DIST_NAME)-signed.pkg
  222. mv dist/$(DIST_NAME)-signed.pkg dist/$(DIST_NAME).pkg
  223. endif
  224. ifdef ARCH_WIN
  225. # Make NSIS installer
  226. # pacman -S mingw-w64-x86_64-nsis
  227. makensis -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION=$(VERSION) "-XOutFile dist/$(DIST_NAME).exe" installer.nsi
  228. endif
  229. # SDK
  230. cd dist && zip -q -9 -r $(DIST_SDK) $(DIST_SDK_DIR)
  231. lipo:
  232. ifndef OTHER_RACK_DIR
  233. $(error OTHER_RACK_DIR not defined)
  234. endif
  235. ifdef ARCH_MAC
  236. # App bundle
  237. lipo -create -output dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET) dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET) $(OTHER_RACK_DIR)/dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  238. lipo -create -output dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET) $(OTHER_RACK_DIR)/dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  239. lipo -create -output dist/$(DIST_SDK_DIR)/$(TARGET) dist/$(DIST_SDK_DIR)/$(TARGET) $(OTHER_RACK_DIR)/dist/$(DIST_SDK_DIR)/$(TARGET)
  240. # Fundamental package
  241. cp $(OTHER_RACK_DIR)/dist/"$(DIST_BUNDLE)"/Contents/Resources/Fundamental-*.vcvplugin dist/"$(DIST_BUNDLE)"/Contents/Resources/
  242. endif
  243. notarize:
  244. ifdef ARCH_MAC
  245. # Submit installer package to Apple
  246. xcrun notarytool submit --keychain-profile "VCV" --wait dist/$(DIST_NAME).pkg
  247. # Mark app as notarized
  248. xcrun stapler staple dist/$(DIST_NAME).pkg
  249. # Check notarization
  250. stapler validate dist/$(DIST_NAME).pkg
  251. endif
  252. install: uninstall
  253. ifdef ARCH_MAC
  254. sudo installer -pkg dist/$(DIST_NAME).pkg -target /
  255. endif
  256. uninstall:
  257. ifdef ARCH_MAC
  258. sudo rm -rf /Applications/"$(DIST_BUNDLE)"
  259. endif
  260. cleandist:
  261. rm -rfv dist
  262. .DEFAULT_GOAL := all
  263. .PHONY: all dep run debug clean plugins dist sdk package lipo notarize