package.mk 9.0 KB

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