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.

325 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_FLAGS += --gen-suppressions=all
  112. VALGRIND_FLAGS += --suppressions=valgrind.supp
  113. # VALGRIND_FLAGS += --leak-check=full
  114. VALGRIND_FLAGS += --track-origins=yes
  115. VALGRIND_FLAGS += --exit-on-first-error=yes
  116. valgrind: $(STANDALONE_TARGET)
  117. valgrind $(VALGRIND_FLAGS) ./$< -d
  118. clean:
  119. rm -rfv build dist $(TARGET) $(STANDALONE_TARGET) *.a
  120. # Windows resources
  121. build/%.res: %.rc
  122. ifdef ARCH_WIN
  123. windres $^ -O coff -o $@
  124. endif
  125. # Plugin helper
  126. plugins:
  127. ifdef CMD
  128. for f in plugins/*; do (cd "$$f" && $(CMD)); done
  129. else
  130. for f in plugins/*; do $(MAKE) -C "$$f"; done
  131. endif
  132. # The following targets are not supported for public use
  133. DIST_NAME = Rack$(RACK_EDITION)-$(RACK_VERSION)-$(ARCH_NAME)
  134. ifdef ARCH_MAC
  135. DIST_BUNDLE := VCV Rack $(RACK_VERSION_MAJOR) $(RACK_EDITION).app
  136. else
  137. DIST_DIR := Rack$(RACK_VERSION_MAJOR)$(RACK_EDITION)
  138. endif
  139. DIST_MD := $(wildcard *.md)
  140. DIST_HTML := $(patsubst %.md, build/%.html, $(DIST_MD))
  141. DIST_RES := res cacert.pem Core.json template.vcv LICENSE-GPLv3.txt $(DIST_HTML) translations
  142. DIST_SDK_DIR := Rack-SDK
  143. DIST_SDK = Rack-SDK-$(RACK_VERSION)-$(ARCH_NAME).zip
  144. FUNDAMENTAL_VERSION ?= 2.6.1
  145. FUNDAMENTAL_FILENAME := Fundamental-$(FUNDAMENTAL_VERSION)-$(ARCH_NAME).vcvplugin
  146. dist: $(TARGET) $(STANDALONE_TARGET) $(DIST_HTML)
  147. mkdir -p dist
  148. # Download Fundamental package if not already downloaded
  149. [ -f "$(FUNDAMENTAL_FILENAME)" ] || curl -o "$(FUNDAMENTAL_FILENAME)" "https://api.vcvrack.com/download?slug=Fundamental&version=$(FUNDAMENTAL_VERSION)&arch=$(ARCH_NAME)"
  150. ifdef ARCH_LIN
  151. mkdir -p dist/"$(DIST_DIR)"
  152. cp $(TARGET) dist/"$(DIST_DIR)"/
  153. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  154. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  155. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  156. # Manually check that no nonstandard shared libraries are linked
  157. ldd dist/"$(DIST_DIR)"/$(TARGET)
  158. ldd dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  159. # Copy resources
  160. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  161. cp "$(FUNDAMENTAL_FILENAME)" dist/"$(DIST_DIR)"/
  162. endif
  163. ifdef ARCH_MAC
  164. mkdir -p dist/"$(DIST_BUNDLE)"
  165. mkdir -p dist/"$(DIST_BUNDLE)"/Contents
  166. mkdir -p dist/"$(DIST_BUNDLE)"/Contents/Resources
  167. mkdir -p dist/"$(DIST_BUNDLE)"/Contents/MacOS
  168. cp $(TARGET) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  169. cp $(STANDALONE_TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/
  170. $(STRIP) -S dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  171. $(STRIP) -S dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  172. install_name_tool -change $(TARGET) @executable_path/../Resources/$(TARGET) dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  173. # Manually check that no nonstandard shared libraries are linked
  174. otool -L dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  175. otool -L dist/"$(DIST_BUNDLE)"/Contents/MacOS/$(STANDALONE_TARGET)
  176. # Copy resources
  177. cp Info.plist dist/"$(DIST_BUNDLE)"/Contents/
  178. $(SED) 's/{RACK_VERSION}/$(RACK_VERSION)/g' dist/"$(DIST_BUNDLE)"/Contents/Info.plist
  179. cp -R icon.icns dist/"$(DIST_BUNDLE)"/Contents/Resources/
  180. cp -R $(DIST_RES) dist/"$(DIST_BUNDLE)"/Contents/Resources/
  181. cp "$(FUNDAMENTAL_FILENAME)" dist/"$(DIST_BUNDLE)"/Contents/Resources/
  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 /mingw64/bin/libwinpthread-1.dll dist/"$(DIST_DIR)"/
  192. cp /mingw64/bin/libstdc++-6.dll dist/"$(DIST_DIR)"/
  193. cp /mingw64/bin/libgcc_s_seh-1.dll dist/"$(DIST_DIR)"/
  194. cp "$(FUNDAMENTAL_FILENAME)" dist/"$(DIST_DIR)"/
  195. endif
  196. sdk: $(DIST_HTML)
  197. mkdir -p dist/$(DIST_SDK_DIR)
  198. cp -R include *.mk helper.py $(DIST_HTML) dist/$(DIST_SDK_DIR)/
  199. mkdir -p dist/$(DIST_SDK_DIR)/dep
  200. cp -R dep/include dist/$(DIST_SDK_DIR)/dep/
  201. ifdef ARCH_LIN
  202. cp $(TARGET) dist/$(DIST_SDK_DIR)/
  203. $(STRIP) -s dist/$(DIST_SDK_DIR)/$(TARGET)
  204. endif
  205. ifdef ARCH_MAC
  206. cp $(TARGET) dist/$(DIST_SDK_DIR)/
  207. $(STRIP) -S dist/$(DIST_SDK_DIR)/$(TARGET)
  208. endif
  209. ifdef ARCH_WIN
  210. cp $(TARGET).a dist/$(DIST_SDK_DIR)/
  211. endif
  212. # SDK
  213. cd dist && zip -q -9 -r $(DIST_SDK) $(DIST_SDK_DIR)
  214. package:
  215. ifdef ARCH_LIN
  216. # Make ZIP
  217. cd dist && zip -q -9 -r $(DIST_NAME).zip "$(DIST_DIR)"
  218. endif
  219. ifdef ARCH_MAC
  220. # Clean up and sign bundle
  221. xattr -cr dist/"$(DIST_BUNDLE)"
  222. 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)"
  223. codesign --verify --deep --strict --verbose=2 dist/"$(DIST_BUNDLE)"
  224. # Make standalone PKG
  225. mkdir -p dist/Component
  226. cp -R dist/"$(DIST_BUNDLE)" dist/Component/
  227. pkgbuild --identifier com.vcvrack.rack2 --component-plist Component.plist --root dist/Component --install-location /Applications dist/Component.pkg
  228. # Make PKG
  229. productbuild --distribution Distribution.xml --package-path dist dist/$(DIST_NAME).pkg
  230. productsign --sign "Developer ID Installer: Andrew Belt (V8SW9J626X)" dist/$(DIST_NAME).pkg dist/$(DIST_NAME)-signed.pkg
  231. mv dist/$(DIST_NAME)-signed.pkg dist/$(DIST_NAME).pkg
  232. endif
  233. ifdef ARCH_WIN
  234. # Make NSIS installer
  235. # pacman -S mingw-w64-x86_64-nsis
  236. makensis -DRACK_VERSION_MAJOR=$(RACK_VERSION_MAJOR) -DRACK_VERSION=$(RACK_VERSION) "-XOutFile dist/$(DIST_NAME).exe" installer.nsi
  237. endif
  238. lipo:
  239. ifndef OTHER_RACK_DIR
  240. $(error OTHER_RACK_DIR not defined)
  241. endif
  242. ifdef ARCH_MAC
  243. # App bundle
  244. lipo -create -output dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET) dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET) $(OTHER_RACK_DIR)/dist/"$(DIST_BUNDLE)"/Contents/Resources/$(TARGET)
  245. 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)
  246. # Fundamental package
  247. cp $(OTHER_RACK_DIR)/dist/"$(DIST_BUNDLE)"/Contents/Resources/Fundamental-*.vcvplugin dist/"$(DIST_BUNDLE)"/Contents/Resources/
  248. endif
  249. notarize:
  250. ifdef ARCH_MAC
  251. # Submit installer package to Apple
  252. xcrun notarytool submit --keychain-profile "VCV" --wait dist/$(DIST_NAME).pkg
  253. # Mark app as notarized
  254. xcrun stapler staple dist/$(DIST_NAME).pkg
  255. # Check notarization
  256. stapler validate dist/$(DIST_NAME).pkg
  257. endif
  258. install: uninstall
  259. ifdef ARCH_MAC
  260. sudo installer -pkg dist/$(DIST_NAME).pkg -target /
  261. endif
  262. uninstall:
  263. ifdef ARCH_MAC
  264. sudo rm -rf /Applications/"$(DIST_BUNDLE)"
  265. endif
  266. cleandist:
  267. rm -rfv dist
  268. .DEFAULT_GOAL := all
  269. .PHONY: all dep run debug clean plugins dist sdk package lipo notarize