cae2bfe2ba07a73683050e3c72ae07a21d23db37
[openwrt/staging/aparcar.git] / include / rootfs.mk
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
34 apk = \
35 IPKG_INSTROOT=$(1) \
36 $(FAKEROOT) $(STAGING_DIR_HOST)/bin/apk \
37 --root $(1) \
38 --keys-dir $(TOPDIR) \
39 --no-cache \
40 --no-logfile \
41 --no-scripts \
42 --preserve-env \
43 --repository file://$(PACKAGE_DIR_ALL)/packages.adb
44
45 TARGET_DIR_ORIG := $(TARGET_ROOTFS_DIR)/root.orig-$(BOARD)
46
47 ifdef CONFIG_CLEAN_IPKG
48 define clean_ipkg
49 -find $(1)/usr/lib/opkg/info -type f -and -not -name '*.control' -delete
50 -sed -i -ne '/^Require-User: /p' $(1)/usr/lib/opkg/info/*.control
51 awk ' \
52 BEGIN { conffiles = 0; print "Conffiles:" } \
53 /^Conffiles:/ { conffiles = 1; next } \
54 !/^ / { conffiles = 0; next } \
55 conffiles == 1 { print } \
56 ' $(1)/usr/lib/opkg/status >$(1)/usr/lib/opkg/status.new
57 mv $(1)/usr/lib/opkg/status.new $(1)/usr/lib/opkg/status
58 -find $(1)/usr/lib/opkg -empty -delete
59 endef
60 endif
61
62 define prepare_rootfs
63 $(if $(2),@if [ -d '$(2)' ]; then \
64 $(call file_copy,$(2)/.,$(1)); \
65 fi)
66 @mkdir -p $(1)/etc/rc.d
67 @mkdir -p $(1)/var/lock
68 @( \
69 cd $(1); \
70 $(STAGING_DIR_HOST)/bin/tar -xf ./lib/apk/db/scripts.tar --wildcards "*.post-install" -O > script.sh; \
71 chmod +x script.sh; \
72 IPKG_INSTROOT=$(1) $$(command -v bash) script.sh; \
73 for script in ./etc/init.d/*; do \
74 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
75 if ! echo " $(3) " | grep -q " $$(basename $$script) "; then \
76 IPKG_INSTROOT=$(1) $$(command -v bash) ./etc/rc.common $$script enable; \
77 echo "Enabling" $$(basename $$script); \
78 else \
79 IPKG_INSTROOT=$(1) $$(command -v bash) ./etc/rc.common $$script disable; \
80 echo "Disabling" $$(basename $$script); \
81 fi; \
82 done || true \
83 )
84 @-find $(1) -name CVS -o -name .svn -o -name .git -o -name '.#*' | $(XARGS) rm -rf
85 @-find $(1)/usr/cache/apk/ -name '*.apk' -delete
86 rm -rf \
87 $(1)/boot \
88 $(1)/tmp/* \
89 $(1)/var/lock/*.lock
90 $(call clean_ipkg,$(1))
91 $(call mklibs,$(1))
92 $(if $(SOURCE_DATE_EPOCH),find $(1)/ -mindepth 1 -execdir touch -hcd "@$(SOURCE_DATE_EPOCH)" "{}" +)
93 endef