image: fix CONFIG_CLEAN_IPKG with CONFIG_TARGET_PER_DEVICE_ROOTFS
[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 $(INCLUDE_DIR)/rootfs.mk
11
12 -include $(TMP_DIR)/.packagedeps
13 $(curdir)/builddirs:=$(sort $(package-) $(package-y) $(package-m))
14 $(curdir)/builddirs-install:=.
15 $(curdir)/builddirs-default:=. $(sort $(package-y) $(package-m))
16 $(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m))
17 ifneq ($(IGNORE_ERRORS),)
18 package-y-filter := $(package-y)
19 package-m-filter := $(filter-out $(package-y),$(package-m))
20 package-n-filter := $(filter-out $(package-y) $(package-m),$(package-))
21 package-ignore-errors := $(filter n m y,$(IGNORE_ERRORS))
22 package-ignore-errors := $(if $(package-ignore-errors),$(package-ignore-errors),n m)
23 package-ignore-subdirs := $(sort $(foreach m,$(package-ignore-errors),$(package-$(m)-filter)))
24 $(curdir)/builddirs-ignore-download := $(package-ignore-subdirs)
25 $(curdir)/builddirs-ignore-compile := $(package-ignore-subdirs)
26 $(curdir)/builddirs-ignore-host-download := $(package-ignore-subdirs)
27 $(curdir)/builddirs-ignore-host-compile := $(package-ignore-subdirs)
28 endif
29
30 PACKAGE_INSTALL_FILES:= \
31 $(foreach pkg,$(sort $(package-y)), \
32 $(foreach variant, \
33 $(if $(strip $(package/$(pkg)/variants)), \
34 $(package/$(pkg)/variants), \
35 $(if $(package/$(pkg)/default-variant), \
36 $(package/$(pkg)/default-variant), \
37 default \
38 ) \
39 ), \
40 $(PKG_INFO_DIR)/$(lastword $(subst /,$(space),$(pkg))).$(variant).install \
41 ) \
42 )
43
44 $(curdir)/cleanup: $(TMP_DIR)/.build
45 rm -rf $(STAGING_DIR_ROOT)
46
47 $(curdir)/merge:
48 rm -rf $(PACKAGE_DIR_ALL)
49 mkdir -p $(PACKAGE_DIR_ALL)
50 -$(foreach pdir,$(PACKAGE_SUBDIRS),$(if $(wildcard $(pdir)/*.ipk),ln -s $(pdir)/*.ipk $(PACKAGE_DIR_ALL);))
51
52 $(curdir)/merge-index: $(curdir)/merge
53 (cd $(PACKAGE_DIR_ALL) && $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages; )
54
55 $(curdir)/install: $(TMP_DIR)/.build $(curdir)/system/opkg/host/install $(curdir)/merge $(if $(CONFIG_TARGET_PER_DEVICE_ROOTFS),$(curdir)/merge-index)
56 - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
57 rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
58 [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
59 $(call opkg,$(TARGET_DIR)) install \
60 $(call opkg_package_files,$(shell cat $(PACKAGE_INSTALL_FILES) 2>/dev/null))
61 @for file in $(PACKAGE_INSTALL_FILES); do \
62 [ -s $$file.flags ] || continue; \
63 for flag in `cat $$file.flags`; do \
64 $(call opkg,$(TARGET_DIR)) flag $$flag `cat $$file`; \
65 done; \
66 done || true
67 @-$(MAKE) package/preconfig
68
69 $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
70
71 $(call prepare_rootfs,$(TARGET_DIR))
72
73 PASSOPT=""
74 PASSARG=""
75 ifndef CONFIG_OPKGSMIME_PASSPHRASE
76 ifneq ($(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE)),)
77 PASSOPT="-passin"
78 PASSARG="file:$(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE))"
79 endif
80 endif
81
82 $(curdir)/index: FORCE
83 @echo Generating package index...
84 @for d in $(PACKAGE_SUBDIRS); do ( \
85 mkdir -p $$d; \
86 cd $$d || continue; \
87 $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
88 gzip -9nc Packages > Packages.gz; \
89 ); done
90 ifdef CONFIG_SIGNED_PACKAGES
91 @echo Signing package index...
92 @for d in $(PACKAGE_SUBDIRS); do ( \
93 [ -d $$d ] && \
94 cd $$d || continue; \
95 $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY); \
96 ); done
97 else
98 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_KEY)),)
99 @echo Signing key has not been configured
100 else
101 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_CERT)),)
102 @echo Certificate has not been configured
103 else
104 @echo Signing package index...
105 @for d in $(PACKAGE_SUBDIRS); do ( \
106 [ -d $$d ] && \
107 cd $$d || continue; \
108 openssl smime -binary -in Packages.gz \
109 -out Packages.sig -outform PEM -sign \
110 -signer $(CONFIG_OPKGSMIME_CERT) \
111 -inkey $(CONFIG_OPKGSMIME_KEY) \
112 $(PASSOPT) $(PASSARG); \
113 ); done
114 endif
115 endif
116 endif
117
118 $(curdir)/preconfig:
119
120 $(curdir)/flags-install:= -j1
121
122 $(eval $(call stampfile,$(curdir),package,prereq,.config))
123 $(eval $(call stampfile,$(curdir),package,cleanup,$(TMP_DIR)/.build))
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)))