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.

plugin.mk 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. XDG_DATA_HOME ?= $(HOME)/.local/share
  29. RACK_USER_DIR ?= $(XDG_DATA_HOME)/Rack2
  30. endif
  31. ifdef ARCH_MAC
  32. TARGET := $(TARGET).dylib
  33. LDFLAGS += -undefined dynamic_lookup
  34. RACK_USER_DIR ?= $(HOME)/Library/Application Support/Rack2
  35. CODESIGN ?= codesign -f -s -
  36. endif
  37. ifdef ARCH_WIN
  38. TARGET := $(TARGET).dll
  39. LDFLAGS += -static-libstdc++
  40. RACK_USER_DIR ?= $(LOCALAPPDATA)/Rack2
  41. endif
  42. PLUGINS_DIR := $(RACK_USER_DIR)/plugins-$(ARCH_OS)-$(ARCH_CPU)
  43. DEP_FLAGS += -fPIC
  44. include $(RACK_DIR)/dep.mk
  45. all: $(TARGET)
  46. include $(RACK_DIR)/compile.mk
  47. clean:
  48. rm -rfv build $(TARGET) dist
  49. ZSTD_COMPRESSION_LEVEL ?= 19
  50. dist: all
  51. rm -rf dist
  52. mkdir -p dist/$(SLUG)
  53. @# Strip symbols from binary
  54. cp $(TARGET) dist/$(SLUG)/
  55. ifdef ARCH_MAC
  56. $(STRIP) -S dist/$(SLUG)/$(TARGET)
  57. $(INSTALL_NAME_TOOL) -change libRack.dylib /tmp/Rack2/libRack.dylib dist/$(SLUG)/$(TARGET)
  58. $(OTOOL) -L dist/$(SLUG)/$(TARGET)
  59. else
  60. $(STRIP) -s dist/$(SLUG)/$(TARGET)
  61. endif
  62. @# Sign binary if CODESIGN is defined
  63. ifdef CODESIGN
  64. $(CODESIGN) dist/$(SLUG)/$(TARGET)
  65. endif
  66. @# Copy distributables
  67. ifdef ARCH_MAC
  68. rsync -rR $(DISTRIBUTABLES) dist/$(SLUG)/
  69. else
  70. cp -r --parents $(DISTRIBUTABLES) dist/$(SLUG)/
  71. endif
  72. @# Create ZIP package
  73. cd dist && tar -c $(SLUG) | zstd -$(ZSTD_COMPRESSION_LEVEL) -o "$(SLUG)"-"$(VERSION)"-$(ARCH_NAME).vcvplugin
  74. install: dist
  75. mkdir -p "$(PLUGINS_DIR)"
  76. cp dist/*.vcvplugin "$(PLUGINS_DIR)"/
  77. .PHONY: clean dist
  78. .DEFAULT_GOAL := all