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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. RACK_DIR ?= .
  2. VERSION_MAJOR := 2
  3. VERSION := 2.2.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 dep/lib/libarchive.a dep/lib/libzstd.a dep/lib/libspeexdsp.a dep/lib/libsamplerate.a dep/lib/librtmidi.a 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. LDFLAGS += -Wl,--exclude-libs,libzstd.a
  54. LDFLAGS += -Wl,--exclude-libs,libarchive.a
  55. LDFLAGS += -Wl,--exclude-libs,librtmidi.a
  56. LDFLAGS += -Wl,--exclude-libs,librtaudio.a
  57. include compile.mk
  58. # Standalone adapter
  59. STANDALONE_SOURCES += adapters/standalone.cpp
  60. ifdef ARCH_LIN
  61. STANDALONE_TARGET := Rack
  62. STANDALONE_LDFLAGS += -static-libstdc++ -static-libgcc
  63. STANDALONE_LDFLAGS += -Wl,-rpath=.
  64. endif
  65. ifdef ARCH_MAC
  66. STANDALONE_TARGET := Rack
  67. STANDALONE_LDFLAGS += -stdlib=libc++
  68. endif
  69. ifdef ARCH_WIN
  70. STANDALONE_TARGET := Rack.exe
  71. STANDALONE_LDFLAGS += -mwindows
  72. # 1MiB stack size to match MSVC
  73. STANDALONE_LDFLAGS += -Wl,--stack,0x100000
  74. STANDALONE_OBJECTS += build/Rack.res
  75. endif
  76. STANDALONE_OBJECTS += $(TARGET)
  77. $(STANDALONE_TARGET): $(STANDALONE_SOURCES) $(STANDALONE_OBJECTS)
  78. $(CXX) $(CXXFLAGS) -o $@ $^ $(STANDALONE_LDFLAGS)
  79. # Convenience targets
  80. all: $(TARGET) $(STANDALONE_TARGET)
  81. dep:
  82. $(MAKE) -C dep
  83. cleandep:
  84. $(MAKE) -C dep clean
  85. run: $(STANDALONE_TARGET)
  86. ./$< -d
  87. runr: $(STANDALONE_TARGET)
  88. ./$<
  89. debug: $(STANDALONE_TARGET)
  90. ifdef ARCH_MAC
  91. lldb -- ./$< -d
  92. endif
  93. ifdef ARCH_WIN
  94. gdb --args ./$< -d
  95. endif
  96. ifdef ARCH_LIN
  97. gdb --args ./$< -d
  98. endif
  99. perf: $(STANDALONE_TARGET)
  100. # Requires perf
  101. perf record --call-graph dwarf -o perf.data ./$< -d
  102. # Analyze with hotspot (https://github.com/KDAB/hotspot) for example
  103. hotspot perf.data
  104. rm perf.data
  105. valgrind: $(STANDALONE_TARGET)
  106. # --gen-suppressions=yes
  107. # --leak-check=full
  108. valgrind --suppressions=valgrind.supp ./$< -d
  109. clean:
  110. rm -rfv build dist $(TARGET) $(STANDALONE_TARGET) *.a
  111. # For Windows resources
  112. build/%.res: %.rc
  113. ifdef ARCH_WIN
  114. windres $^ -O coff -o $@
  115. endif
  116. DIST_RES := res cacert.pem Core.json template.vcv LICENSE-GPLv3.txt
  117. DIST_NAME := RackFree-$(VERSION)-$(ARCH_NAME)
  118. DIST_SDK_DIR := Rack-SDK
  119. DIST_SDK := Rack-SDK-$(VERSION)-$(ARCH_NAME).zip
  120. ifdef ARCH_MAC
  121. DIST_BUNDLE := VCV Rack $(VERSION_MAJOR) Free.app
  122. else
  123. DIST_DIR := Rack$(VERSION_MAJOR)Free
  124. endif
  125. DIST_MD := $(wildcard *.md)
  126. DIST_HTML := $(patsubst %.md, build/%.html, $(DIST_MD))
  127. # Target not supported for public use
  128. dist: $(TARGET) $(STANDALONE_TARGET) $(DIST_HTML) | cleandist
  129. mkdir -p dist
  130. # Copy Rack to dist
  131. ifdef ARCH_LIN
  132. mkdir -p dist/"$(DIST_DIR)"
  133. cp $(TARGET) dist/"$(DIST_DIR)"/
  134. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  135. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  136. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  137. # Manually check that no nonstandard shared libraries are linked
  138. ldd dist/"$(DIST_DIR)"/$(TARGET)
  139. ldd dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  140. # Copy resources
  141. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  142. cp $(DIST_HTML) dist/"$(DIST_DIR)"/
  143. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_DIR)"/Fundamental.vcvplugin
  144. # Make ZIP
  145. cd dist && zip -q -9 -r "$(DIST_NAME)".zip "$(DIST_DIR)"
  146. endif
  147. ifdef ARCH_MAC
  148. mkdir -p dist/"$(DIST_BUNDLE)"
  149. mkdir -p dist/"$(DIST_BUNDLE)"/Contents
  150. mkdir -p dist/"$(DIST_BUNDLE)"/Contents/Resources
  151. mkdir -p dist/"$(DIST_BUNDLE)"/Contents/MacOS
  152. cp $(TARGET) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  153. cp $(STANDALONE_TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/
  154. $(STRIP) -S dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  155. $(STRIP) -S dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  156. install_name_tool -change $(TARGET) @executable_path/../Resources/$(TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  157. # Manually check that no nonstandard shared libraries are linked
  158. otool -L dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  159. otool -L dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  160. # Copy resources
  161. cp Info.plist dist/"$(DIST_BUNDLE)"/Contents/
  162. $(SED) 's/{VERSION}/$(VERSION)/g' dist/"$(DIST_BUNDLE)"/Contents/Info.plist
  163. cp -R $(DIST_RES) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  164. cp $(DIST_HTML) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  165. cp -R icon.icns dist/"$(DIST_BUNDLE)"/Contents/Resources/
  166. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_BUNDLE)"/Contents/Resources/Fundamental.vcvplugin
  167. # Clean up and sign bundle
  168. xattr -cr dist/"$(DIST_BUNDLE)"
  169. 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)"
  170. codesign --verify --deep --strict --verbose=2 dist/"$(DIST_BUNDLE)"
  171. # Make standalone PKG
  172. mkdir -p dist/Component
  173. cp -R dist/"$(DIST_BUNDLE)" dist/Component/
  174. pkgbuild --identifier com.vcvrack.rack --component-plist Component.plist --root dist/Component --install-location /Applications dist/Component.pkg
  175. # Make PKG
  176. productbuild --distribution Distribution.xml --package-path dist dist/"$(DIST_NAME)".pkg
  177. productsign --sign "Developer ID Installer: Andrew Belt (V8SW9J626X)" dist/"$(DIST_NAME)".pkg dist/"$(DIST_NAME)"-signed.pkg
  178. mv dist/"$(DIST_NAME)"-signed.pkg dist/"$(DIST_NAME)".pkg
  179. endif
  180. ifdef ARCH_WIN
  181. mkdir -p dist/"$(DIST_DIR)"
  182. cp $(TARGET) dist/"$(DIST_DIR)"/
  183. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  184. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  185. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  186. # Copy resources
  187. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  188. cp $(DIST_HTML) dist/"$(DIST_DIR)"/
  189. cp /mingw64/bin/libwinpthread-1.dll dist/"$(DIST_DIR)"/
  190. cp /mingw64/bin/libstdc++-6.dll dist/"$(DIST_DIR)"/
  191. cp /mingw64/bin/libgcc_s_seh-1.dll dist/"$(DIST_DIR)"/
  192. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_DIR)"/Fundamental.vcvplugin
  193. # Make NSIS installer
  194. # pacman -S mingw-w64-x86_64-nsis
  195. makensis -DVERSION_MAJOR="$(VERSION_MAJOR)" -DVERSION="$(VERSION)" "-XOutFile dist/$(DIST_NAME).exe" installer.nsi
  196. endif
  197. # Build Rack SDK
  198. mkdir -p dist/"$(DIST_SDK_DIR)"
  199. cp -R LICENSE* *.mk include helper.py dist/"$(DIST_SDK_DIR)"/
  200. mkdir -p dist/"$(DIST_SDK_DIR)"/dep/
  201. cp -R dep/include dist/"$(DIST_SDK_DIR)"/dep/
  202. ifdef ARCH_LIN
  203. cp $(TARGET) dist/"$(DIST_SDK_DIR)"/
  204. $(STRIP) -s dist/"$(DIST_SDK_DIR)"/$(TARGET)
  205. endif
  206. ifdef ARCH_MAC
  207. cp $(TARGET) dist/"$(DIST_SDK_DIR)"/
  208. $(STRIP) -S dist/"$(DIST_SDK_DIR)"/$(TARGET)
  209. endif
  210. ifdef ARCH_WIN
  211. cp libRack.dll.a dist/"$(DIST_SDK_DIR)"/
  212. endif
  213. cd dist && zip -q -9 -r "$(DIST_SDK)" "$(DIST_SDK_DIR)"
  214. install: dist
  215. ifdef ARCH_MAC
  216. sudo installer -pkg dist/"$(DIST_NAME)".pkg -target /
  217. endif
  218. uninstall:
  219. ifdef ARCH_MAC
  220. sudo rm -rf /Applications/"$(DIST_BUNDLE)"
  221. endif
  222. # Target not supported for public use
  223. notarize:
  224. ifdef ARCH_MAC
  225. 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
  226. # Wait for Apple's servers to approve the app
  227. while true; do \
  228. echo "Waiting on Apple servers..." ; \
  229. sleep 10 ; \
  230. 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 ; \
  231. if [ "`/usr/libexec/PlistBuddy -c "Print :notarization-info:Status" dist/RequestInfo.plist`" != "in progress" ]; then \
  232. break ; \
  233. fi ; \
  234. done
  235. # Mark app as notarized
  236. xcrun stapler staple dist/"$(DIST_NAME)".pkg
  237. # Check notarization
  238. stapler validate dist/"$(DIST_NAME)".pkg
  239. endif
  240. cleandist:
  241. rm -rfv dist
  242. # Plugin helpers
  243. plugins:
  244. ifdef CMD
  245. for f in plugins/*; do (cd "$$f" && $(CMD)); done
  246. else
  247. for f in plugins/*; do $(MAKE) -C "$$f"; done
  248. endif
  249. # Includes
  250. .DEFAULT_GOAL := all
  251. .PHONY: all dep run debug clean dist upload src plugins