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