package.mk 11 KB

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