package.mk 10 KB

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