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.

98 lines
2.5KB

  1. ifndef RACK_DIR
  2. $(error RACK_DIR is not defined)
  3. endif
  4. SLUG := $(shell jq -r .slug plugin.json)
  5. VERSION := $(shell jq -r .version plugin.json)
  6. ifndef SLUG
  7. $(error SLUG could not be found in manifest)
  8. endif
  9. ifndef VERSION
  10. $(error VERSION could not be found in manifest)
  11. endif
  12. DISTRIBUTABLES += plugin.json
  13. FLAGS += -fPIC
  14. FLAGS += -I$(RACK_DIR)/include -I$(RACK_DIR)/dep/include
  15. LDFLAGS += -shared
  16. # Plugins must link to libRack because when Rack is used as a plugin of another application, its symbols are not available to subsequently loaded shared libraries.
  17. LDFLAGS += -L$(RACK_DIR) -lRack
  18. include $(RACK_DIR)/arch.mk
  19. TARGET := plugin
  20. ifdef ARCH_LIN
  21. TARGET := $(TARGET).so
  22. # This prevents static variables in the DSO (dynamic shared object) from being preserved after dlclose().
  23. FLAGS += -fno-gnu-unique
  24. # When Rack loads a plugin, it symlinks /tmp/Rack2 to its system dir, so the plugin can link to libRack.
  25. LDFLAGS += -Wl,-rpath=/tmp/Rack2
  26. # Since the plugin's compiler could be a different version than Rack's compiler, link libstdc++ and libgcc statically to avoid ABI issues.
  27. LDFLAGS += -static-libstdc++ -static-libgcc
  28. RACK_USER_DIR ?= $(HOME)/.Rack2
  29. endif
  30. ifdef ARCH_MAC
  31. TARGET := $(TARGET).dylib
  32. LDFLAGS += -undefined dynamic_lookup
  33. RACK_USER_DIR ?= $(HOME)/Documents/Rack2
  34. CODESIGN ?= codesign -f -s -
  35. endif
  36. ifdef ARCH_WIN
  37. TARGET := $(TARGET).dll
  38. LDFLAGS += -static-libstdc++
  39. RACK_USER_DIR ?= $(USERPROFILE)/Documents/Rack2
  40. endif
  41. PLUGINS_DIR := $(RACK_USER_DIR)/plugins-$(ARCH_OS)-$(ARCH_CPU)
  42. DEP_FLAGS += -fPIC
  43. include $(RACK_DIR)/dep.mk
  44. all: $(TARGET)
  45. include $(RACK_DIR)/compile.mk
  46. clean:
  47. rm -rfv build $(TARGET) dist
  48. ZSTD_COMPRESSION_LEVEL ?= 19
  49. dist: all
  50. rm -rf dist
  51. mkdir -p dist/$(SLUG)
  52. @# Strip symbols from binary
  53. cp $(TARGET) dist/$(SLUG)/
  54. ifdef ARCH_MAC
  55. $(STRIP) -S dist/$(SLUG)/$(TARGET)
  56. $(INSTALL_NAME_TOOL) -change libRack.dylib /tmp/Rack2/libRack.dylib dist/$(SLUG)/$(TARGET)
  57. $(OTOOL) -L dist/$(SLUG)/$(TARGET)
  58. else
  59. $(STRIP) -s dist/$(SLUG)/$(TARGET)
  60. endif
  61. @# Sign binary if CODESIGN is defined
  62. ifdef CODESIGN
  63. $(CODESIGN) dist/$(SLUG)/$(TARGET)
  64. endif
  65. @# Copy distributables
  66. ifdef ARCH_MAC
  67. rsync -rR $(DISTRIBUTABLES) dist/$(SLUG)/
  68. else
  69. cp -r --parents $(DISTRIBUTABLES) dist/$(SLUG)/
  70. endif
  71. @# Create ZIP package
  72. cd dist && tar -c $(SLUG) | zstd -$(ZSTD_COMPRESSION_LEVEL) -o "$(SLUG)"-"$(VERSION)"-$(ARCH_NAME).vcvplugin
  73. install: dist
  74. mkdir -p "$(PLUGINS_DIR)"
  75. cp dist/*.vcvplugin "$(PLUGINS_DIR)"/
  76. .PHONY: clean dist
  77. .DEFAULT_GOAL := all