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