1
0

package.mk 8.9 KB

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