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.

270 lines
8.9KB

  1. RACK_DIR ?= .
  2. VERSION := 2.dev.$(shell git rev-parse --short HEAD)
  3. # VERSION := 2.0.0
  4. FLAGS += -DVERSION=$(VERSION)
  5. FLAGS += -Iinclude -Idep/include
  6. include arch.mk
  7. SED := perl -pi -e
  8. # Sources and build flags
  9. SOURCES += dep/nanovg/src/nanovg.c
  10. SOURCES += dep/osdialog/osdialog.c
  11. SOURCES += dep/pffft/pffft.c dep/pffft/fftpack.c
  12. SOURCES += $(wildcard src/*.c src/*/*.c)
  13. SOURCES += $(wildcard src/*.cpp src/*/*.cpp)
  14. STANDALONE_SOURCES += adapters/standalone.cpp
  15. FLAGS += -fPIC
  16. LDFLAGS += -shared
  17. ifdef ARCH_LIN
  18. TARGET := libRack.so
  19. SOURCES += dep/osdialog/osdialog_gtk3.c
  20. build/dep/osdialog/osdialog_gtk3.c.o: FLAGS += $(shell pkg-config --cflags gtk+-3.0)
  21. # This prevents static variables in the DSO (dynamic shared object) from being preserved after dlclose().
  22. # I don't really understand the side effects (see GCC manual), but so far tests are positive.
  23. FLAGS += -fno-gnu-unique
  24. LDFLAGS += -Wl,--whole-archive
  25. 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
  26. LDFLAGS += -Wl,--no-whole-archive
  27. LDFLAGS += -lpthread -lGL -ldl -lX11 -lasound -ljack
  28. LDFLAGS += $(shell pkg-config --libs gtk+-3.0)
  29. STANDALONE_TARGET := Rack
  30. STANDALONE_LDFLAGS += -Wl,-rpath=.
  31. endif
  32. ifdef ARCH_MAC
  33. TARGET := libRack.dylib
  34. SOURCES += dep/osdialog/osdialog_mac.m
  35. LDFLAGS += -lpthread -ldl
  36. LDFLAGS += -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. STANDALONE_TARGET := Rack
  40. STANDALONE_LDFLAGS += -stdlib=libc++
  41. # For LuaJIT to work inside plugins
  42. STANDALONE_LDFLAGS += -Wl,-pagezero_size,10000 -Wl,-image_base,100000000
  43. endif
  44. ifdef ARCH_WIN
  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
  54. STANDALONE_TARGET := Rack.exe
  55. STANDALONE_LDFLAGS += -mwindows
  56. STANDALONE_OBJECTS += build/Rack.res
  57. endif
  58. include compile.mk
  59. # Standalone adapter
  60. ifdef ARCH_MAC
  61. STANDALONE_LDFLAGS += $(MAC_SDK_FLAGS)
  62. endif
  63. STANDALONE_OBJECTS += $(patsubst %, build/%.o, $(STANDALONE_SOURCES))
  64. STANDALONE_DEPENDENCIES := $(patsubst %, build/%.d, $(STANDALONE_SOURCES))
  65. -include $(STANDALONE_DEPENDENCIES)
  66. $(STANDALONE_TARGET): $(STANDALONE_OBJECTS) $(TARGET)
  67. $(CXX) -o $@ $^ $(STANDALONE_LDFLAGS)
  68. # Convenience targets
  69. all: $(TARGET) $(STANDALONE_TARGET)
  70. dep:
  71. $(MAKE) -C dep
  72. run: $(STANDALONE_TARGET)
  73. ./$< -d
  74. runr: $(STANDALONE_TARGET)
  75. ./$<
  76. debug: $(STANDALONE_TARGET)
  77. ifdef ARCH_MAC
  78. lldb -- ./$< -d
  79. endif
  80. ifdef ARCH_WIN
  81. gdb --args ./$< -d
  82. endif
  83. ifdef ARCH_LIN
  84. gdb --args ./$< -d
  85. endif
  86. screenshot: $(STANDALONE_TARGET)
  87. ./$< -d -t 2
  88. perf: $(STANDALONE_TARGET)
  89. # Requires perf
  90. perf record --call-graph dwarf -o perf.data ./$< -d
  91. # Analyze with hotspot (https://github.com/KDAB/hotspot) for example
  92. hotspot perf.data
  93. rm perf.data
  94. valgrind: $(STANDALONE_TARGET)
  95. # --gen-suppressions=yes
  96. # --leak-check=full
  97. valgrind --suppressions=valgrind.supp ./$< -d
  98. clean:
  99. rm -rfv $(TARGET) $(STANDALONE_TARGET) libRack.dll.a Rack.res build dist
  100. # For Windows resources
  101. build/%.res: %.rc
  102. ifdef ARCH_WIN
  103. windres $^ -O coff -o $@
  104. endif
  105. DIST_RES := res cacert.pem Core.json template.vcv
  106. DIST_NAME := Rack-"$(VERSION)"-$(ARCH)
  107. DIST_SDK_DIR := Rack-SDK
  108. DIST_SDK := Rack-SDK-$(VERSION).zip
  109. ifdef ARCH_MAC
  110. DIST_DIR := VCV Rack.app
  111. else
  112. DIST_DIR := Rack
  113. endif
  114. DIST_MD := $(wildcard *.md)
  115. DIST_HTML := $(patsubst %.md, build/%.html, $(DIST_MD))
  116. # This target is not supported for public use
  117. dist: $(TARGET) $(STANDALONE_TARGET) $(DIST_HTML)
  118. rm -rf dist
  119. mkdir -p dist
  120. # Copy Rack to dist
  121. ifdef ARCH_LIN
  122. mkdir -p dist/"$(DIST_DIR)"
  123. cp $(TARGET) dist/"$(DIST_DIR)"/
  124. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  125. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  126. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  127. # Manually check that no nonstandard shared libraries are linked
  128. ldd dist/"$(DIST_DIR)"/$(TARGET)
  129. ldd dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  130. # Copy resources
  131. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  132. cp $(DIST_HTML) dist/"$(DIST_DIR)"/
  133. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_DIR)"/Fundamental.vcvplugin
  134. # Make ZIP
  135. cd dist && zip -q -9 -r $(DIST_NAME).zip Rack
  136. endif
  137. ifdef ARCH_MAC
  138. mkdir -p dist/"$(DIST_DIR)"
  139. mkdir -p dist/"$(DIST_DIR)"/Contents
  140. mkdir -p dist/"$(DIST_DIR)"/Contents/Resources
  141. mkdir -p dist/"$(DIST_DIR)"/Contents/MacOS
  142. cp $(TARGET) dist/"$(DIST_DIR)"/Contents/Resources/
  143. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/Contents/MacOS/
  144. $(STRIP) -S dist/"$(DIST_DIR)"/Contents/Resources/$(TARGET)
  145. $(STRIP) -S dist/"$(DIST_DIR)"/Contents/MacOS/$(STANDALONE_TARGET)
  146. install_name_tool -change $(TARGET) @executable_path/../Resources/$(TARGET) dist/"$(DIST_DIR)"/Contents/MacOS/$(STANDALONE_TARGET)
  147. # Manually check that no nonstandard shared libraries are linked
  148. otool -L dist/"$(DIST_DIR)"/Contents/Resources/$(TARGET)
  149. otool -L dist/"$(DIST_DIR)"/Contents/MacOS/$(STANDALONE_TARGET)
  150. # Copy resources
  151. cp Info.plist dist/"$(DIST_DIR)"/Contents/
  152. $(SED) 's/{VERSION}/$(VERSION)/g' dist/"$(DIST_DIR)"/Contents/Info.plist
  153. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/Contents/Resources/
  154. cp $(DIST_HTML) dist/"$(DIST_DIR)"/Contents/Resources/
  155. cp -R icon.icns dist/"$(DIST_DIR)"/Contents/Resources/
  156. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_DIR)"/Fundamental.vcvplugin
  157. # Clean up and sign bundle
  158. xattr -cr dist/"$(DIST_DIR)"
  159. # This will only work if you have the private key to my certificate
  160. codesign --verbose --sign "Developer ID Application: Andrew Belt (VRF26934X5)" --options runtime --entitlements Entitlements.plist --deep dist/"$(DIST_DIR)"
  161. codesign --verify --deep --strict --verbose=2 dist/"$(DIST_DIR)"
  162. # Make ZIP
  163. cd dist && zip -q -9 -r $(DIST_NAME).zip "$(DIST_DIR)"
  164. endif
  165. ifdef ARCH_WIN
  166. mkdir -p dist/"$(DIST_DIR)"
  167. cp $(TARGET) dist/"$(DIST_DIR)"/
  168. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  169. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  170. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  171. # Copy resources
  172. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  173. cp $(DIST_HTML) dist/"$(DIST_DIR)"/
  174. cp /mingw64/bin/libwinpthread-1.dll dist/"$(DIST_DIR)"/
  175. cp /mingw64/bin/libstdc++-6.dll dist/"$(DIST_DIR)"/
  176. cp /mingw64/bin/libgcc_s_seh-1.dll dist/"$(DIST_DIR)"/
  177. cp plugins/Fundamental/dist/Fundamental-*.vcvplugin dist/"$(DIST_DIR)"/Fundamental.vcvplugin
  178. # Make ZIP
  179. cd dist && zip -q -9 -r $(DIST_NAME).zip "$(DIST_DIR)"
  180. # Make NSIS installer
  181. # pacman -S mingw-w64-x86_64-nsis
  182. makensis -DVERSION=$(VERSION) installer.nsi
  183. mv installer.exe dist/$(DIST_NAME).exe
  184. endif
  185. # Build Rack SDK
  186. mkdir -p dist/"$(DIST_SDK_DIR)"
  187. cp -R LICENSE* *.mk include helper.py dist/"$(DIST_SDK_DIR)"/
  188. mkdir -p dist/"$(DIST_SDK_DIR)"/dep/
  189. cp -R dep/include dist/"$(DIST_SDK_DIR)"/dep/
  190. ifdef ARCH_WIN
  191. cp libRack.dll.a dist/"$(DIST_SDK_DIR)"/
  192. endif
  193. cd dist && zip -q -9 -r $(DIST_SDK) "$(DIST_SDK_DIR)"
  194. notarize:
  195. ifdef ARCH_MAC
  196. # This will only work if you have my Apple ID password in your keychain
  197. xcrun altool --notarize-app -f dist/"$(DIST_DIR)"-$(VERSION)-$(ARCH).zip --primary-bundle-id=com.vcvrack.rack -u "andrewpbelt@gmail.com" -p @keychain:notarize --output-format xml > dist/UploadInfo.plist
  198. # Wait for Apple's servers to approve the app
  199. while true; do \
  200. echo "Waiting on Apple servers..." ; \
  201. xcrun altool --notarization-info `/usr/libexec/PlistBuddy -c "Print :notarization-upload:RequestUUID" dist/UploadInfo.plist` -u "andrewpbelt@gmail.com" -p @keychain:notarize --output-format xml > dist/RequestInfo.plist ; \
  202. if [ "`/usr/libexec/PlistBuddy -c "Print :notarization-info:Status" dist/RequestInfo.plist`" != "in progress" ]; then \
  203. break ; \
  204. fi ; \
  205. sleep 10 ; \
  206. done
  207. # Mark app as notarized, check, and re-zip
  208. xcrun stapler staple dist/"$(DIST_DIR)"
  209. spctl --assess --type execute --ignore-cache --no-cache -vv dist/"$(DIST_DIR)"
  210. cd dist && zip -q -9 -r $(DIST_NAME).zip Rack.app
  211. endif
  212. # Plugin helpers
  213. plugins:
  214. ifdef CMD
  215. for f in plugins/*; do (cd "$$f" && $(CMD)); done
  216. else
  217. for f in plugins/*; do $(MAKE) -C "$$f"; done
  218. endif
  219. # Includes
  220. .DEFAULT_GOAL := all
  221. .PHONY: all dep run debug clean dist upload src plugins