2 # Copyright (C) 2006-2010 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
10 include $(INCLUDE_DIR)/feeds.mk
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)
30 ifdef CONFIG_USE_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) \
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 \
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; \
63 # where to build (and put) .ipk packages
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) \
78 --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
80 PACKAGE_INSTALL_FILES:= \
81 $(foreach pkg,$(sort $(package-y)), \
83 $(if $(strip $(package/$(pkg)/variants)), \
84 $(package/$(pkg)/variants), \
85 $(if $(package/$(pkg)/default-variant), \
86 $(package/$(pkg)/default-variant), \
90 $(PKG_INFO_DIR)/$(lastword $(subst /,$(space),$(pkg))).$(variant).install \
94 $(curdir)/cleanup: $(TMP_DIR)/.build
95 rm -rf $(STAGING_DIR_ROOT)
97 $(curdir)/install: $(TMP_DIR)/.build $(curdir)/system/opkg/host/install
98 - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
100 [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
101 @echo $(wildcard $(foreach dir,$(PACKAGE_SUBDIRS),$(foreach pkg,$(shell cat $(PACKAGE_INSTALL_FILES) 2>/dev/null),$(dir)/$(pkg)_*.ipk))) | $(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; \
108 @-$(MAKE) package/preconfig
109 @if [ -d $(TOPDIR)/files ]; then \
110 $(call file_copy,$(TOPDIR)/files/.,$(TARGET_DIR)); \
112 @mkdir -p $(TARGET_DIR)/etc/rc.d
115 for script in ./usr/lib/opkg/info/*.postinst; do \
116 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
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; \
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)
135 ifndef CONFIG_OPKGSMIME_PASSPHRASE
136 ifneq ($(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE)),)
138 PASSARG="file:$(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE))"
142 $(curdir)/index: FORCE
143 @echo Generating package index...
144 @for d in $(PACKAGE_SUBDIRS); do ( \
146 cd $$d || continue; \
147 $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
148 gzip -9nc Packages > Packages.gz; \
150 ifdef CONFIG_SIGNED_PACKAGES
151 @echo Signing package index...
152 @for d in $(PACKAGE_SUBDIRS); do ( \
154 cd $$d || continue; \
155 $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY); \
158 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_KEY)),)
159 @echo Signing key has not been configured
161 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_CERT)),)
162 @echo Certificate has not been configured
164 @echo Signing package index...
165 @for d in $(PACKAGE_SUBDIRS); do ( \
167 cd $$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); \
180 $(curdir)/flags-install:= -j1
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))
187 $(eval $(call subdir,$(curdir)))