package.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. all: build-all-pkgs
  4. # does not change CONFIGURE_ARGS in minimal mode
  5. ifeq ($(filter minimal,${CONFIG_STYLE}),)
  6. ifneq ($(ADK_DEBUG),)
  7. CONFIGURE_ARGS+= --enable-debug
  8. endif
  9. endif
  10. AUTOTOOL_ENV+= PATH='${HOST_PATH}' \
  11. PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig:${STAGING_TARGET_DIR}/usr/share/pkgconfig' \
  12. PKG_CONFIG_SYSROOT_DIR='${STAGING_TARGET_DIR}' \
  13. ${COMMON_ENV}
  14. MESON_ENV+= PATH='${HOST_PATH}' \
  15. PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig:${STAGING_TARGET_DIR}/usr/share/pkgconfig' \
  16. PKG_CONFIG_SYSROOT_DIR='${STAGING_TARGET_DIR}'
  17. CONFIGURE_ENV+= PATH='${TARGET_PATH}' \
  18. ${COMMON_ENV} \
  19. ${TARGET_ENV} \
  20. PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig:${STAGING_TARGET_DIR}/usr/share/pkgconfig' \
  21. PKG_CONFIG_SYSROOT_DIR='${STAGING_TARGET_DIR}' \
  22. cross_compiling=yes
  23. CONFIGURE_PROG?= configure
  24. MAKE_FILE?= Makefile
  25. # this is environment for 'make all' and 'make install'
  26. MAKE_ENV?=
  27. # this is arguments for 'make all' and 'make install'
  28. XAKE_FLAGS?=
  29. # this is arguments for 'make all' ONLY
  30. MAKE_FLAGS?=
  31. # this is arguments for 'make install' ONLY
  32. FAKE_FLAGS?=
  33. ALL_TARGET?= all
  34. INSTALL_TARGET?= install
  35. MAKE_ENV+= PATH='${TARGET_PATH}' \
  36. ${COMMON_ENV} \
  37. ${TARGET_ENV} \
  38. PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig:${STAGING_TARGET_DIR}/usr/share/pkgconfig' \
  39. PKG_CONFIG_SYSROOT_DIR='${STAGING_TARGET_DIR}' \
  40. WRKDIR='${WRKDIR}' WRKDIST='${WRKDIST}' \
  41. WRKSRC='${WRKSRC}' WRKBUILD='${WRKBUILD}'
  42. MAKE_FLAGS+= ${XAKE_FLAGS}
  43. FAKE_FLAGS+= ${XAKE_FLAGS}
  44. ifeq ($(strip ${WRKDIR_BSD}),)
  45. WRKDIR_BASE:= ${BUILD_DIR}
  46. else
  47. WRKDIR_BASE:= $(shell pwd)
  48. endif
  49. _EXTRACT_COOKIE= ${WRKDIST}/.extract_done
  50. _PATCH_COOKIE= ${WRKDIST}/.prepared
  51. _CONFIGURE_COOKIE= ${WRKBUILD}/.configure_done
  52. _BUILD_COOKIE= ${WRKBUILD}/.build_done
  53. _FAKE_COOKIE= ${WRKINST}/.fake_done
  54. _IPKGS_COOKIE= ${STAGING_PKG_DIR}/stamps/${PKG_NAME}${PKG_VERSION}-${PKG_RELEASE}
  55. _IN_PACKAGE:= 1
  56. include ${ADK_TOPDIR}/mk/buildhlp.mk
  57. # defined in buildhlp.mk ('extract' can fail, use 'patch' then)
  58. extract: ${_EXTRACT_COOKIE}
  59. patch: ${_PATCH_COOKIE}
  60. # defined below (will be moved to pkg-bottom.mk!)
  61. configure: ${_CONFIGURE_COOKIE}
  62. build: ${_BUILD_COOKIE}
  63. fake: ${_FAKE_COOKIE}
  64. # our recursive build entry point
  65. build-all-pkgs: ${_IPKGS_COOKIE}
  66. # there are some parameters to the PKG_template function
  67. # 1.) Config.in identifier ADK_PACKAGE_$(1)
  68. # 2.) name of the package, for single package mostly $(PKG_NAME)
  69. # 3.) package version (upstream version) and package release (adk version),
  70. # always $(PKG_VERSION)-$(PKG_RELEASE)
  71. # 4.) dependencies to other packages, $(PKG_DEPENDS)
  72. # 5.) description for the package, $(PKG_DESCR)
  73. # 6.) section of the package, $(PKG_SECTION)
  74. # 7.) special package options $(PKG_OPTS)
  75. # noscripts -> do not install scripts to $(STAGING_TARGET_DIR)/scripts
  76. # (needed for example for autoconf/automake)
  77. # noremove -> do not remove files from $(STAGING_TARGET_DIR) while
  78. # cleaning (needed for toolchain packages like glibc)
  79. # nostaging -> do not install files to $(STAGING_TARGET_DIR)
  80. # nostrip -> do not strip files
  81. # dev -> create a development subpackage with headers and pkg-config files
  82. # devonly -> create a development package only
  83. # should be package format independent and modular in the future
  84. define PKG_template
  85. ALL_PKGOPTS+= $(1)
  86. PKGNAME_$(1)= $(2)
  87. PKGDEPS_$(1)= $(4)
  88. PKGDESC_$(1)= $(5)
  89. PKGSECT_$(1)= $(6)
  90. IPKG_$(1)= $(PACKAGE_DIR)/$(2)_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
  91. IPKG_$(1)_DEV= $(PACKAGE_DIR)/$(2)-dev_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
  92. IPKG_$(1)_DBG= $(PACKAGE_DIR)/$(2)-dbg_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
  93. IDIR_$(1)= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)
  94. IDIR_$(1)_DEV= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)-dev
  95. IDIR_$(1)_DBG= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)-dbg
  96. ifneq (${ADK_PACKAGE_$(1)}${DEVELOPER},)
  97. ifneq (,$(filter dev,$(7)))
  98. ifneq ($(ADK_TARGET_USE_STATIC_LIBS_ONLY),y)
  99. ifneq ($(ADK_TARGET_BINFMT_FLAT),y)
  100. ALL_IPKGS+= $$(IPKG_$(1))
  101. ALL_IDIRS+= $${IDIR_$(1)}
  102. ALL_POSTINST+= $(2)-install
  103. $(2)-install:
  104. endif
  105. endif
  106. else
  107. ALL_IPKGS+= $$(IPKG_$(1))
  108. ALL_IDIRS+= $${IDIR_$(1)}
  109. ALL_POSTINST+= $(2)-install
  110. $(2)-install:
  111. endif
  112. endif
  113. INFO_$(1)= $(PKG_STATE_DIR)/info/$(2).list
  114. INFO_$(1)_DEV= $(PKG_STATE_DIR)/info/$(2)-dev.list
  115. INFO_$(1)_DBG= $(PKG_STATE_DIR)/info/$(2)-dbg.list
  116. ifeq ($(ADK_PACKAGE_$(1)),y)
  117. ifeq (,$(filter devonly,$(7)))
  118. ifeq ($(ADK_PACKAGE_$(1)_DBG),y)
  119. install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG)
  120. ifeq ($(ADK_PACKAGE_$(1)_DEV),y)
  121. install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG) $$(INFO_$(1)_DEV)
  122. else
  123. install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG)
  124. endif
  125. else
  126. ifeq ($(ADK_PACKAGE_$(1)_DEV),y)
  127. install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DEV)
  128. else
  129. install-targets: $$(INFO_$(1))
  130. endif
  131. endif
  132. else
  133. install-targets: $$(INFO_$(1))
  134. endif
  135. endif
  136. IDEPEND_$(1):= $$(strip $(4))
  137. _ALL_CONTROLS+= $$(IDIR_$(1))/CONTROL/control
  138. ICONTROL_$(1)?= $(WRKDIR)/.$(2).control
  139. ICONTROL_$(1)_DEV?= $(WRKDIR)/.$(2)-dev.control
  140. ICONTROL_$(1)_DBG?= $(WRKDIR)/.$(2)-dbg.control
  141. $$(IDIR_$(1))/CONTROL/control: ${_PATCH_COOKIE}
  142. @echo "Package: $$(shell echo $(2) | tr '_' '-')" > $(WRKDIR)/.$(2).control
  143. @echo "Section: $(6)" >> $(WRKDIR)/.$(2).control
  144. @echo "Description: $(5)" >> $(WRKDIR)/.$(2).control
  145. @${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)} $${ICONTROL_$(1)} $(3) ${ADK_TARGET_CPU_ARCH}
  146. @adeps='$$(strip $${IDEPEND_$(1)})'; if [[ -n $$$$adeps ]]; then \
  147. comma=; \
  148. deps=; \
  149. last=; \
  150. for dep in $$$$adeps; do \
  151. if [[ $$$$last = kernel && $$$$dep = \(* ]]; then \
  152. deps="$$$$deps $$$$dep"; \
  153. else \
  154. deps="$$$$deps$$$$comma$$$$dep"; \
  155. fi; \
  156. comma=", "; \
  157. last=$$$$dep; \
  158. done; \
  159. echo "Depends: $$$$deps" | tr '_' '-' >>$${IDIR_$(1)}/CONTROL/control; \
  160. fi
  161. @for file in conffiles preinst postinst prerm postrm; do \
  162. [ ! -f ./files/$(2).$$$$file ] || cp ./files/$(2).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file; \
  163. done
  164. ifeq ($(ADK_BUILD_WITH_DEBUG),y)
  165. @echo "Package: $$(shell echo $(2) | tr '_' '-')-dbg" > $(WRKDIR)/.$(2)-dbg.control
  166. @echo "Section: debug" >> $(WRKDIR)/.$(2)-dbg.control
  167. @echo "Description: debugging symbols for $(2)" >> $(WRKDIR)/.$(2)-dbg.control
  168. @${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)_DBG} $${ICONTROL_$(1)_DBG} $(3) ${ADK_TARGET_CPU_ARCH}
  169. @echo "Depends: $$(shell echo $(2) | tr '_' '-')" >> $${IDIR_$(1)_DBG}/CONTROL/control
  170. endif
  171. ifneq (,$(filter dev,$(7)))
  172. @echo "Package: $$(shell echo $(2) | tr '_' '-')-dev" > $(WRKDIR)/.$(2)-dev.control
  173. @echo "Section: devel" >> $(WRKDIR)/.$(2)-dev.control
  174. @echo "Description: development files for $(2)" >> $(WRKDIR)/.$(2)-dev.control
  175. @${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)_DEV} $${ICONTROL_$(1)_DEV} $(3) ${ADK_TARGET_CPU_ARCH}
  176. @echo "Depends: $$(shell echo $(2) | tr '_' '-')" >> $${IDIR_$(1)_DEV}/CONTROL/control
  177. endif
  178. $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $${_FAKE_COOKIE}
  179. ifeq (,$(filter nostrip,$(7)))
  180. ifeq ($(ADK_DEBUG),)
  181. @$${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  182. endif
  183. ifeq ($(ADK_DEBUG_STRIP),y)
  184. @$${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  185. endif
  186. endif
  187. ifeq (${ADK_LEAVE_ETC_ALONE}$(filter force_etc,$(7)),y)
  188. -rm -rf $${IDIR_$(1)}/etc
  189. else
  190. ifeq (${ADK_INSTALL_PACKAGE_INIT_SCRIPTS},y)
  191. @for file in $$$$(ls ./files/*.init 2>/dev/null); do \
  192. fname=$$$$(echo $$$$file| sed -e "s#.*/##" -e "s#.init##"); \
  193. check=$$$$(grep PKG $$$$file|cut -d ' ' -f 2); \
  194. if [ "$$$$check" == $(2) ];then \
  195. mkdir -p $$(IDIR_$(1))/etc/init.d && cp $$$$file $$(IDIR_$(1))/etc/init.d/$$$$fname; \
  196. fi; \
  197. done
  198. @cd $${IDIR_$(1)}; for script in etc/init.d/*; do \
  199. [[ -e $$$$script ]] || continue; \
  200. chmod 0755 "$$$$script"; \
  201. done
  202. endif
  203. ifneq (${ADK_INSTALL_PACKAGE_NETWORK_SCRIPTS},y)
  204. -@rm -rf $${IDIR_$(1)}/etc/network
  205. endif
  206. ifeq (${ADK_RUNTIME_INIT_SYSTEMD},y)
  207. @for file in $$$$(ls ./files/*.service 2>/dev/null); do \
  208. fname=$$$$(echo $$$$file| sed -e "s#.*/##"); \
  209. mkdir -p $$(IDIR_$(1))/usr/lib/systemd/system && cp $$$$file $$(IDIR_$(1))/usr/lib/systemd/system/$$$$fname; \
  210. mkdir -p $$(IDIR_$(1))/etc/systemd/system/multi-user.target.wants; \
  211. ln -sf ../../../../usr/lib/systemd/system/$$$$fname \
  212. $$(IDIR_$(1))/etc/systemd/system/multi-user.target.wants; \
  213. done
  214. endif
  215. endif
  216. @mkdir -p $${PACKAGE_DIR} '$${STAGING_PKG_DIR}/stamps' \
  217. '$${STAGING_TARGET_DIR}/scripts'
  218. @for file in $$$$(ls ./files/*.perm 2>/dev/null); do \
  219. cat $$$$file >> $${STAGING_TARGET_DIR}/scripts/permissions.sh; \
  220. done
  221. ifeq (,$(filter noremove,$(7)))
  222. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  223. cd '$${STAGING_TARGET_DIR}'; \
  224. while read fn; do \
  225. rm -f "$$$$fn"; \
  226. done <'$${STAGING_PKG_DIR}/$(1)'; \
  227. fi
  228. endif
  229. @rm -f '$${STAGING_PKG_DIR}/$(1)'
  230. ifeq (,$(filter nostaging,$(7)))
  231. @-cd $${IDIR_$(1)}; \
  232. x=$$$$(find tmp run -mindepth 1 2>/dev/null); if [[ -n $$$$x ]]; then \
  233. echo 'WARNING: $${IPKG_$(1)} installs files into a' \
  234. 'ramdisk location:' >&2; \
  235. echo "$$$$x" | sed 's/^/- /' >&2; \
  236. fi; \
  237. find usr ! -type d 2>/dev/null | \
  238. grep -E -v -e '^usr/lib/pkgconfig' -e '^usr/share' -e '^usr/doc' -e '^usr/src' -e '^usr/man' \
  239. -e '^usr/info' -e '^usr/lib/libc.so' -e '^usr/bin/[a-z0-9-]+-config' -e '^usr/lib/.*\.la$$$$' | \
  240. tee '$${STAGING_PKG_DIR}/$(1)' | \
  241. $(CPIO) -padlmu --quiet '$${STAGING_TARGET_DIR}'
  242. endif
  243. ifeq (,$(filter noscripts,$(7)))
  244. @cd '$${STAGING_TARGET_DIR}'; grep 'usr/s*bin/' \
  245. '$${STAGING_PKG_DIR}/$(1)' | \
  246. while read fn; do \
  247. b="$$$$(dd if="$$$$fn" bs=2 count=1 2>/dev/null)"; \
  248. [[ $$$$b = '#!' ]] || continue; \
  249. cp "$$$$fn" scripts/; \
  250. echo "scripts/$$$$(basename "$$$$fn")" \
  251. >>'$${STAGING_PKG_DIR}/$(1)'; \
  252. done
  253. endif
  254. ifeq (,$(filter devonly,$(7)))
  255. PATH='$(HOST_PATH)' $${PKG_BUILD} $${IDIR_$(1)} $${PACKAGE_DIR} $(MAKE_TRACE)
  256. ifneq ($(ADK_BUILD_WITH_DEBUG),)
  257. PATH='$(HOST_PATH)' $${PKG_BUILD} $${IDIR_$(1)_DBG} $${PACKAGE_DIR} $(MAKE_TRACE)
  258. endif
  259. endif
  260. ifneq (,$(filter dev,$(7)))
  261. PATH='$(HOST_PATH)' $${PKG_BUILD} $${IDIR_$(1)_DEV} $${PACKAGE_DIR} $(MAKE_TRACE)
  262. endif
  263. clean-targets: clean-dev-$(1)
  264. clean-dev-$(1):
  265. ifeq (,$(filter noremove,$(7)))
  266. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  267. cd '$${STAGING_TARGET_DIR}'; \
  268. while read fn; do \
  269. rm -f "$$$$fn"; \
  270. done <'$${STAGING_PKG_DIR}/$(1)'; \
  271. fi
  272. endif
  273. @rm -f '$${STAGING_PKG_DIR}/$(1)'
  274. $$(INFO_$(1)): $$(IPKG_$(1))
  275. $(PKG_INSTALL) $$(IPKG_$(1))
  276. $$(INFO_$(1)_DBG): $$(IPKG_$(1)_DBG)
  277. $(PKG_INSTALL) $$(IPKG_$(1)_DBG)
  278. ifneq ($(1),UCLIBC_NG)
  279. ifneq ($(1),GLIBC)
  280. ifneq ($(1),MUSL)
  281. $$(INFO_$(1)_DEV): $$(IPKG_$(1)_DEV)
  282. $(PKG_INSTALL) $$(IPKG_$(1)_DEV)
  283. endif
  284. endif
  285. endif
  286. endef
  287. install-targets:
  288. install:
  289. @$(CMD_TRACE) "installing.. "
  290. @$(MAKE) install-targets $(MAKE_TRACE)
  291. clean-targets:
  292. clean:
  293. @printf " ---> cleaning package build directories and files.. "
  294. @$(MAKE) clean-targets $(MAKE_TRACE)
  295. rm -rf ${WRKDIR} ${ALL_IPKGS} ${_IPKGS_COOKIE}
  296. @printf " done\n"
  297. distclean: clean
  298. rm -f ${FULLDISTFILES}
  299. .PHONY: all refetch extract patch configure \
  300. build fake package install clean build-all-pkgs