rootfs.mk 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ifdef CONFIG_USE_MKLIBS
  2. define mklibs
  3. rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
  4. # first find all programs and add them to the mklibs list
  5. find $(STAGING_DIR_ROOT) -type f -perm /100 -exec \
  6. file -r -N -F '' {} + | \
  7. awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
  8. # find all loadable objects that are not regular libraries and add them to the list as well
  9. find $(STAGING_DIR_ROOT) -type f -name \*.so\* -exec \
  10. file -r -N -F '' {} + | \
  11. awk ' /shared object/ { print $$1 }' > $(TMP_DIR)/mklibs-libs
  12. mkdir -p $(TMP_DIR)/mklibs-out
  13. $(STAGING_DIR_HOST)/bin/mklibs -D \
  14. -d $(TMP_DIR)/mklibs-out \
  15. --sysroot $(STAGING_DIR_ROOT) \
  16. `cat $(TMP_DIR)/mklibs-libs | sed 's:/*[^/]\+/*$$::' | uniq | sed 's:^$(STAGING_DIR_ROOT):-L :'` \
  17. --ldlib $(patsubst $(STAGING_DIR_ROOT)/%,/%,$(firstword $(wildcard \
  18. $(foreach name,ld-uClibc.so.* ld-linux.so.* ld-*.so ld-musl-*.so.*, \
  19. $(STAGING_DIR_ROOT)/lib/$(name) \
  20. )))) \
  21. --target $(REAL_GNU_TARGET_NAME) \
  22. `cat $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-libs` 2>&1
  23. $(RSTRIP) $(TMP_DIR)/mklibs-out
  24. for lib in `ls $(TMP_DIR)/mklibs-out/*.so.* 2>/dev/null`; do \
  25. LIB="$${lib##*/}"; \
  26. DEST="`ls "$(1)/lib/$$LIB" "$(1)/usr/lib/$$LIB" 2>/dev/null`"; \
  27. [ -n "$$DEST" ] || continue; \
  28. echo "Copying stripped library $$lib to $$DEST"; \
  29. cp "$$lib" "$$DEST" || exit 1; \
  30. done
  31. endef
  32. endif
  33. # where to build (and put) .ipk packages
  34. opkg = \
  35. IPKG_NO_SCRIPT=1 \
  36. IPKG_INSTROOT=$(1) \
  37. TMPDIR=$(1)/tmp \
  38. $(STAGING_DIR_HOST)/bin/opkg \
  39. --offline-root $(1) \
  40. --force-postinstall \
  41. --add-dest root:/ \
  42. --add-arch all:100 \
  43. --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
  44. TARGET_DIR_ORIG := $(TARGET_ROOTFS_DIR)/root.orig-$(BOARD)
  45. ifdef CONFIG_CLEAN_IPKG
  46. define clean_ipkg
  47. -find $(1)/usr/lib/opkg/info -type f -and -not -name '*.control' | $(XARGS) rm -rf
  48. -sed -i -ne '/^Require-User: /p' $(1)/usr/lib/opkg/info/*.control
  49. awk ' \
  50. BEGIN { conffiles = 0; print "Conffiles:" } \
  51. /^Conffiles:/ { conffiles = 1; next } \
  52. !/^ / { conffiles = 0; next } \
  53. conffiles == 1 { print } \
  54. ' $(1)/usr/lib/opkg/status >$(1)/usr/lib/opkg/status.new
  55. mv $(1)/usr/lib/opkg/status.new $(1)/usr/lib/opkg/status
  56. -find $(1)/usr/lib/opkg -empty | $(XARGS) rm -rf
  57. endef
  58. endif
  59. define prepare_rootfs
  60. $(if $(2),@if [ -d '$(2)' ]; then \
  61. $(call file_copy,$(2)/.,$(1)); \
  62. fi)
  63. @mkdir -p $(1)/etc/rc.d
  64. @mkdir -p $(1)/var/lock
  65. @( \
  66. cd $(1); \
  67. for script in ./usr/lib/opkg/info/*.postinst; do \
  68. IPKG_INSTROOT=$(1) $$(which bash) $$script; \
  69. ret=$$?; \
  70. if [ $$ret -ne 0 ]; then \
  71. echo "postinst script $$script has failed with exit code $$ret" >&2; \
  72. exit 1; \
  73. fi; \
  74. done; \
  75. for script in ./etc/init.d/*; do \
  76. grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
  77. if ! echo " $(3) " | grep -q " $$(basename $$script) "; then \
  78. IPKG_INSTROOT=$(1) $$(which bash) ./etc/rc.common $$script enable; \
  79. echo "Enabling" $$(basename $$script); \
  80. else \
  81. IPKG_INSTROOT=$(1) $$(which bash) ./etc/rc.common $$script disable; \
  82. echo "Disabling" $$(basename $$script); \
  83. fi; \
  84. done || true \
  85. )
  86. $(if $(SOURCE_DATE_EPOCH),sed -i "s/Installed-Time: .*/Installed-Time: $(SOURCE_DATE_EPOCH)/" $(1)/usr/lib/opkg/status)
  87. @-find $(1) -name CVS | $(XARGS) rm -rf
  88. @-find $(1) -name .svn | $(XARGS) rm -rf
  89. @-find $(1) -name .git | $(XARGS) rm -rf
  90. @-find $(1) -name '.#*' | $(XARGS) rm -f
  91. rm -rf $(1)/tmp/*
  92. rm -f $(1)/usr/lib/opkg/lists/*
  93. rm -f $(1)/usr/lib/opkg/info/*.postinst*
  94. rm -f $(1)/var/lock/*.lock
  95. rm -rf $(1)/boot
  96. $(call clean_ipkg,$(1))
  97. $(call mklibs,$(1))
  98. endef