package.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. ac_cv_func_realloc_0_nonnull=yes \
  19. ac_cv_func_malloc_0_nonnull=yes \
  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} V=1
  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. # dev -> create a development subpackage with headers and pkg-config files
  80. # devonly -> create a development package only
  81. # should be package format independent and modular in the future
  82. define PKG_template
  83. ALL_PKGOPTS+= $(1)
  84. PKGNAME_$(1)= $(2)
  85. PKGDEPS_$(1)= $(4)
  86. PKGDESC_$(1)= $(5)
  87. PKGSECT_$(1)= $(6)
  88. IPKG_$(1)= $(PACKAGE_DIR)/$(2)_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
  89. IPKG_$(1)_DEV= $(PACKAGE_DIR)/$(2)-dev_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
  90. IPKG_$(1)_DBG= $(PACKAGE_DIR)/$(2)-dbg_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
  91. IDIR_$(1)= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)
  92. IDIR_$(1)_DEV= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)-dev
  93. IDIR_$(1)_DBG= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)-dbg
  94. ifneq (${ADK_PACKAGE_$(1)}${DEVELOPER},)
  95. ifneq (,$(filter dev,$(7)))
  96. ifneq ($(ADK_TARGET_USE_STATIC_LIBS),y)
  97. ALL_IPKGS+= $$(IPKG_$(1))
  98. ALL_IDIRS+= $${IDIR_$(1)}
  99. ALL_POSTINST+= $(2)-install
  100. $(2)-install:
  101. endif
  102. else
  103. ALL_IPKGS+= $$(IPKG_$(1))
  104. ALL_IDIRS+= $${IDIR_$(1)}
  105. ALL_POSTINST+= $(2)-install
  106. $(2)-install:
  107. endif
  108. endif
  109. INFO_$(1)= $(PKG_STATE_DIR)/info/$(2).list
  110. INFO_$(1)_DEV= $(PKG_STATE_DIR)/info/$(2)-dev.list
  111. INFO_$(1)_DBG= $(PKG_STATE_DIR)/info/$(2)-dbg.list
  112. ifeq ($(ADK_PACKAGE_$(1)),y)
  113. ifeq (,$(filter devonly,$(7)))
  114. ifeq ($(ADK_PACKAGE_$(1)_DBG),y)
  115. install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG)
  116. ifeq ($(ADK_PACKAGE_$(1)_DEV),y)
  117. install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG) $$(INFO_$(1)_DEV)
  118. else
  119. install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG)
  120. endif
  121. else
  122. ifeq ($(ADK_PACKAGE_$(1)_DEV),y)
  123. install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DEV)
  124. else
  125. install-targets: $$(INFO_$(1))
  126. endif
  127. endif
  128. else
  129. install-targets: $$(INFO_$(1))
  130. endif
  131. endif
  132. IDEPEND_$(1):= $$(strip $(4))
  133. _ALL_CONTROLS+= $$(IDIR_$(1))/CONTROL/control
  134. ICONTROL_$(1)?= $(WRKDIR)/.$(2).control
  135. ICONTROL_$(1)_DEV?= $(WRKDIR)/.$(2)-dev.control
  136. ICONTROL_$(1)_DBG?= $(WRKDIR)/.$(2)-dbg.control
  137. $$(IDIR_$(1))/CONTROL/control: ${_PATCH_COOKIE}
  138. @echo "Package: $$(shell echo $(2) | tr '_' '-')" > $(WRKDIR)/.$(2).control
  139. @echo "Section: $(6)" >> $(WRKDIR)/.$(2).control
  140. @echo "Description: $(5)" >> $(WRKDIR)/.$(2).control
  141. @${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)} $${ICONTROL_$(1)} $(3) ${ADK_TARGET_CPU_ARCH}
  142. @adeps='$$(strip $${IDEPEND_$(1)})'; if [[ -n $$$$adeps ]]; then \
  143. comma=; \
  144. deps=; \
  145. last=; \
  146. for dep in $$$$adeps; do \
  147. if [[ $$$$last = kernel && $$$$dep = \(* ]]; then \
  148. deps="$$$$deps $$$$dep"; \
  149. else \
  150. deps="$$$$deps$$$$comma$$$$dep"; \
  151. fi; \
  152. comma=", "; \
  153. last=$$$$dep; \
  154. done; \
  155. echo "Depends: $$$$deps" | tr '_' '-' >>$${IDIR_$(1)}/CONTROL/control; \
  156. fi
  157. @for file in conffiles preinst postinst prerm postrm; do \
  158. [ ! -f ./files/$(2).$$$$file ] || cp ./files/$(2).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file; \
  159. done
  160. ifeq ($(ADK_RUNTIME_START_$(1)),y)
  161. $(SED) "s#NO#YES#" $$(IDIR_$(1))/CONTROL/postinst
  162. endif
  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 ($(ADK_DEBUG),)
  179. @$${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  180. endif
  181. ifeq ($(ADK_DEBUG_STRIP),y)
  182. @$${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  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' -e '^usr/info' -e '^usr/lib/libc.so' -e '^usr/bin/[a-z0-9-]+-config' | \
  224. tee '$${STAGING_PKG_DIR}/$(1)' | \
  225. $(STAGING_HOST_DIR)/usr/bin/cpio -padlmu '$${STAGING_TARGET_DIR}'
  226. @cd '$${STAGING_TARGET_DIR}'; grep 'usr/lib/.*\.la$$$$' \
  227. '$${STAGING_PKG_DIR}/$(1)' | while read fn; do \
  228. chmod u+w $$$$fn; \
  229. $(SED) "s,\(^libdir='\| \|-L\|^dependency_libs='\)/usr/lib,\1$(STAGING_TARGET_DIR)/usr/lib,g" $$$$fn; \
  230. done
  231. endif
  232. ifeq (,$(filter noscripts,$(7)))
  233. @cd '$${STAGING_TARGET_DIR}'; grep 'usr/s*bin/' \
  234. '$${STAGING_PKG_DIR}/$(1)' | \
  235. while read fn; do \
  236. b="$$$$(dd if="$$$$fn" bs=2 count=1 2>/dev/null)"; \
  237. [[ $$$$b = '#!' ]] || continue; \
  238. cp "$$$$fn" scripts/; \
  239. echo "scripts/$$$$(basename "$$$$fn")" \
  240. >>'$${STAGING_PKG_DIR}/$(1)'; \
  241. done
  242. endif
  243. ifeq (,$(filter devonly,$(7)))
  244. $${PKG_BUILD} $${IDIR_$(1)} $${PACKAGE_DIR} $(MAKE_TRACE)
  245. ifneq ($(ADK_DEBUG),y)
  246. $${PKG_BUILD} $${IDIR_$(1)_DBG} $${PACKAGE_DIR} $(MAKE_TRACE)
  247. endif
  248. endif
  249. ifneq (,$(filter dev,$(7)))
  250. $${PKG_BUILD} $${IDIR_$(1)_DEV} $${PACKAGE_DIR} $(MAKE_TRACE)
  251. endif
  252. clean-targets: clean-dev-$(1)
  253. clean-dev-$(1):
  254. ifeq (,$(filter noremove,$(7)))
  255. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  256. cd '$${STAGING_TARGET_DIR}'; \
  257. while read fn; do \
  258. rm -f "$$$$fn"; \
  259. done <'$${STAGING_PKG_DIR}/$(1)'; \
  260. fi
  261. endif
  262. @rm -f '$${STAGING_PKG_DIR}/$(1)'
  263. $$(INFO_$(1)): $$(IPKG_$(1))
  264. $(PKG_INSTALL) $$(IPKG_$(1))
  265. $$(INFO_$(1)_DBG): $$(IPKG_$(1)_DBG)
  266. $(PKG_INSTALL) $$(IPKG_$(1)_DBG)
  267. ifneq ($(1),UCLIBC)
  268. ifneq ($(1),GLIBC)
  269. ifneq ($(1),MUSL)
  270. $$(INFO_$(1)_DEV): $$(IPKG_$(1)_DEV)
  271. $(PKG_INSTALL) $$(IPKG_$(1)_DEV)
  272. endif
  273. endif
  274. endif
  275. endef
  276. install-targets:
  277. install:
  278. @$(CMD_TRACE) "installing... "
  279. @$(MAKE) install-targets $(MAKE_TRACE)
  280. clean-targets:
  281. clean:
  282. @$(CMD_TRACE) "cleaning... "
  283. @$(MAKE) clean-targets $(MAKE_TRACE)
  284. rm -rf ${WRKDIR} ${ALL_IPKGS} ${STAGING_PKG_DIR}/stamps/${PKG_NAME}${PKG_VERSION}
  285. distclean: clean
  286. rm -f ${FULLDISTFILES}
  287. .PHONY: all refetch extract patch configure \
  288. build fake package install clean build-all-pkgs