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