Makefile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #
  2. # Copyright (C) 2006-2010 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. curdir:=package
  8. include $(INCLUDE_DIR)/feeds.mk
  9. -include $(TMP_DIR)/.packagedeps
  10. $(curdir)/builddirs:=$(sort $(package-) $(package-y) $(package-m))
  11. $(curdir)/builddirs-install:=.
  12. $(curdir)/builddirs-default:=. $(sort $(package-y) $(package-m))
  13. $(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m))
  14. ifneq ($(IGNORE_ERRORS),)
  15. package-y-filter := $(package-y)
  16. package-m-filter := $(filter-out $(package-y),$(package-m))
  17. package-n-filter := $(filter-out $(package-y) $(package-m),$(package-))
  18. package-ignore-errors := $(filter n m y,$(IGNORE_ERRORS))
  19. package-ignore-errors := $(if $(package-ignore-errors),$(package-ignore-errors),n m)
  20. package-ignore-subdirs := $(sort $(foreach m,$(package-ignore-errors),$(package-$(m)-filter)))
  21. $(curdir)/builddirs-ignore-download := $(package-ignore-subdirs)
  22. $(curdir)/builddirs-ignore-compile := $(package-ignore-subdirs)
  23. $(curdir)/builddirs-ignore-host-download := $(package-ignore-subdirs)
  24. $(curdir)/builddirs-ignore-host-compile := $(package-ignore-subdirs)
  25. endif
  26. ifdef CONFIG_USE_MKLIBS
  27. define mklibs
  28. rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
  29. # first find all programs and add them to the mklibs list
  30. find $(STAGING_DIR_ROOT) -type f -perm /100 -exec \
  31. file -r -N -F '' {} + | \
  32. awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
  33. # find all loadable objects that are not regular libraries and add them to the list as well
  34. find $(STAGING_DIR_ROOT) -type f -name \*.so\* -exec \
  35. file -r -N -F '' {} + | \
  36. awk ' /shared object/ { print $$1 }' > $(TMP_DIR)/mklibs-libs
  37. mkdir -p $(TMP_DIR)/mklibs-out
  38. $(STAGING_DIR_HOST)/bin/mklibs -D \
  39. -d $(TMP_DIR)/mklibs-out \
  40. --sysroot $(STAGING_DIR_ROOT) \
  41. `cat $(TMP_DIR)/mklibs-libs | sed 's:/*[^/]\+/*$$::' | uniq | sed 's:^$(STAGING_DIR_ROOT):-L :'` \
  42. --ldlib $(patsubst $(STAGING_DIR_ROOT)/%,/%,$(firstword $(wildcard \
  43. $(foreach name,ld-uClibc.so.* ld-linux.so.* ld-*.so ld-musl-*.so.*, \
  44. $(STAGING_DIR_ROOT)/lib/$(name) \
  45. )))) \
  46. --target $(REAL_GNU_TARGET_NAME) \
  47. `cat $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-libs` 2>&1
  48. $(RSTRIP) $(TMP_DIR)/mklibs-out
  49. for lib in `ls $(TMP_DIR)/mklibs-out/*.so.* 2>/dev/null`; do \
  50. LIB="$${lib##*/}"; \
  51. DEST="`ls "$(TARGET_DIR)/lib/$$LIB" "$(TARGET_DIR)/usr/lib/$$LIB" 2>/dev/null`"; \
  52. [ -n "$$DEST" ] || continue; \
  53. echo "Copying stripped library $$lib to $$DEST"; \
  54. cp "$$lib" "$$DEST" || exit 1; \
  55. done
  56. endef
  57. endif
  58. # where to build (and put) .ipk packages
  59. OPKG:= \
  60. IPKG_NO_SCRIPT=1 \
  61. IPKG_TMP=$(TMP_DIR)/ipkg \
  62. IPKG_INSTROOT=$(TARGET_DIR) \
  63. IPKG_CONF_DIR=$(STAGING_DIR)/etc \
  64. IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
  65. $(XARGS) $(STAGING_DIR_HOST)/bin/opkg \
  66. --offline-root $(TARGET_DIR) \
  67. --force-depends \
  68. --force-overwrite \
  69. --force-postinstall \
  70. --force-maintainer \
  71. --add-dest root:/ \
  72. --add-arch all:100 \
  73. --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
  74. PACKAGE_INSTALL_FILES:= \
  75. $(foreach pkg,$(sort $(package-y)), \
  76. $(foreach variant, \
  77. $(if $(strip $(package/$(pkg)/variants)), \
  78. $(package/$(pkg)/variants), \
  79. $(if $(package/$(pkg)/default-variant), \
  80. $(package/$(pkg)/default-variant), \
  81. default \
  82. ) \
  83. ), \
  84. $(PKG_INFO_DIR)/$(lastword $(subst /,$(space),$(pkg))).$(variant).install \
  85. ) \
  86. )
  87. $(curdir)/cleanup: $(TMP_DIR)/.build
  88. rm -rf $(STAGING_DIR_ROOT)
  89. $(curdir)/install: $(TMP_DIR)/.build $(curdir)/system/opkg/host/install
  90. - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
  91. rm -rf $(TARGET_DIR)
  92. [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
  93. @$(FIND) `sed -e 's|.*|$(PACKAGE_DIR)$(if $(CONFIG_PER_FEED_REPO),/*)/&_*.ipk|' $(PACKAGE_INSTALL_FILES)` | sort -u | $(OPKG) install
  94. @for file in $(PACKAGE_INSTALL_FILES); do \
  95. [ -s $$file.flags ] || continue; \
  96. for flag in `cat $$file.flags`; do \
  97. $(OPKG) flag $$flag < $$file; \
  98. done; \
  99. done || true
  100. @-$(MAKE) package/preconfig
  101. @if [ -d $(TOPDIR)/files ]; then \
  102. $(call file_copy,$(TOPDIR)/files/.,$(TARGET_DIR)); \
  103. fi
  104. @mkdir -p $(TARGET_DIR)/etc/rc.d
  105. @( \
  106. cd $(TARGET_DIR); \
  107. for script in ./usr/lib/opkg/info/*.postinst; do \
  108. IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
  109. done; \
  110. for script in ./etc/init.d/*; do \
  111. grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
  112. IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) ./etc/rc.common $$script enable; \
  113. done || true \
  114. )
  115. $(if $(SOURCE_DATE_EPOCH),sed -i "s/Installed-Time: .*/Installed-Time: $(SOURCE_DATE_EPOCH)/" $(TARGET_DIR)/usr/lib/opkg/status)
  116. @-find $(TARGET_DIR) -name CVS | $(XARGS) rm -rf
  117. @-find $(TARGET_DIR) -name .svn | $(XARGS) rm -rf
  118. @-find $(TARGET_DIR) -name .git | $(XARGS) rm -rf
  119. @-find $(TARGET_DIR) -name '.#*' | $(XARGS) rm -f
  120. rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst*
  121. rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.prerm*
  122. $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
  123. $(call mklibs)
  124. PASSOPT=""
  125. PASSARG=""
  126. ifndef CONFIG_OPKGSMIME_PASSPHRASE
  127. ifneq ($(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE)),)
  128. PASSOPT="-passin"
  129. PASSARG="file:$(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE))"
  130. endif
  131. endif
  132. PACKAGE_SUBDIRS=.
  133. ifneq ($(CONFIG_PER_FEED_REPO),)
  134. ifneq ($(CONFIG_PER_FEED_REPO_ADD_DISABLED),)
  135. PACKAGE_SUBDIRS=base kernel $(FEEDS_AVAILABLE)
  136. else
  137. PACKAGE_SUBDIRS=base kernel $(FEEDS_ENABLED)
  138. endif
  139. endif
  140. $(curdir)/index: FORCE
  141. @echo Generating package index...
  142. @for d in $(PACKAGE_SUBDIRS); do ( \
  143. mkdir -p $(PACKAGE_DIR)/$$d; \
  144. cd $(PACKAGE_DIR)/$$d || continue; \
  145. $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
  146. gzip -9nc Packages > Packages.gz; \
  147. ); done
  148. ifdef CONFIG_SIGNED_PACKAGES
  149. @echo Signing package index...
  150. @for d in $(PACKAGE_SUBDIRS); do ( \
  151. [ -d $(PACKAGE_DIR)/$$d ] && \
  152. cd $(PACKAGE_DIR)/$$d || continue; \
  153. $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY); \
  154. ); done
  155. else
  156. ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_KEY)),)
  157. @echo Signing key has not been configured
  158. else
  159. ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_CERT)),)
  160. @echo Certificate has not been configured
  161. else
  162. @echo Signing package index...
  163. @for d in $(PACKAGE_SUBDIRS); do ( \
  164. [ -d $(PACKAGE_DIR)/$$d ] && \
  165. cd $(PACKAGE_DIR)/$$d || continue; \
  166. openssl smime -binary -in Packages.gz \
  167. -out Packages.sig -outform PEM -sign \
  168. -signer $(CONFIG_OPKGSMIME_CERT) \
  169. -inkey $(CONFIG_OPKGSMIME_KEY) \
  170. $(PASSOPT) $(PASSARG); \
  171. ); done
  172. endif
  173. endif
  174. endif
  175. $(curdir)/preconfig:
  176. $(curdir)/flags-install:= -j1
  177. $(eval $(call stampfile,$(curdir),package,prereq,.config))
  178. $(eval $(call stampfile,$(curdir),package,cleanup,$(TMP_DIR)/.build))
  179. $(eval $(call stampfile,$(curdir),package,compile,$(TMP_DIR)/.build))
  180. $(eval $(call stampfile,$(curdir),package,install,$(TMP_DIR)/.build))
  181. $(eval $(call subdir,$(curdir)))