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.

322 lines
11KB

  1. RACK_DIR ?= .
  2. RACK_EDITION := Free
  3. RACK_VERSION_MAJOR := 2
  4. RACK_VERSION ?= $(patsubst v%,%,$(shell git describe --tags --match "v$(RACK_VERSION_MAJOR).*"))
  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_RACK_VERSION=$(RACK_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.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 -lbcrypt
  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$(RACK_EDITION)-$(RACK_VERSION)-$(ARCH_NAME)
  131. ifdef ARCH_MAC
  132. DIST_BUNDLE := VCV Rack $(RACK_VERSION_MAJOR) $(RACK_EDITION).app
  133. else
  134. DIST_DIR := Rack$(RACK_VERSION_MAJOR)$(RACK_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) translations
  139. DIST_SDK_DIR := Rack-SDK
  140. DIST_SDK = Rack-SDK-$(RACK_VERSION)-$(ARCH_NAME).zip
  141. FUNDAMENTAL_VERSION ?= 2.6.1
  142. FUNDAMENTAL_FILENAME := Fundamental-$(FUNDAMENTAL_VERSION)-$(ARCH_NAME).vcvplugin
  143. dist: $(TARGET) $(STANDALONE_TARGET) $(DIST_HTML)
  144. mkdir -p dist
  145. # Download Fundamental package if not already downloaded
  146. [ -f "$(FUNDAMENTAL_FILENAME)" ] || curl -o "$(FUNDAMENTAL_FILENAME)" "https://api.vcvrack.com/download?slug=Fundamental&version=$(FUNDAMENTAL_VERSION)&arch=$(ARCH_NAME)"
  147. ifdef ARCH_LIN
  148. mkdir -p dist/"$(DIST_DIR)"
  149. cp $(TARGET) dist/"$(DIST_DIR)"/
  150. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  151. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  152. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  153. # Manually check that no nonstandard shared libraries are linked
  154. ldd dist/"$(DIST_DIR)"/$(TARGET)
  155. ldd dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  156. # Copy resources
  157. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  158. cp "$(FUNDAMENTAL_FILENAME)" dist/"$(DIST_DIR)"/
  159. endif
  160. ifdef ARCH_MAC
  161. mkdir -p dist/"$(DIST_BUNDLE)"
  162. mkdir -p dist/"$(DIST_BUNDLE)"/Contents
  163. mkdir -p dist/"$(DIST_BUNDLE)"/Contents/Resources
  164. mkdir -p dist/"$(DIST_BUNDLE)"/Contents/MacOS
  165. cp $(TARGET) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  166. cp $(STANDALONE_TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/
  167. $(STRIP) -S dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  168. $(STRIP) -S dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  169. install_name_tool -change $(TARGET) @executable_path/../Resources/$(TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  170. # Manually check that no nonstandard shared libraries are linked
  171. otool -L dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  172. otool -L dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  173. # Copy resources
  174. cp Info.plist dist/"$(DIST_BUNDLE)"/Contents/
  175. $(SED) 's/{RACK_VERSION}/$(RACK_VERSION)/g' dist/"$(DIST_BUNDLE)"/Contents/Info.plist
  176. cp -R icon.icns dist/"$(DIST_BUNDLE)"/Contents/Resources/
  177. cp -R $(DIST_RES) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  178. cp "$(FUNDAMENTAL_FILENAME)" dist/"$(DIST_BUNDLE)"/Contents/Resources/
  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 /mingw64/bin/libwinpthread-1.dll dist/"$(DIST_DIR)"/
  189. cp /mingw64/bin/libstdc++-6.dll dist/"$(DIST_DIR)"/
  190. cp /mingw64/bin/libgcc_s_seh-1.dll dist/"$(DIST_DIR)"/
  191. cp "$(FUNDAMENTAL_FILENAME)" dist/"$(DIST_DIR)"/
  192. endif
  193. sdk: $(DIST_HTML)
  194. mkdir -p dist/$(DIST_SDK_DIR)
  195. cp -R include *.mk helper.py $(DIST_HTML) dist/$(DIST_SDK_DIR)/
  196. mkdir -p dist/$(DIST_SDK_DIR)/dep
  197. cp -R dep/include dist/$(DIST_SDK_DIR)/dep/
  198. ifdef ARCH_LIN
  199. cp $(TARGET) dist/$(DIST_SDK_DIR)/
  200. $(STRIP) -s dist/$(DIST_SDK_DIR)/$(TARGET)
  201. endif
  202. ifdef ARCH_MAC
  203. cp $(TARGET) dist/$(DIST_SDK_DIR)/
  204. $(STRIP) -S dist/$(DIST_SDK_DIR)/$(TARGET)
  205. endif
  206. ifdef ARCH_WIN
  207. cp $(TARGET).a dist/$(DIST_SDK_DIR)/
  208. endif
  209. # SDK
  210. cd dist && zip -q -9 -r $(DIST_SDK) $(DIST_SDK_DIR)
  211. package:
  212. ifdef ARCH_LIN
  213. # Make ZIP
  214. cd dist && zip -q -9 -r $(DIST_NAME).zip "$(DIST_DIR)"
  215. endif
  216. ifdef ARCH_MAC
  217. # Clean up and sign bundle
  218. xattr -cr dist/"$(DIST_BUNDLE)"
  219. 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)"
  220. codesign --verify --deep --strict --verbose=2 dist/"$(DIST_BUNDLE)"
  221. # Make standalone PKG
  222. mkdir -p dist/Component
  223. cp -R dist/"$(DIST_BUNDLE)" dist/Component/
  224. pkgbuild --identifier com.vcvrack.rack2 --component-plist Component.plist --root dist/Component --install-location /Applications dist/Component.pkg
  225. # Make PKG
  226. productbuild --distribution Distribution.xml --package-path dist dist/$(DIST_NAME).pkg
  227. productsign --sign "Developer ID Installer: Andrew Belt (V8SW9J626X)" dist/$(DIST_NAME).pkg dist/$(DIST_NAME)-signed.pkg
  228. mv dist/$(DIST_NAME)-signed.pkg dist/$(DIST_NAME).pkg
  229. endif
  230. ifdef ARCH_WIN
  231. # Make NSIS installer
  232. # pacman -S mingw-w64-x86_64-nsis
  233. makensis -DRACK_VERSION_MAJOR=$(RACK_VERSION_MAJOR) -DRACK_VERSION=$(RACK_VERSION) "-XOutFile dist/$(DIST_NAME).exe" installer.nsi
  234. endif
  235. lipo:
  236. ifndef OTHER_RACK_DIR
  237. $(error OTHER_RACK_DIR not defined)
  238. endif
  239. ifdef ARCH_MAC
  240. # App bundle
  241. lipo -create -output dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET) dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET) $(OTHER_RACK_DIR)/dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  242. 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)
  243. # Fundamental package
  244. cp $(OTHER_RACK_DIR)/dist/"$(DIST_BUNDLE)"/Contents/Resources/Fundamental-*.vcvplugin dist/"$(DIST_BUNDLE)"/Contents/Resources/
  245. endif
  246. notarize:
  247. ifdef ARCH_MAC
  248. # Submit installer package to Apple
  249. xcrun notarytool submit --keychain-profile "VCV" --wait dist/$(DIST_NAME).pkg
  250. # Mark app as notarized
  251. xcrun stapler staple dist/$(DIST_NAME).pkg
  252. # Check notarization
  253. stapler validate dist/$(DIST_NAME).pkg
  254. endif
  255. install: uninstall
  256. ifdef ARCH_MAC
  257. sudo installer -pkg dist/$(DIST_NAME).pkg -target /
  258. endif
  259. uninstall:
  260. ifdef ARCH_MAC
  261. sudo rm -rf /Applications/"$(DIST_BUNDLE)"
  262. endif
  263. cleandist:
  264. rm -rfv dist
  265. .DEFAULT_GOAL := all
  266. .PHONY: all dep run debug clean plugins dist sdk package lipo notarize