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