package.mk 8.1 KB

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