Cross-Platform build scripts for audio plugins
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.

227 lines
6.8KB

  1. # Case conversion macros. This is inspired by the 'up' macro from gmsl
  2. # (http://gmsl.sf.net). It is optimised very heavily because these macros
  3. # are used a lot. It is about 5 times faster than forking a shell and tr.
  4. #
  5. # The caseconvert-helper creates a definition of the case conversion macro.
  6. # After expansion by the outer $(eval ), the UPPERCASE macro is defined as:
  7. # $(strip $(eval __tmp := $(1)) $(eval __tmp := $(subst a,A,$(__tmp))) ... )
  8. # In other words, every letter is substituted one by one.
  9. #
  10. # The caseconvert-helper allows us to create this definition out of the
  11. # [FROM] and [TO] lists, so we don't need to write down every substition
  12. # manually. The uses of $ and $$ quoting are chosen in order to do as
  13. # much expansion as possible up-front.
  14. #
  15. # Note that it would be possible to conceive a slightly more optimal
  16. # implementation that avoids the use of __tmp, but that would be even
  17. # more unreadable and is not worth the effort.
  18. [FROM] := a b c d e f g h i j k l m n o p q r s t u v w x y z - .
  19. [TO] := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ _
  20. define caseconvert-helper
  21. $(1) = $$(strip \
  22. $$(eval __tmp := $$(1))\
  23. $(foreach c, $(2),\
  24. $$(eval __tmp := $$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)),$$(__tmp))))\
  25. $$(__tmp))
  26. endef
  27. $(eval $(call caseconvert-helper,UPPERCASE,$(join $(addsuffix :,$([FROM])),$([TO]))))
  28. $(eval $(call caseconvert-helper,LOWERCASE,$(join $(addsuffix :,$([TO])),$([FROM]))))
  29. # utilities
  30. blank =
  31. comma = ,
  32. space = $(blank) $(blank)
  33. # Sanitize macro cleans up generic strings so it can be used as a filename
  34. # and in rules. Particularly useful for VCS version strings, that can contain
  35. # slashes, colons (OK in filenames but not in rules), and spaces.
  36. sanitize = $(subst $(space),_,$(subst :,_,$(subst /,_,$(strip $(1)))))
  37. # github(user,package,version): returns site of GitHub repository
  38. github = https://github.com/$(1)/$(2)/archive/$(3)
  39. # custom for PawPaw
  40. PKG = $(call UPPERCASE,$(call sanitize,$(pkgname)))
  41. $(PKG)_PKGDIR = $(CURDIR)/mod-plugin-builder/plugins/package/$(pkgname)
  42. BR2_TARGET_OPTIMIZATION =
  43. MAKE1 = make -j1
  44. PARALLEL_JOBS = $(shell nproc)
  45. WORKDIR ?= $(HOME)/mod-workdir
  46. HOST_DIR = $(WORKDIR)/moddwarf-new/host
  47. TARGET_CFLAGS = $(CFLAGS)
  48. TARGET_CXXFLAGS = $(CXXFLAGS)
  49. TARGET_LDFLAGS = $(LDFLAGS)
  50. TARGET_DIR = $(PAWPAW_PREFIX)
  51. ifeq ($(MACOS),true)
  52. libtoolize = glibtoolize
  53. else
  54. libtoolize = libtoolize
  55. endif
  56. ifeq ($(MACOS),true)
  57. STRIP = true
  58. else ifeq ($(WINDOWS),true)
  59. BR2_SKIP_LTO = y
  60. endif
  61. ifneq ($(TOOLCHAIN_PREFIX),)
  62. BR2_EXTRA_CONFIGURE_OPTS = --host=$(TOOLCHAIN_PREFIX) ac_cv_build=$(shell uname -m)-linux-gnu ac_cv_host=$(TOOLCHAIN_PREFIX)
  63. endif
  64. define generic-package
  65. endef
  66. define autotools-package
  67. define $$(PKG)_CONFIGURE_CMDS
  68. (cd $$($$(PKG)_BUILDDIR) && \
  69. ./configure \
  70. --disable-debug \
  71. --disable-doc \
  72. --disable-docs \
  73. --disable-maintainer-mode \
  74. --prefix='/usr' \
  75. $(BR2_EXTRA_CONFIGURE_OPTS) \
  76. $$($$(PKG)_CONF_OPTS) \
  77. )
  78. endef
  79. define $$(PKG)_BUILD_CMDS
  80. $(MAKE) -C $$($$(PKG)_BUILDDIR)
  81. endef
  82. ifndef $$(PKG)_INSTALL_TARGET_CMDS
  83. define $$(PKG)_INSTALL_TARGET_CMDS
  84. $(MAKE) -C $$($$(PKG)_BUILDDIR) install DESTDIR=$(PAWPAW_PREFIX)
  85. endef
  86. endif
  87. endef
  88. define cmake-package
  89. define $(PKG)_CONFIGURE_CMDS
  90. rm -f $$($$(PKG)_BUILDDIR)/CMakeCache.txt && \
  91. $$(CMAKE) -S $$($$(PKG)_BUILDDIR) -B $$($$(PKG)_BUILDDIR)/build \
  92. -DCMAKE_BUILD_TYPE=Release \
  93. -DCMAKE_INSTALL_LIBDIR=lib \
  94. -DCMAKE_INSTALL_PREFIX='/usr' \
  95. --no-warn-unused-cli \
  96. $$($$(PKG)_CONF_OPTS)
  97. endef
  98. define $(PKG)_BUILD_CMDS
  99. $(MAKE) -C $$($$(PKG)_BUILDDIR)/build
  100. endef
  101. ifndef $(PKG)_INSTALL_TARGET_CMDS
  102. define $(PKG)_INSTALL_TARGET_CMDS
  103. $(MAKE) -C $$($$(PKG)_BUILDDIR)/build install DESTDIR=$(PAWPAW_PREFIX)
  104. endef
  105. endif
  106. endef
  107. include $(CURDIR)/mod-plugin-builder/plugins/package/$(pkgname)/$(pkgname).mk
  108. $(PKG)_DLVERSION = $(call sanitize,$(strip $($(PKG)_VERSION)))
  109. $(PKG)_BUILDDIR = $(PAWPAW_BUILDDIR)/$(pkgname)-$($(PKG)_DLVERSION)
  110. ifdef $(PKG)_SOURCE
  111. $(PKG)_DLSITE = $($(PKG)_SITE)/$($(PKG)_SOURCE)
  112. else
  113. $(PKG)_SOURCE = $(pkgname)-$($(PKG)_DLVERSION).tar.gz
  114. $(PKG)_DLSITE = $($(PKG)_SITE).tar.gz
  115. endif
  116. $(PKG)_DLFILE = $(PAWPAW_DOWNLOADDIR)/$($(PKG)_SOURCE)
  117. STAMP_EXTRACTED = $($(PKG)_BUILDDIR)/.stamp_extracted
  118. STAMP_PATCHED = $($(PKG)_BUILDDIR)/.stamp_patched
  119. STAMP_CONFIGURED = $($(PKG)_BUILDDIR)/.stamp_configured
  120. STAMP_BUILT = $($(PKG)_BUILDDIR)/.stamp_built
  121. STAMP_INSTALLED = $($(PKG)_BUILDDIR)/.stamp_installed
  122. STAMP_PINSTALLED = $($(PKG)_BUILDDIR)/.stamp_post_installed
  123. PAWPAW_TMPDIR = /tmp/PawPaw
  124. PAWPAW_TMPNAME = git-dl
  125. all: $(STAMP_PINSTALLED)
  126. $(STAMP_PINSTALLED): $(STAMP_INSTALLED)
  127. $(call $($(PKG)_POST_INSTALL_TARGET_HOOKS))
  128. ifneq (,$(wildcard $(PAWPAW_PREFIX)/usr/lib/lv2/$(firstword $($(PKG)_BUNDLES))/*.dll))
  129. $(foreach b,$($(PKG)_BUNDLES),sed -i -e 's|lv2:binary <\([_a-zA-Z0-9-]*\)\.so>|lv2:binary <\1\.dll>|g' $(PAWPAW_PREFIX)/usr/lib/lv2/$(b)/manifest.ttl;)
  130. $(foreach b,$($(PKG)_BUNDLES),rm -f $(PAWPAW_PREFIX)/usr/lib/lv2/$(b)/*.dll.a;)
  131. endif
  132. touch $@
  133. $(STAMP_INSTALLED): $(STAMP_BUILT)
  134. $($(PKG)_INSTALL_TARGET_CMDS)
  135. touch $@
  136. $(STAMP_BUILT): $(STAMP_CONFIGURED)
  137. ifeq ($(MACOS),true)
  138. $(foreach p,$(wildcard $($(PKG)_BUILDDIR)/Makefile $($(PKG)_BUILDDIR)/*/makefile),\
  139. sed -i -e 's/-Wl,--gc-sections//g' $(p);)
  140. $(foreach p,$(wildcard $($(PKG)_BUILDDIR)/*/makefile),\
  141. sed -i -e 's/-Wl,--no-undefined//g' $(p);)
  142. $(foreach p,$(wildcard $($(PKG)_BUILDDIR)/*/makefile),\
  143. sed -i -e 's/-Wl,--exclude-libs,ALL//g' $(p);)
  144. $(foreach p,$(wildcard $($(PKG)_BUILDDIR)/*/makefile),\
  145. sed -i -e 's/-Wl,-z,relro,-z,now//g' $(p);)
  146. $(foreach p,$(wildcard $($(PKG)_BUILDDIR)/*/makefile),\
  147. sed -i -e 's/-Wl,-z,noexecstack//g' $(p);)
  148. endif
  149. $($(PKG)_BUILD_CMDS)
  150. touch $@
  151. $(STAMP_CONFIGURED): $(STAMP_PATCHED)
  152. ifeq ($($(PKG)_AUTORECONF),YES)
  153. (cd $($(PKG)_BUILDDIR) && \
  154. aclocal --force && \
  155. $(libtoolize) --force --automake --copy && \
  156. autoheader --force && \
  157. autoconf --force && \
  158. automake -a --copy \
  159. )
  160. endif
  161. $($(PKG)_CONFIGURE_CMDS)
  162. touch $@
  163. $(STAMP_PATCHED): $(STAMP_EXTRACTED)
  164. $(foreach p,$(wildcard $($(PKG)_PKGDIR)/*.patch),patch -p1 -d '$($(PKG)_BUILDDIR)' -i $(p);)
  165. touch $@
  166. $(STAMP_EXTRACTED): $($(PKG)_DLFILE)
  167. mkdir -p '$($(PKG)_BUILDDIR)'
  168. tar -xf '$($(PKG)_DLFILE)' -C '$($(PKG)_BUILDDIR)' --strip-components=1
  169. touch $@
  170. $($(PKG)_DLFILE):
  171. ifeq ($($(PKG)_SITE_METHOD),git)
  172. rm -rf '$(PAWPAW_TMPDIR)'
  173. git clone '$($(PKG)_SITE)' '$(PAWPAW_TMPDIR)/$(PAWPAW_TMPNAME)' && \
  174. git -C '$(PAWPAW_TMPDIR)/$(PAWPAW_TMPNAME)' checkout '$($(PKG)_VERSION)' && \
  175. touch '$(PAWPAW_TMPDIR)/$(PAWPAW_TMPNAME)/.gitmodules' && \
  176. sed -i -e 's|git://github.com/|https://github.com/|g' '$(PAWPAW_TMPDIR)/$(PAWPAW_TMPNAME)/.gitmodules' && \
  177. git -C '$(PAWPAW_TMPDIR)/$(PAWPAW_TMPNAME)' submodule update --recursive --init && \
  178. tar --exclude='.git' -czf '$($(PKG)_DLFILE)' -C '$(PAWPAW_TMPDIR)' '$(PAWPAW_TMPNAME)'
  179. rm -rf '$(PAWPAW_TMPDIR)'
  180. else
  181. wget -O '$($(PKG)_DLFILE)' '$($(PKG)_DLSITE)'
  182. endif