pkg-bottom.mk 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. # Comments:
  4. # * pre/do/post-foo are always defined here, but empty. This is so
  5. # that we can call it (BSD make has .if target(foo) but GNU not)
  6. # and it won't error out.
  7. # * ${_foo_COOKIE} are the actual targets
  8. # * default is "auto"
  9. # * define "manual" if you need your own method
  10. # -> define a do-foo: target in the Makefile
  11. # * if you have a style -> define a pre-foo: and post-foo: if they
  12. # are required, but the do-foo: magic is done here
  13. REORDER_DEPENDENCIES= ${TOPDIR}/scripts/automake.dep
  14. PKG_LIBNAME?= $(PKG_NAME)
  15. pre-configure:
  16. do-configure:
  17. post-configure:
  18. ${_CONFIGURE_COOKIE}: ${_HOST_COOKIE} ${_PATCH_COOKIE}
  19. @sed -e '/^#/d' ${REORDER_DEPENDENCIES} | \
  20. tsort | while read f; do \
  21. cd ${WRKSRC}; \
  22. case $$f in \
  23. /*) \
  24. find . -name "$${f#/}" -print | while read i; do \
  25. touch "$$i"; \
  26. done;; \
  27. *) \
  28. if test -e "$$f" ; then \
  29. touch "$$f"; \
  30. fi;; \
  31. esac; \
  32. done
  33. mkdir -p ${WRKBUILD}
  34. @${MAKE} pre-configure $(MAKE_TRACE)
  35. ifneq ($(filter manual,${CONFIG_STYLE}),)
  36. env ${CONFIGURE_ENV} ${MAKE} do-configure $(MAKE_TRACE)
  37. else ifneq ($(filter minimal,${CONFIG_STYLE}),)
  38. @$(CMD_TRACE) "configuring... "
  39. @cd ${WRKBUILD}; \
  40. for i in $$(find . -name config.sub);do \
  41. if [ -f $$i ]; then \
  42. ${CP} $$i $$i.bak; \
  43. ${CP} ${SCRIPT_DIR}/config.sub $$i; \
  44. fi; \
  45. done; \
  46. for i in $$(find . -name config.guess);do \
  47. if [ -f $$i ]; then \
  48. ${CP} $$i $$i.bak; \
  49. ${CP} ${SCRIPT_DIR}/config.guess $$i; \
  50. fi; \
  51. done;
  52. cd ${WRKBUILD}; rm -f config.{cache,status}; \
  53. env ${CONFIGURE_ENV} \
  54. ${BASH} ${WRKSRC}/${CONFIGURE_PROG} \
  55. ${CONFIGURE_ARGS} $(MAKE_TRACE)
  56. else ifeq ($(strip ${CONFIG_STYLE}),)
  57. @$(CMD_TRACE) "configuring... "
  58. @cd ${WRKBUILD}; \
  59. for i in $$(find . -name config.sub);do \
  60. if [ -f $$i ]; then \
  61. ${CP} $$i $$i.bak; \
  62. ${CP} ${SCRIPT_DIR}/config.sub $$i; \
  63. fi; \
  64. done; \
  65. for i in $$(find . -name config.guess);do \
  66. if [ -f $$i ]; then \
  67. ${CP} $$i $$i.bak; \
  68. ${CP} ${SCRIPT_DIR}/config.guess $$i; \
  69. fi; \
  70. done;
  71. cd ${WRKBUILD}; rm -f config.{cache,status}; \
  72. env ${CONFIGURE_ENV} \
  73. ${BASH} ${WRKSRC}/${CONFIGURE_PROG} ${CONFIGURE_TRIPLE} \
  74. --program-prefix= \
  75. --program-suffix= \
  76. --prefix=/usr \
  77. --bindir=/usr/bin \
  78. --datadir=/usr/share \
  79. --mandir=/usr/share/man \
  80. --libexecdir=/usr/libexec \
  81. --localstatedir=/var \
  82. --sysconfdir=/etc \
  83. --enable-shared \
  84. --enable-static \
  85. --disable-dependency-tracking \
  86. --disable-libtool-lock \
  87. --disable-nls \
  88. ${CONFIGURE_ARGS} $(MAKE_TRACE)
  89. else
  90. @echo "Invalid CONFIG_STYLE '${CONFIG_STYLE}'" >&2
  91. @exit 1
  92. endif
  93. @${MAKE} post-configure $(MAKE_TRACE)
  94. touch $@
  95. # do a parallel build if requested && package doesn't force disable it
  96. ifeq (${ADK_MAKE_PARALLEL},y)
  97. ifeq ($(strip ${PKG_NOPARALLEL}),)
  98. MAKE_FLAGS+= -j${ADK_MAKE_JOBS}
  99. endif
  100. endif
  101. pre-build:
  102. do-build:
  103. post-build:
  104. ${_BUILD_COOKIE}: ${_CONFIGURE_COOKIE}
  105. @env ${MAKE_ENV} ${MAKE} pre-build $(MAKE_TRACE)
  106. @$(CMD_TRACE) "compiling... "
  107. ifneq ($(filter manual,${BUILD_STYLE}),)
  108. env ${MAKE_ENV} ${MAKE} do-build $(MAKE_TRACE)
  109. else ifeq ($(strip ${BUILD_STYLE}),)
  110. cd ${WRKBUILD} && env ${MAKE_ENV} ${MAKE} -f ${MAKE_FILE} \
  111. ${MAKE_FLAGS} ${ALL_TARGET} $(MAKE_TRACE)
  112. else
  113. @echo "Invalid BUILD_STYLE '${BUILD_STYLE}'" >&2
  114. @exit 1
  115. endif
  116. @env ${MAKE_ENV} ${MAKE} post-build $(MAKE_TRACE)
  117. touch $@
  118. pre-install:
  119. do-install:
  120. post-install:
  121. spkg-install: ${ALL_POSTINST}
  122. ${_FAKE_COOKIE}: ${_BUILD_COOKIE}
  123. -rm -f ${_ALL_CONTROLS}
  124. @mkdir -p '${STAGING_PKG_DIR}' ${WRKINST} '${STAGING_DIR}/scripts'
  125. @${MAKE} ${_ALL_CONTROLS} $(MAKE_TRACE)
  126. @env ${MAKE_ENV} ${MAKE} pre-install $(MAKE_TRACE)
  127. ifneq ($(filter manual,${INSTALL_STYLE}),)
  128. env ${MAKE_ENV} ${MAKE} do-install $(MAKE_TRACE)
  129. else ifeq ($(strip ${INSTALL_STYLE}),)
  130. cd ${WRKBUILD} && env ${MAKE_ENV} ${MAKE} -f ${MAKE_FILE} \
  131. DESTDIR='${WRKINST}' ${FAKE_FLAGS} ${INSTALL_TARGET} $(MAKE_TRACE)
  132. ifeq (,$(filter libonly,${PKG_OPTS}))
  133. env ${MAKE_ENV} ${MAKE} post-install $(MAKE_TRACE)
  134. endif
  135. else
  136. @echo "Invalid INSTALL_STYLE '${INSTALL_STYLE}'" >&2
  137. @exit 1
  138. endif
  139. env ${MAKE_ENV} ${MAKE} spkg-install $(MAKE_TRACE)
  140. @rm -f '${STAGING_PKG_DIR}/${PKG_NAME}.scripts'
  141. @for a in ${WRKINST}/usr/bin/*-config*; do \
  142. [[ -e $$a ]] || continue; \
  143. sed -e "s,^prefix=.*,prefix=${STAGING_TARGET_DIR}/usr," $$a > \
  144. ${STAGING_DIR}/usr/bin/$$(basename $$a); \
  145. chmod u+x ${STAGING_DIR}/usr/bin/$$(basename $$a); \
  146. [[ "$$(basename $$a)" != "pkg-config" ]] && cp ${STAGING_DIR}/usr/bin/$$(basename $$a) ${STAGING_DIR}/scripts; \
  147. echo "scripts/$$(basename $$a)" \
  148. >>'${STAGING_PKG_DIR}/${PKG_NAME}.scripts'; \
  149. done
  150. @for a in ${WRKINST}/usr/lib/pkgconfig/*.pc; do \
  151. [[ -e $$a ]] || continue; \
  152. sed -e "s,^prefix=.*,prefix=${STAGING_TARGET_DIR}/usr," $$a > \
  153. ${STAGING_DIR}/usr/lib/pkgconfig/$$(basename $$a); \
  154. done
  155. ifeq (,$(filter noremove,${PKG_OPTS}))
  156. @if test -s '${STAGING_PKG_DIR}/${PKG_NAME}'; then \
  157. cd '${STAGING_DIR}'; \
  158. while read fn; do \
  159. rm -f "$$fn"; \
  160. done <'${STAGING_PKG_DIR}/${PKG_NAME}'; \
  161. fi
  162. endif
  163. @rm -f '${STAGING_PKG_DIR}/${PKG_NAME}'
  164. ifneq (,$(filter dev,${PKG_OPTS}))
  165. @mkdir -p $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/include
  166. @test -d ${WRKINST}/usr/include && cd ${WRKINST}/usr/include; \
  167. find . -name \*.h | \
  168. $(TOOLS_DIR)/cpio -padlmu $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/include
  169. @mkdir -p $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/lib/pkgconfig
  170. @test -d ${WRKINST}/usr/lib/pkgconfig && cd ${WRKINST}/usr/lib/pkgconfig; \
  171. find . -name \*.pc | \
  172. $(TOOLS_DIR)/cpio -padlmu $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/lib/pkgconfig
  173. @for a in ${WRKINST}/usr/bin/*-config*; do \
  174. [[ -e $$a ]] || continue; \
  175. mkdir -p $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/bin; \
  176. cp $$a $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/bin; \
  177. chmod 755 $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/bin/$$(basename $$a); \
  178. done
  179. endif
  180. @-cd ${WRKINST}; \
  181. if [ "${PKG_NAME}" != "uClibc" -a "${PKG_NAME}" != "eglibc" -a "${PKG_NAME}" != "glibc" -a "${PKG_NAME}" != "libpthread" -a "${PKG_NAME}" != "libstdcxx" -a "${PKG_NAME}" != "libgcc" -a "${PKG_NAME}" != "libthread-db" -a "${PKG_NAME}" != "musl" ];then \
  182. find lib \( -name lib\*.so\* -o -name lib\*.a \) \
  183. -exec echo 'WARNING: ${PKG_NAME} installs files in /lib -' \
  184. ' fix this!' >&2 \; -quit 2>/dev/null; fi;\
  185. find usr ! -type d 2>/dev/null | \
  186. grep -E -v -e '^usr/lib/pkgconfig' -e '^usr/share' -e '^usr/src' -e '^usr/doc' -e '^usr/local' -e '^usr/man' -e '^usr/info' -e '^usr/lib/libc.so' -e '^usr/bin/[a-z0-9-]+-config*' -e '^/usr/lib/libpthread_nonshared.a' | \
  187. tee '${STAGING_PKG_DIR}/${PKG_NAME}' | \
  188. $(TOOLS_DIR)/cpio -padlmu '${STAGING_DIR}'
  189. @cd '${STAGING_DIR}'; grep 'usr/lib/.*\.la$$' \
  190. '${STAGING_PKG_DIR}/${PKG_NAME}' | while read fn; do \
  191. chmod u+w $$fn; \
  192. $(SED) "s,\(^libdir='\| \|-L\|^dependency_libs='\)/usr/lib,\1$(STAGING_TARGET_DIR)/usr/lib,g" $$fn; \
  193. done
  194. ifeq (,$(filter noscripts,${PKG_OPTS}))
  195. @cd '${STAGING_DIR}'; grep 'usr/s*bin/' \
  196. '${STAGING_PKG_DIR}/${PKG_NAME}' | \
  197. while read fn; do \
  198. b="$$(dd if="$$fn" bs=2 count=1 2>/dev/null)"; \
  199. [[ $$b = '#!' ]] || continue; \
  200. cp "$$fn" scripts/; \
  201. echo "scripts/$$(basename "$$fn")" \
  202. >>'${STAGING_PKG_DIR}/${PKG_NAME}'; \
  203. done
  204. endif
  205. -@test -e '${STAGING_PKG_DIR}/${PKG_NAME}.scripts' && \
  206. cat '${STAGING_PKG_DIR}/${PKG_NAME}.scripts' >> '${STAGING_PKG_DIR}/${PKG_NAME}' || echo
  207. touch $@
  208. ${_IPKGS_COOKIE}:
  209. @clean=0; \
  210. for f in ${ALL_IPKGS}; do \
  211. [[ -e $$f ]] && clean=1; \
  212. done; \
  213. [[ $$clean = 0 ]] || ${MAKE} clean
  214. exec ${MAKE} package
  215. package: ${ALL_IPKGS}
  216. @cd ${WRKDIR}/fake-${CPU_ARCH} || exit 1; \
  217. y=; sp=; for x in ${ALL_IDIRS}; do \
  218. y="$$y$$sp$${x#$(WRKDIR)/fake-${CPU_ARCH}/}"; \
  219. sp=' '; \
  220. done; ls=; ln=; x=1; [[ -z $$y ]] || \
  221. md5sum $$(find $$y -type f) | sed -e "s/*//" | \
  222. while read sum name; do \
  223. inode=$$(ls -i "$$name"); \
  224. echo "$$sum $${inode%% *} $$name"; \
  225. done | sort | while read sum inode name; do \
  226. if [[ $$sum = $$ls ]]; then \
  227. [[ $$li = $$inode ]] && continue; \
  228. case $$x in \
  229. 1) echo 'WARNING: duplicate files found in' \
  230. 'package "${PKG_NAME}"! Fix them.' >&2; \
  231. echo -n "> $$ln "; \
  232. ;; \
  233. 2) echo -n "> $$ln "; \
  234. ;; \
  235. 3) echo -n ' '; \
  236. ;; \
  237. esac; \
  238. echo -n "$$name"; \
  239. x=3; \
  240. else \
  241. case $$x in \
  242. 3) echo; \
  243. x=2; \
  244. ;; \
  245. esac; \
  246. fi; \
  247. ls=$$sum; \
  248. ln=$$name; \
  249. li=$$inode; \
  250. done
  251. touch ${_IPKGS_COOKIE}
  252. clean-targets: clean-dev-generic
  253. clean-dev-generic:
  254. ifeq (,$(filter noremove,${PKG_OPTS}))
  255. @if test -s '${STAGING_PKG_DIR}/${PKG_NAME}'; then \
  256. cd '${STAGING_DIR}'; \
  257. while read fn; do \
  258. rm -f "$$fn"; \
  259. done <'${STAGING_PKG_DIR}/${PKG_NAME}'; \
  260. fi
  261. endif
  262. @rm -f '${STAGING_PKG_DIR}/${PKG_NAME}'