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.

264 lines
8.6KB

  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 := LICENSE* CHANGELOG.md res cacert.pem Core.json template.vcv
  106. DIST_NAME := VCV-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. # This target is not supported for public use
  115. dist: $(TARGET) $(STANDALONE_TARGET)
  116. rm -rf dist
  117. mkdir -p dist
  118. # Copy Rack to dist
  119. ifdef ARCH_LIN
  120. mkdir -p dist/"$(DIST_DIR)"
  121. cp $(TARGET) dist/"$(DIST_DIR)"/
  122. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  123. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  124. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  125. # Manually check that no nonstandard shared libraries are linked
  126. ldd dist/"$(DIST_DIR)"/$(TARGET)
  127. ldd dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  128. # Copy resources
  129. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  130. cp Fundamental.vcvplugin dist/"$(DIST_DIR)"/
  131. # Make ZIP
  132. cd dist && zip -q -9 -r $(DIST_NAME).zip Rack
  133. endif
  134. ifdef ARCH_MAC
  135. mkdir -p dist/"$(DIST_DIR)"
  136. mkdir -p dist/"$(DIST_DIR)"/Contents
  137. mkdir -p dist/"$(DIST_DIR)"/Contents/Resources
  138. mkdir -p dist/"$(DIST_DIR)"/Contents/MacOS
  139. cp $(TARGET) dist/"$(DIST_DIR)"/Contents/Resources/
  140. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/Contents/MacOS/
  141. $(STRIP) -S dist/"$(DIST_DIR)"/Contents/Resources/$(TARGET)
  142. $(STRIP) -S dist/"$(DIST_DIR)"/Contents/MacOS/$(STANDALONE_TARGET)
  143. install_name_tool -change $(TARGET) @executable_path/../Resources/$(TARGET) dist/"$(DIST_DIR)"/Contents/MacOS/$(STANDALONE_TARGET)
  144. # Manually check that no nonstandard shared libraries are linked
  145. otool -L dist/"$(DIST_DIR)"/Contents/Resources/$(TARGET)
  146. otool -L dist/"$(DIST_DIR)"/Contents/MacOS/$(STANDALONE_TARGET)
  147. # Copy resources
  148. cp Info.plist dist/"$(DIST_DIR)"/Contents/
  149. $(SED) 's/{VERSION}/$(VERSION)/g' dist/"$(DIST_DIR)"/Contents/Info.plist
  150. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/Contents/Resources/
  151. cp -R icon.icns dist/"$(DIST_DIR)"/Contents/Resources/
  152. cp Fundamental.vcvplugin dist/"$(DIST_DIR)"/Contents/Resources/
  153. # Clean up and sign bundle
  154. xattr -cr dist/"$(DIST_DIR)"
  155. # This will only work if you have the private key to my certificate
  156. codesign --verbose --sign "Developer ID Application: Andrew Belt (VRF26934X5)" --options runtime --entitlements Entitlements.plist --deep dist/"$(DIST_DIR)"
  157. codesign --verify --deep --strict --verbose=2 dist/"$(DIST_DIR)"
  158. # Make ZIP
  159. cd dist && zip -q -9 -r $(DIST_NAME).zip "$(DIST_DIR)"
  160. endif
  161. ifdef ARCH_WIN
  162. mkdir -p dist/"$(DIST_DIR)"
  163. cp $(TARGET) dist/"$(DIST_DIR)"/
  164. cp $(STANDALONE_TARGET) dist/"$(DIST_DIR)"/
  165. $(STRIP) -s dist/"$(DIST_DIR)"/$(TARGET)
  166. $(STRIP) -s dist/"$(DIST_DIR)"/$(STANDALONE_TARGET)
  167. # Copy resources
  168. cp -R $(DIST_RES) dist/"$(DIST_DIR)"/
  169. cp /mingw64/bin/libwinpthread-1.dll dist/"$(DIST_DIR)"/
  170. cp /mingw64/bin/libstdc++-6.dll dist/"$(DIST_DIR)"/
  171. cp /mingw64/bin/libgcc_s_seh-1.dll dist/"$(DIST_DIR)"/
  172. cp Fundamental.vcvplugin dist/"$(DIST_DIR)"/
  173. # Make ZIP
  174. cd dist && zip -q -9 -r $(DIST_NAME).zip "$(DIST_DIR)"
  175. # Make NSIS installer
  176. # pacman -S mingw-w64-x86_64-nsis
  177. makensis -DVERSION=$(VERSION) installer.nsi
  178. mv installer.exe dist/$(DIST_NAME).exe
  179. endif
  180. # Build Rack SDK
  181. mkdir -p dist/"$(DIST_SDK_DIR)"
  182. cp -R LICENSE* *.mk include helper.py dist/"$(DIST_SDK_DIR)"/
  183. mkdir -p dist/"$(DIST_SDK_DIR)"/dep/
  184. cp -R dep/include dist/"$(DIST_SDK_DIR)"/dep/
  185. ifdef ARCH_WIN
  186. cp libRack.dll.a dist/"$(DIST_SDK_DIR)"/
  187. endif
  188. cd dist && zip -q -9 -r $(DIST_SDK) "$(DIST_SDK_DIR)"
  189. notarize:
  190. ifdef ARCH_MAC
  191. # This will only work if you have my Apple ID password in your keychain
  192. 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
  193. # Wait for Apple's servers to approve the app
  194. while true; do \
  195. echo "Waiting on Apple servers..." ; \
  196. 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 ; \
  197. if [ "`/usr/libexec/PlistBuddy -c "Print :notarization-info:Status" dist/RequestInfo.plist`" != "in progress" ]; then \
  198. break ; \
  199. fi ; \
  200. sleep 10 ; \
  201. done
  202. # Mark app as notarized, check, and re-zip
  203. xcrun stapler staple dist/"$(DIST_DIR)"
  204. spctl --assess --type execute --ignore-cache --no-cache -vv dist/"$(DIST_DIR)"
  205. cd dist && zip -q -9 -r $(DIST_NAME).zip Rack.app
  206. endif
  207. # Plugin helpers
  208. plugins:
  209. ifdef CMD
  210. for f in plugins/*; do (cd "$$f" && $(CMD)); done
  211. else
  212. for f in plugins/*; do $(MAKE) -C "$$f"; done
  213. endif
  214. # Includes
  215. .DEFAULT_GOAL := all
  216. .PHONY: all dep run debug clean dist upload src plugins