package/index: fix index creating when building without signing
[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 package-y-filter := $(package-y)
20 package-m-filter := $(filter-out $(package-y),$(package-m))
21 package-n-filter := $(filter-out $(package-y) $(package-m),$(package-))
22 package-ignore-errors := $(filter n m y,$(IGNORE_ERRORS))
23 package-ignore-errors := $(if $(package-ignore-errors),$(package-ignore-errors),n m)
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_TMP=$(TMP_DIR)/ipkg \
63 IPKG_INSTROOT=$(TARGET_DIR) \
64 IPKG_CONF_DIR=$(STAGING_DIR)/etc \
65 IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
66 $(XARGS) $(STAGING_DIR_HOST)/bin/opkg \
67 --offline-root $(TARGET_DIR) \
68 --force-depends \
69 --force-overwrite \
70 --force-postinstall \
71 --force-maintainer \
72 --add-dest root:/ \
73 --add-arch all:100 \
74 --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
75
76 PACKAGE_INSTALL_FILES:= \
77 $(foreach pkg,$(sort $(package-y)), \
78 $(foreach variant, \
79 $(if $(package/$(pkg)/variants), \
80 $(package/$(pkg)/variants), \
81 $(if $(package/$(pkg)/default-variant), \
82 $(package/$(pkg)/default-variant), \
83 default \
84 ) \
85 ), \
86 $(PKG_INFO_DIR)/$(lastword $(subst /,$(space),$(pkg))).$(variant).install \
87 ) \
88 )
89
90 $(curdir)/cleanup: $(TMP_DIR)/.build
91 rm -rf $(STAGING_DIR_ROOT)
92
93 $(curdir)/install: $(TMP_DIR)/.build
94 - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
95 rm -rf $(TARGET_DIR)
96 [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
97 @$(FIND) `sed -e 's|.*|$(PACKAGE_DIR)/&_*.ipk|' $(PACKAGE_INSTALL_FILES)` | sort -u | $(OPKG) install
98 @for file in $(PACKAGE_INSTALL_FILES); do \
99 [ -s $$file.flags ] || continue; \
100 for flag in `cat $$file.flags`; do \
101 $(OPKG) flag $$flag < $$file; \
102 done; \
103 done || true
104 @-$(MAKE) package/preconfig
105 @if [ -d $(TOPDIR)/files ]; then \
106 $(call file_copy,$(TOPDIR)/files/.,$(TARGET_DIR)); \
107 fi
108 @mkdir -p $(TARGET_DIR)/etc/rc.d
109 @( \
110 cd $(TARGET_DIR); \
111 for script in ./etc/init.d/*; do \
112 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
113 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) ./etc/rc.common $$script enable; \
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 $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
121 $(call mklibs)
122
123 PASSOPT=""
124 PASSARG=""
125 ifndef CONFIG_OPKGSMIME_PASSPHRASE
126 ifneq ($(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE)),)
127 PASSOPT="-passin"
128 PASSARG="file:$(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE))"
129 endif
130 endif
131
132 $(curdir)/index: FORCE
133 @echo Generating package index...
134 @(cd $(PACKAGE_DIR); \
135 $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
136 gzip -9c Packages > Packages.gz )
137 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_KEY)),)
138 @echo Signing key has not been configured
139 else
140 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_CERT)),)
141 @echo Certificate has not been configured
142 else
143 @echo Signing package index...
144 @(cd $(PACKAGE_DIR); \
145 openssl smime -binary -in Packages.gz \
146 -out Packages.sig -outform PEM -sign \
147 -signer $(CONFIG_OPKGSMIME_CERT) \
148 -inkey $(CONFIG_OPKGSMIME_KEY) \
149 $(PASSOPT) $(PASSARG) )
150 endif
151 endif
152
153 $(curdir)/preconfig:
154
155 $(curdir)/flags-install:= -j1
156
157 $(eval $(call stampfile,$(curdir),package,prereq,.config))
158 $(eval $(call stampfile,$(curdir),package,cleanup,$(TMP_DIR)/.build))
159 $(eval $(call stampfile,$(curdir),package,compile,$(TMP_DIR)/.build))
160 $(eval $(call stampfile,$(curdir),package,install,$(TMP_DIR)/.build))
161
162 $(eval $(call subdir,$(curdir)))