netifd: Send DHCP release when client exits
[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)/feeds.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 ifdef CONFIG_USE_MKLIBS
31 define mklibs
32 rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
33 # first find all programs and add them to the mklibs list
34 find $(STAGING_DIR_ROOT) -type f -perm /100 -exec \
35 file -r -N -F '' {} + | \
36 awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
37 # find all loadable objects that are not regular libraries and add them to the list as well
38 find $(STAGING_DIR_ROOT) -type f -name \*.so\* -exec \
39 file -r -N -F '' {} + | \
40 awk ' /shared object/ { print $$1 }' > $(TMP_DIR)/mklibs-libs
41 mkdir -p $(TMP_DIR)/mklibs-out
42 $(STAGING_DIR_HOST)/bin/mklibs -D \
43 -d $(TMP_DIR)/mklibs-out \
44 --sysroot $(STAGING_DIR_ROOT) \
45 `cat $(TMP_DIR)/mklibs-libs | sed 's:/*[^/]\+/*$$::' | uniq | sed 's:^$(STAGING_DIR_ROOT):-L :'` \
46 --ldlib $(patsubst $(STAGING_DIR_ROOT)/%,/%,$(firstword $(wildcard \
47 $(foreach name,ld-uClibc.so.* ld-linux.so.* ld-*.so ld-musl-*.so.*, \
48 $(STAGING_DIR_ROOT)/lib/$(name) \
49 )))) \
50 --target $(REAL_GNU_TARGET_NAME) \
51 `cat $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-libs` 2>&1
52 $(RSTRIP) $(TMP_DIR)/mklibs-out
53 for lib in `ls $(TMP_DIR)/mklibs-out/*.so.* 2>/dev/null`; do \
54 LIB="$${lib##*/}"; \
55 DEST="`ls "$(TARGET_DIR)/lib/$$LIB" "$(TARGET_DIR)/usr/lib/$$LIB" 2>/dev/null`"; \
56 [ -n "$$DEST" ] || continue; \
57 echo "Copying stripped library $$lib to $$DEST"; \
58 cp "$$lib" "$$DEST" || exit 1; \
59 done
60 endef
61 endif
62
63 # where to build (and put) .ipk packages
64 OPKG:= \
65 IPKG_NO_SCRIPT=1 \
66 IPKG_TMP=$(TMP_DIR)/ipkg \
67 IPKG_INSTROOT=$(TARGET_DIR) \
68 IPKG_CONF_DIR=$(STAGING_DIR)/etc \
69 IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
70 $(XARGS) $(STAGING_DIR_HOST)/bin/opkg \
71 --offline-root $(TARGET_DIR) \
72 --force-depends \
73 --force-overwrite \
74 --force-postinstall \
75 --force-maintainer \
76 --add-dest root:/ \
77 --add-arch all:100 \
78 --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
79
80 PACKAGE_INSTALL_FILES:= \
81 $(foreach pkg,$(sort $(package-y)), \
82 $(foreach variant, \
83 $(if $(strip $(package/$(pkg)/variants)), \
84 $(package/$(pkg)/variants), \
85 $(if $(package/$(pkg)/default-variant), \
86 $(package/$(pkg)/default-variant), \
87 default \
88 ) \
89 ), \
90 $(PKG_INFO_DIR)/$(lastword $(subst /,$(space),$(pkg))).$(variant).install \
91 ) \
92 )
93
94 $(curdir)/cleanup: $(TMP_DIR)/.build
95 rm -rf $(STAGING_DIR_ROOT)
96
97 $(curdir)/install: $(TMP_DIR)/.build $(curdir)/system/opkg/host/install
98 - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
99 rm -rf $(TARGET_DIR)
100 [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
101 @$(FIND) `sed -e 's|.*|$(PACKAGE_DIR)$(if $(CONFIG_PER_FEED_REPO),/*)/&_*.ipk|' $(PACKAGE_INSTALL_FILES)` | sort -u | $(OPKG) install
102 @for file in $(PACKAGE_INSTALL_FILES); do \
103 [ -s $$file.flags ] || continue; \
104 for flag in `cat $$file.flags`; do \
105 $(OPKG) flag $$flag < $$file; \
106 done; \
107 done || true
108 @-$(MAKE) package/preconfig
109 @if [ -d $(TOPDIR)/files ]; then \
110 $(call file_copy,$(TOPDIR)/files/.,$(TARGET_DIR)); \
111 fi
112 @mkdir -p $(TARGET_DIR)/etc/rc.d
113 @( \
114 cd $(TARGET_DIR); \
115 for script in ./usr/lib/opkg/info/*.postinst; do \
116 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
117 done; \
118 for script in ./etc/init.d/*; do \
119 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
120 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) ./etc/rc.common $$script enable; \
121 done || true \
122 )
123 $(if $(SOURCE_DATE_EPOCH),sed -i "s/Installed-Time: .*/Installed-Time: $(SOURCE_DATE_EPOCH)/" $(TARGET_DIR)/usr/lib/opkg/status)
124 @-find $(TARGET_DIR) -name CVS | $(XARGS) rm -rf
125 @-find $(TARGET_DIR) -name .svn | $(XARGS) rm -rf
126 @-find $(TARGET_DIR) -name .git | $(XARGS) rm -rf
127 @-find $(TARGET_DIR) -name '.#*' | $(XARGS) rm -f
128 rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst*
129 rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.prerm*
130 $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
131 $(call mklibs)
132
133 PASSOPT=""
134 PASSARG=""
135 ifndef CONFIG_OPKGSMIME_PASSPHRASE
136 ifneq ($(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE)),)
137 PASSOPT="-passin"
138 PASSARG="file:$(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE))"
139 endif
140 endif
141
142 PACKAGE_SUBDIRS=.
143 ifneq ($(CONFIG_PER_FEED_REPO),)
144 ifneq ($(CONFIG_PER_FEED_REPO_ADD_DISABLED),)
145 PACKAGE_SUBDIRS=base kernel $(FEEDS_AVAILABLE)
146 else
147 PACKAGE_SUBDIRS=base kernel $(FEEDS_ENABLED)
148 endif
149 endif
150
151 $(curdir)/index: FORCE
152 @echo Generating package index...
153 @for d in $(PACKAGE_SUBDIRS); do ( \
154 mkdir -p $(PACKAGE_DIR)/$$d; \
155 cd $(PACKAGE_DIR)/$$d || continue; \
156 $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
157 gzip -9nc Packages > Packages.gz; \
158 ); done
159 ifdef CONFIG_SIGNED_PACKAGES
160 @echo Signing package index...
161 @for d in $(PACKAGE_SUBDIRS); do ( \
162 [ -d $(PACKAGE_DIR)/$$d ] && \
163 cd $(PACKAGE_DIR)/$$d || continue; \
164 $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY); \
165 ); done
166 else
167 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_KEY)),)
168 @echo Signing key has not been configured
169 else
170 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_CERT)),)
171 @echo Certificate has not been configured
172 else
173 @echo Signing package index...
174 @for d in $(PACKAGE_SUBDIRS); do ( \
175 [ -d $(PACKAGE_DIR)/$$d ] && \
176 cd $(PACKAGE_DIR)/$$d || continue; \
177 openssl smime -binary -in Packages.gz \
178 -out Packages.sig -outform PEM -sign \
179 -signer $(CONFIG_OPKGSMIME_CERT) \
180 -inkey $(CONFIG_OPKGSMIME_KEY) \
181 $(PASSOPT) $(PASSARG); \
182 ); done
183 endif
184 endif
185 endif
186
187 $(curdir)/preconfig:
188
189 $(curdir)/flags-install:= -j1
190
191 $(eval $(call stampfile,$(curdir),package,prereq,.config))
192 $(eval $(call stampfile,$(curdir),package,cleanup,$(TMP_DIR)/.build))
193 $(eval $(call stampfile,$(curdir),package,compile,$(TMP_DIR)/.build))
194 $(eval $(call stampfile,$(curdir),package,install,$(TMP_DIR)/.build))
195
196 $(eval $(call subdir,$(curdir)))