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