package.mk 8.4 KB

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