include/rootfs.mk: retain list of conffiles with CONFIG_CLEAN_IPKG
[oweals/openwrt.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/info -type f -and -not -name '*.control' | $(XARGS) rm -rf
53         -sed -i -ne '/^Require-User: /p' $(1)/usr/lib/opkg/info/*.control
54         awk ' \
55                 BEGIN { conffiles = 0; print "Conffiles:" } \
56                 /^Conffiles:/ { conffiles = 1; next } \
57                 !/^ / { conffiles = 0; next } \
58                 conffiles == 1 { print } \
59         ' $(1)/usr/lib/opkg/status >$(1)/usr/lib/opkg/status.new
60         mv $(1)/usr/lib/opkg/status.new $(1)/usr/lib/opkg/status
61         -find $(1)/usr/lib/opkg -empty | $(XARGS) rm -rf
62   endef
63 endif
64
65 define prepare_rootfs
66         @if [ -d $(TOPDIR)/files ]; then \
67                 $(call file_copy,$(TOPDIR)/files/.,$(1)); \
68         fi
69         @mkdir -p $(1)/etc/rc.d
70         @mkdir -p $(1)/var/lock
71         @( \
72                 cd $(1); \
73                 for script in ./usr/lib/opkg/info/*.postinst; do \
74                         IPKG_INSTROOT=$(1) $$(which bash) $$script; \
75                         ret=$$?; \
76                         if [ $$ret -ne 0 ]; then \
77                                 echo "postinst script $$script has failed with exit code $$ret" >&2; \
78                                 exit 1; \
79                         fi; \
80                 done; \
81                 for script in ./etc/init.d/*; do \
82                         grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
83                         IPKG_INSTROOT=$(1) $$(which bash) ./etc/rc.common $$script enable; \
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         $(call clean_ipkg,$(1))
96         $(call mklibs,$(1))
97 endef