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.

261 lines
8.5KB

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