package.mk 11 KB

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