package.mk 11 KB

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