package.mk 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. CONFIGURE_ENV+= GCC_HONOUR_COPTS=s \
  11. PATH='${TARGET_PATH}' \
  12. CONFIG_SHELL='$(strip ${SHELL})' \
  13. CFLAGS='$(strip ${TARGET_CFLAGS})' \
  14. CXXFLAGS='$(strip ${TARGET_CXXFLAGS})' \
  15. CPPFLAGS='$(strip ${TARGET_CPPFLAGS})' \
  16. LDFLAGS='$(strip ${TARGET_LDFLAGS})' \
  17. ${HOST_CONFIGURE_OPTS} \
  18. PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig' \
  19. ac_cv_func_realloc_0_nonnull=yes \
  20. ac_cv_func_malloc_0_nonnull=yes
  21. ifeq ($(ADK_NATIVE),)
  22. CONFIGURE_ENV+= ${TARGET_CONFIGURE_OPTS} cross_compiling=yes
  23. endif
  24. CONFIGURE_PROG?= configure
  25. MAKE_FILE?= Makefile
  26. # this is environment for 'make all' and 'make install'
  27. MAKE_ENV?=
  28. # this is arguments for 'make all' and 'make install'
  29. XAKE_FLAGS?=
  30. # this is arguments for 'make all' ONLY
  31. MAKE_FLAGS?=
  32. # this is arguments for 'make install' ONLY
  33. FAKE_FLAGS?=
  34. ALL_TARGET?= all
  35. INSTALL_TARGET?= install
  36. MAKE_ENV+= GCC_HONOUR_COPTS=2 \
  37. PATH='${TARGET_PATH}' \
  38. WRKDIR='${WRKDIR}' WRKDIST='${WRKDIST}' \
  39. WRKSRC='${WRKSRC}' WRKBUILD='${WRKBUILD}' \
  40. CFLAGS='$(strip ${TARGET_CFLAGS})' \
  41. CXXFLAGS='$(strip ${TARGET_CXXFLAGS})' \
  42. CPPFLAGS='$(strip ${TARGET_CPPFLAGS})' \
  43. LDFLAGS='$(strip ${TARGET_LDFLAGS})' \
  44. ${HOST_CONFIGURE_OPTS} \
  45. PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig'
  46. ifeq ($(ADK_NATIVE),)
  47. MAKE_ENV+= ${TARGET_CONFIGURE_OPTS}
  48. else
  49. MAKE_ENV+= M4=m4
  50. endif
  51. MAKE_FLAGS+= ${XAKE_FLAGS} V=1
  52. FAKE_FLAGS+= ${XAKE_FLAGS}
  53. ifeq ($(strip ${WRKDIR_BSD}),)
  54. WRKDIR_BASE:= ${BUILD_DIR}
  55. else
  56. WRKDIR_BASE:= $(shell pwd)
  57. endif
  58. _EXTRACT_COOKIE= ${WRKDIST}/.extract_done
  59. _PATCH_COOKIE= ${WRKDIST}/.prepared
  60. _CONFIGURE_COOKIE= ${WRKBUILD}/.configure_done
  61. _BUILD_COOKIE= ${WRKBUILD}/.build_done
  62. _FAKE_COOKIE= ${WRKINST}/.fake_done
  63. _IPKGS_COOKIE= ${PACKAGE_DIR}/.stamps/${PKG_NAME}${PKG_VERSION}-${PKG_RELEASE}
  64. _IN_PACKAGE:= 1
  65. include ${TOPDIR}/mk/buildhlp.mk
  66. # defined in buildhlp.mk ('extract' can fail, use 'patch' then)
  67. extract: ${_EXTRACT_COOKIE}
  68. patch: ${_PATCH_COOKIE}
  69. # defined below (will be moved to pkg-bottom.mk!)
  70. configure: ${_CONFIGURE_COOKIE}
  71. build: ${_BUILD_COOKIE}
  72. fake: ${_FAKE_COOKIE}
  73. rebuild:
  74. @if [ -f ${TOPDIR}/.rebuild.${PKG_NAME} ];then \
  75. $(MAKE) clean; \
  76. rm -f ${TOPDIR}/.rebuild.${PKG_NAME}; \
  77. fi
  78. # our recursive build entry point
  79. build-all-pkgs: ${_IPKGS_COOKIE}
  80. # there are some parameters to the PKG_template function
  81. # 1.) Config.in identifier ADK_PACKAGE_$(1)
  82. # 2.) name of the package, for single package mostly $(PKG_NAME)
  83. # 3.) package version (upstream version) and package release (adk version),
  84. # always $(PKG_VERSION)-$(PKG_RELEASE)
  85. # 4.) dependencies to other packages, $(PKG_DEPENDS)
  86. # 5.) description for the package, $(PKG_DESCR)
  87. # 6.) section of the package, $(PKG_SECTION)
  88. # 7.) special package options
  89. # noscripts -> do not install scripts to $(STAGING_TARGET_DIR)/target/scripts
  90. # (needed for example for autoconf/automake)
  91. # noremove -> do not remove files from $(STAGING_TARGET_DIR)/target while
  92. # cleaning (needed for toolchain packages like glibc/eglibc)
  93. # should be package format independent and modular in the future
  94. define PKG_template
  95. ALL_PKGOPTS+= $(1)
  96. PKGNAME_$(1)= $(2)
  97. PKGDEPS_$(1)= $(4)
  98. PKGDESC_$(1)= $(5)
  99. PKGSECT_$(1)= $(6)
  100. IPKG_$(1)= $(PACKAGE_DIR)/$(2)_$(3)_${CPU_ARCH}.${PKG_SUFFIX}
  101. IDIR_$(1)= $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(2)
  102. ifneq (${ADK_PACKAGE_$(1)}${DEVELOPER},)
  103. ALL_IPKGS+= $$(IPKG_$(1))
  104. ALL_IDIRS+= $${IDIR_$(1)}
  105. ALL_POSTINST+= $(2)-install
  106. $(2)-install:
  107. endif
  108. INFO_$(1)= $(PKG_STATE_DIR)/info/$(2).list
  109. ifeq ($(ADK_PACKAGE_$(1)),y)
  110. install-targets: $$(INFO_$(1))
  111. endif
  112. IDEPEND_$(1):= $$(strip $(4))
  113. _ALL_CONTROLS+= $$(IDIR_$(1))/CONTROL/control
  114. ICONTROL_$(1)?= $(WRKDIR)/.$(2).control
  115. $$(IDIR_$(1))/CONTROL/control: ${_PATCH_COOKIE}
  116. @echo "Package: $$(shell echo $(2) | tr '_' '-')" > $(WRKDIR)/.$(2).control
  117. @echo "Section: $(6)" >> $(WRKDIR)/.$(2).control
  118. @echo "Description: $(5)" >> $(WRKDIR)/.$(2).control
  119. ${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)} $${ICONTROL_$(1)} $(3) ${CPU_ARCH}
  120. @adeps='$$(strip $${IDEPEND_$(1)})'; if [[ -n $$$$adeps ]]; then \
  121. comma=; \
  122. deps=; \
  123. last=; \
  124. for dep in $$$$adeps; do \
  125. if [[ $$$$last = kernel && $$$$dep = \(* ]]; then \
  126. deps="$$$$deps $$$$dep"; \
  127. else \
  128. deps="$$$$deps$$$$comma$$$$dep"; \
  129. fi; \
  130. comma=", "; \
  131. last=$$$$dep; \
  132. done; \
  133. echo "Depends: $$$$deps" | tr '_' '-' >>$${IDIR_$(1)}/CONTROL/control; \
  134. fi
  135. @for file in conffiles preinst postinst prerm postrm; do \
  136. [ ! -f ./files/$(2).$$$$file ] || cp ./files/$(2).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file; \
  137. done
  138. $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $${_FAKE_COOKIE}
  139. ifeq ($(ADK_DEBUG),)
  140. $${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  141. endif
  142. ifeq ($(ADK_DEBUG_STRIP),y)
  143. $${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  144. endif
  145. ifeq (${ADK_INSTALL_PACKAGE_INIT_SCRIPTS},y)
  146. @for file in $$$$(ls ./files/*.init 2>/dev/null); do \
  147. fname=$$$$(echo $$$$file| sed -e "s#.*/##" -e "s#.init##"); \
  148. check=$$$$(grep PKG $$$$file|cut -d ' ' -f 2); \
  149. if [ "$$$$check" == $(2) ];then \
  150. mkdir -p $$(IDIR_$(1))/etc/init.d && cp $$$$file $$(IDIR_$(1))/etc/init.d/$$$$fname; \
  151. fi; \
  152. done
  153. @cd $${IDIR_$(1)}; for script in etc/init.d/*; do \
  154. [[ -e $$$$script ]] || continue; \
  155. chmod 0755 "$$$$script"; \
  156. done
  157. endif
  158. @mkdir -p $${PACKAGE_DIR} '$${STAGING_PKG_DIR}' \
  159. '$${STAGING_DIR}/scripts'
  160. ifeq (,$(filter noremove,$(7)))
  161. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  162. cd '$${STAGING_DIR}'; \
  163. while read fn; do \
  164. rm -f "$$$$fn"; \
  165. done <'$${STAGING_PKG_DIR}/$(1)'; \
  166. fi
  167. endif
  168. @rm -f '$${STAGING_PKG_DIR}/$(1)'
  169. -@cd $${IDIR_$(1)}; \
  170. x=$$$$(find tmp var -mindepth 1 2>/dev/null); if [[ -n $$$$x ]]; then \
  171. echo 'WARNING: $${IPKG_$(1)} installs files into a' \
  172. 'ramdisk location:' >&2; \
  173. echo "$$$$x" | sed 's/^/- /' >&2; \
  174. fi; \
  175. 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" ];then \
  176. find lib \( -name lib\*.so\* -o -name lib\*.a \) \
  177. -exec echo 'WARNING: $${IPKG_$(1)} installs files in /lib -' \
  178. ' fix this!' >&2 \; -quit 2>/dev/null; fi; \
  179. find usr ! -type d 2>/dev/null | \
  180. 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' | \
  181. tee '$${STAGING_PKG_DIR}/$(1)' | \
  182. $(TOOLS_DIR)/cpio -padlmu '$${STAGING_DIR}'
  183. @cd '$${STAGING_DIR}'; grep 'usr/lib/.*\.la$$$$' \
  184. '$${STAGING_PKG_DIR}/$(1)' | while read fn; do \
  185. chmod u+w $$$$fn; \
  186. $(SED) "s,\(^libdir='\| \|-L\|^dependency_libs='\)/usr/lib,\1$(STAGING_TARGET_DIR)/usr/lib,g" $$$$fn; \
  187. done
  188. ifeq (,$(filter noscripts,$(7)))
  189. @cd '$${STAGING_TARGET_DIR}'; grep 'usr/s*bin/' \
  190. '$${STAGING_PKG_DIR}/$(1)' | \
  191. while read fn; do \
  192. b="$$$$(dd if="$$$$fn" bs=2 count=1 2>/dev/null)"; \
  193. [[ $$$$b = '#!' ]] || continue; \
  194. cp "$$$$fn" scripts/; \
  195. echo "scripts/$$$$(basename "$$$$fn")" \
  196. >>'$${STAGING_PKG_DIR}/$(1)'; \
  197. done
  198. endif
  199. ifeq (,$(filter libmix,$(7)))
  200. ifeq (,$(filter libonly,$(7)))
  201. $${PKG_BUILD} $${IDIR_$(1)} $${PACKAGE_DIR} $(MAKE_TRACE)
  202. endif
  203. endif
  204. clean-targets: clean-dev-$(1)
  205. clean-dev-$(1):
  206. ifeq (,$(filter noremove,$(7)))
  207. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  208. cd '$${STAGING_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. $$(INFO_$(1)): $$(IPKG_$(1))
  216. $(PKG_INSTALL) $$(IPKG_$(1))
  217. endef
  218. install-targets:
  219. install:
  220. @$(CMD_TRACE) "installing... "
  221. @$(MAKE) install-targets $(MAKE_TRACE)
  222. clean-targets:
  223. clean:
  224. @$(CMD_TRACE) "cleaning... "
  225. @$(MAKE) clean-targets $(MAKE_TRACE)
  226. rm -rf ${WRKDIR} ${ALL_IPKGS} ${PACKAGE_DIR}/.stamps/${PKG_NAME}*
  227. distclean: clean
  228. rm -f ${FULLDISTFILES}
  229. .PHONY: all refetch extract patch configure \
  230. build rebuild fake package install clean build-all-pkgs