package.mk 11 KB

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