package.mk 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. ${COMMON_ENV}
  12. CONFIGURE_ENV+= PATH='${TARGET_PATH}' \
  13. ${COMMON_ENV} \
  14. ${TARGET_ENV} \
  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. GCC_HONOUR_COPTS=s \
  18. cross_compiling=yes
  19. CONFIGURE_PROG?= configure
  20. MAKE_FILE?= Makefile
  21. # this is environment for 'make all' and 'make install'
  22. MAKE_ENV?=
  23. # this is arguments for 'make all' and 'make install'
  24. XAKE_FLAGS?=
  25. # this is arguments for 'make all' ONLY
  26. MAKE_FLAGS?=
  27. # this is arguments for 'make install' ONLY
  28. FAKE_FLAGS?=
  29. ALL_TARGET?= all
  30. INSTALL_TARGET?= install
  31. MAKE_ENV+= PATH='${TARGET_PATH}' \
  32. ${COMMON_ENV} \
  33. ${TARGET_ENV} \
  34. PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig:${STAGING_TARGET_DIR}/usr/share/pkgconfig' \
  35. PKG_CONFIG_SYSROOT_DIR='${STAGING_TARGET_DIR}' \
  36. $(GCC_CHECK) \
  37. WRKDIR='${WRKDIR}' WRKDIST='${WRKDIST}' \
  38. WRKSRC='${WRKSRC}' WRKBUILD='${WRKBUILD}'
  39. MAKE_FLAGS+= ${XAKE_FLAGS} V=1
  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),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. ifneq ($(ADK_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. endif
  204. @mkdir -p $${PACKAGE_DIR} '$${STAGING_PKG_DIR}/stamps' \
  205. '$${STAGING_TARGET_DIR}/scripts'
  206. ifeq (,$(filter noremove,$(7)))
  207. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  208. cd '$${STAGING_TARGET_DIR}'; \
  209. while read fn; do \
  210. rm -f "$$$$fn"; \
  211. done <'$${STAGING_PKG_DIR}/$(1)'; \
  212. fi
  213. endif
  214. @rm -f '$${STAGING_PKG_DIR}/$(1)'
  215. ifeq (,$(filter nostaging,$(7)))
  216. @-cd $${IDIR_$(1)}; \
  217. x=$$$$(find tmp var -mindepth 1 2>/dev/null); if [[ -n $$$$x ]]; then \
  218. echo 'WARNING: $${IPKG_$(1)} installs files into a' \
  219. 'ramdisk location:' >&2; \
  220. echo "$$$$x" | sed 's/^/- /' >&2; \
  221. fi; \
  222. find usr ! -type d 2>/dev/null | \
  223. grep -E -v -e '^usr/lib/pkgconfig' -e '^usr/share' -e '^usr/doc' -e '^usr/src' -e '^usr/man' \
  224. -e '^usr/info' -e '^usr/lib/libc.so' -e '^usr/bin/[a-z0-9-]+-config' -e '^usr/lib/.*\.la$$$$' | \
  225. tee '$${STAGING_PKG_DIR}/$(1)' | \
  226. $(STAGING_HOST_DIR)/usr/bin/cpio -padlmu '$${STAGING_TARGET_DIR}'
  227. endif
  228. ifeq (,$(filter noscripts,$(7)))
  229. @cd '$${STAGING_TARGET_DIR}'; grep 'usr/s*bin/' \
  230. '$${STAGING_PKG_DIR}/$(1)' | \
  231. while read fn; do \
  232. b="$$$$(dd if="$$$$fn" bs=2 count=1 2>/dev/null)"; \
  233. [[ $$$$b = '#!' ]] || continue; \
  234. cp "$$$$fn" scripts/; \
  235. echo "scripts/$$$$(basename "$$$$fn")" \
  236. >>'$${STAGING_PKG_DIR}/$(1)'; \
  237. done
  238. endif
  239. ifeq (,$(filter devonly,$(7)))
  240. $${PKG_BUILD} $${IDIR_$(1)} $${PACKAGE_DIR} $(MAKE_TRACE)
  241. ifneq ($(ADK_DEBUG),y)
  242. $${PKG_BUILD} $${IDIR_$(1)_DBG} $${PACKAGE_DIR} $(MAKE_TRACE)
  243. endif
  244. endif
  245. ifneq (,$(filter dev,$(7)))
  246. $${PKG_BUILD} $${IDIR_$(1)_DEV} $${PACKAGE_DIR} $(MAKE_TRACE)
  247. endif
  248. clean-targets: clean-dev-$(1)
  249. clean-dev-$(1):
  250. ifeq (,$(filter noremove,$(7)))
  251. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  252. cd '$${STAGING_TARGET_DIR}'; \
  253. while read fn; do \
  254. rm -f "$$$$fn"; \
  255. done <'$${STAGING_PKG_DIR}/$(1)'; \
  256. fi
  257. endif
  258. @rm -f '$${STAGING_PKG_DIR}/$(1)'
  259. $$(INFO_$(1)): $$(IPKG_$(1))
  260. $(PKG_INSTALL) $$(IPKG_$(1))
  261. $$(INFO_$(1)_DBG): $$(IPKG_$(1)_DBG)
  262. $(PKG_INSTALL) $$(IPKG_$(1)_DBG)
  263. ifneq ($(1),UCLIBC_NG)
  264. ifneq ($(1),UCLIBC)
  265. ifneq ($(1),GLIBC)
  266. ifneq ($(1),MUSL)
  267. $$(INFO_$(1)_DEV): $$(IPKG_$(1)_DEV)
  268. $(PKG_INSTALL) $$(IPKG_$(1)_DEV)
  269. endif
  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. @$(CMD_TRACE) "cleaning... "
  281. @$(MAKE) clean-targets $(MAKE_TRACE)
  282. rm -rf ${WRKDIR} ${ALL_IPKGS} ${_IPKGS_COOKIE}
  283. distclean: clean
  284. rm -f ${FULLDISTFILES}
  285. .PHONY: all refetch extract patch configure \
  286. build fake package install clean build-all-pkgs