build: rework the package/install step - collect package install lists during package...
[openwrt/openwrt.git] / package / Makefile
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
8 curdir:=package
9
10 -include $(TMP_DIR)/.packagedeps
11 $(curdir)/builddirs:=$(sort $(package-) $(package-y) $(package-m))
12 $(curdir)/builddirs-install:=.
13 ifeq ($(SDK),1)
14 else
15 $(curdir)/builddirs-default:=. $(sort $(package-y) $(package-m))
16 $(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m))
17 endif
18 ifneq ($(IGNORE_ERRORS),)
19 $(curdir)/builddirs-ignore-compile:= $(if $(filter n m y, $(IGNORE_ERRORS)),$(foreach m,$(IGNORE_ERRORS),$(package-$(subst n,,$(m)))),$(package-m) $(package-))
20 endif
21
22 ifdef CONFIG_USE_MKLIBS
23 define mklibs
24 rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
25 # first find all programs and add them to the mklibs list
26 find $(STAGING_DIR_ROOT) -type f -perm +100 -exec \
27 file -r -N -F '' {} + | \
28 awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
29 # find all loadable objects that are not regular libraries and add them to the list as well
30 find $(STAGING_DIR_ROOT) -type f -name \*.so\* -exec \
31 file -r -N -F '' {} + | \
32 awk ' /shared object/ { print $$1 }' >> $(TMP_DIR)/mklibs-progs
33 mkdir -p $(TMP_DIR)/mklibs-out
34 $(STAGING_DIR_HOST)/bin/mklibs -D \
35 -d $(TMP_DIR)/mklibs-out \
36 --sysroot $(STAGING_DIR_ROOT) \
37 -L /lib \
38 -L /usr/lib \
39 -L /usr/lib/ebtables \
40 --ldlib $(patsubst $(STAGING_DIR_ROOT)/%,/%,$(firstword $(wildcard \
41 $(foreach name,ld-uClibc.so.* ld-linux.so.* ld-*.so, \
42 $(STAGING_DIR_ROOT)/lib/$(name) \
43 )))) \
44 --target $(REAL_GNU_TARGET_NAME) \
45 `cat $(TMP_DIR)/mklibs-progs` 2>&1
46 $(RSTRIP) $(TMP_DIR)/mklibs-out
47 for lib in `ls $(TMP_DIR)/mklibs-out/*.so.* 2>/dev/null`; do \
48 LIB="$${lib##*/}"; \
49 DEST="`ls "$(TARGET_DIR)/lib/$$LIB" "$(TARGET_DIR)/usr/lib/$$LIB" 2>/dev/null`"; \
50 [ -n "$$DEST" ] || continue; \
51 echo "Copying stripped library $$lib to $$DEST"; \
52 cp "$$lib" "$$DEST" || exit 1; \
53 done
54 endef
55 endif
56
57 # where to build (and put) .ipk packages
58 OPKG:= \
59 IPKG_TMP=$(TMP_DIR)/ipkg \
60 IPKG_INSTROOT=$(TARGET_DIR) \
61 IPKG_CONF_DIR=$(STAGING_DIR)/etc \
62 IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
63 $(STAGING_DIR_HOST)/bin/opkg \
64 --offline-root $(TARGET_DIR) \
65 --force-depends \
66 --force-overwrite \
67 --force-postinstall \
68 --force-maintainer \
69 --add-dest root:/ \
70 --add-arch all:100 \
71 --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
72
73 PACKAGE_INSTALL:=$(sort $(foreach pkg,$(package-y),$(lastword $(subst /,$(space),$(pkg)))))
74 PACKAGE_INSTALL_FILES:=$(patsubst %,$(PKG_INFO_DIR)/%.install,$(PACKAGE_INSTALL))
75
76 $(curdir)/install: $(TMP_DIR)/.build
77 - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
78 rm -rf $(TARGET_DIR) $(STAGING_DIR_ROOT)
79 [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
80 $(OPKG) install `cat $(PACKAGE_INSTALL_FILES) | sed -e 's,^\(.*\)$$,$(PACKAGE_DIR)/\1_*.ipk,'`
81 @for pkg in $(PACKAGE_INSTALL); do \
82 [ -s $(PKG_INFO_DIR)/$${pkg}.install.flags ] || continue; \
83 for flag in `cat $(PKG_INFO_DIR)/$${pkg}.install.flags`; do \
84 $(OPKG) flag $$flag `cat $(PKG_INFO_DIR)/$${pkg}.install`; \
85 done; \
86 done || true
87 @-$(MAKE) package/preconfig
88 @if [ -d $(TOPDIR)/files ]; then \
89 ( cd $(TOPDIR)/files; find -type f ) | \
90 ( cd $(TARGET_DIR); while :; do \
91 read FILE; \
92 [ -z "$$FILE" ] && break; \
93 [ -L "$$FILE" ] || continue; \
94 echo "Removing symlink $(TARGET_DIR)/$$FILE"; \
95 rm -f "$$FILE"; \
96 done; ); \
97 $(CP) $(TOPDIR)/files/. $(TARGET_DIR); \
98 fi
99 @mkdir -p $(TARGET_DIR)/etc/rc.d
100 @( \
101 cd $(TARGET_DIR); \
102 for script in ./etc/init.d/*; do \
103 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
104 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) ./etc/rc.common $$script enable; \
105 done || true \
106 )
107 @-find $(TARGET_DIR) -name CVS | $(XARGS) rm -rf
108 @-find $(TARGET_DIR) -name .svn | $(XARGS) rm -rf
109 @-find $(TARGET_DIR) -name '.#*' | $(XARGS) rm -f
110 rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
111 $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
112 $(call mklibs)
113
114 $(curdir)/index: FORCE
115 @(cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
116 gzip -9c Packages > Packages.gz \
117 )
118
119 $(curdir)/preconfig:
120
121 $(curdir)/flags-install:= -j1
122
123 $(eval $(call stampfile,$(curdir),package,prereq,.config))
124 $(eval $(call stampfile,$(curdir),package,compile,$(TMP_DIR)/.build))
125 $(eval $(call stampfile,$(curdir),package,install,$(TMP_DIR)/.build))
126
127 $(eval $(call subdir,$(curdir)))