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