package.mk 8.8 KB

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