gettext-full: fix to use $STAGING_DIR_HOSTPKG instead of $STAGING_DIR/host
[openwrt/openwrt.git] / include / package-ipkg.mk
1 #
2 # Copyright (C) 2006-2014 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 ifndef DUMP
9 include $(INCLUDE_DIR)/feeds.mk
10 endif
11
12 # invoke ipkg-build with some default options
13 IPKG_BUILD:= \
14 $(SCRIPT_DIR)/ipkg-build -c -o 0 -g 0
15
16 IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
17
18 # 1: package name
19 # 2: variable name
20 # 3: variable suffix
21 # 4: file is a script
22 define BuildIPKGVariable
23 ifdef Package/$(1)/$(2)
24 $$(IPKG_$(1)) : VAR_$(2)$(3)=$$(Package/$(1)/$(2))
25 $(call shexport,Package/$(1)/$(2))
26 $(1)_COMMANDS += echo "$$$$$$$$$(call shvar,Package/$(1)/$(2))" > $(2)$(3); $(if $(4),chmod 0755 $(2)$(3);)
27 endif
28 endef
29
30 PARENL :=(
31 PARENR :=)
32
33 dep_split=$(subst :,$(space),$(1))
34 dep_rem=$(subst !,,$(subst $(strip $(PARENL)),,$(subst $(strip $(PARENR)),,$(word 1,$(call dep_split,$(1))))))
35 dep_confvar=$(strip $(foreach cond,$(subst ||, ,$(call dep_rem,$(1))),$(CONFIG_$(cond))))
36 dep_pos=$(if $(call dep_confvar,$(1)),$(call dep_val,$(1)))
37 dep_neg=$(if $(call dep_confvar,$(1)),,$(call dep_val,$(1)))
38 dep_if=$(if $(findstring !,$(1)),$(call dep_neg,$(1)),$(call dep_pos,$(1)))
39 dep_val=$(word 2,$(call dep_split,$(1)))
40 strip_deps=$(strip $(subst +,,$(filter-out @%,$(1))))
41 filter_deps=$(foreach dep,$(call strip_deps,$(1)),$(if $(findstring :,$(dep)),$(call dep_if,$(dep)),$(dep)))
42
43 define AddDependency
44 $$(if $(1),$$(if $(2),$$(foreach pkg,$(1),$$(IPKG_$$(pkg))): $$(foreach pkg,$(2),$$(IPKG_$$(pkg)))))
45 endef
46
47 define FixupReverseDependencies
48 DEPS := $$(filter %:$(1),$$(IDEPEND))
49 DEPS := $$(patsubst %:$(1),%,$$(DEPS))
50 DEPS := $$(filter $$(DEPS),$$(IPKGS))
51 $(call AddDependency,$$(DEPS),$(1))
52 endef
53
54 define FixupDependencies
55 DEPS := $$(filter $(1):%,$$(IDEPEND))
56 DEPS := $$(patsubst $(1):%,%,$$(DEPS))
57 DEPS := $$(filter $$(DEPS),$$(IPKGS))
58 $(call AddDependency,$(1),$$(DEPS))
59 endef
60
61 ifneq ($(PKG_NAME),toolchain)
62 define CheckDependencies
63 @( \
64 rm -f $(PKG_INFO_DIR)/$(1).missing; \
65 ( \
66 export \
67 READELF=$(TARGET_CROSS)readelf \
68 OBJCOPY=$(TARGET_CROSS)objcopy \
69 XARGS="$(XARGS)"; \
70 $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
71 ) | while read FILE; do \
72 grep -qxF "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
73 echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
74 done; \
75 if [ -f "$(PKG_INFO_DIR)/$(1).missing" ]; then \
76 echo "Package $(1) is missing dependencies for the following libraries:" >&2; \
77 cat "$(PKG_INFO_DIR)/$(1).missing" >&2; \
78 false; \
79 fi; \
80 )
81 endef
82 endif
83
84 _addsep=$(word 1,$(1))$(foreach w,$(wordlist 2,$(words $(1)),$(1)),$(strip $(2) $(w)))
85 _cleansep=$(subst $(space)$(2)$(space),$(2)$(space),$(1))
86 mergelist=$(call _cleansep,$(call _addsep,$(1),$(comma)),$(comma))
87 addfield=$(if $(strip $(2)),$(1): $(2))
88 _define=define
89 _endef=endef
90
91 ifeq ($(DUMP),)
92 define BuildTarget/ipkg
93 PDIR_$(1):=$(call FeedPackageDir,$(1))
94 IPKG_$(1):=$$(PDIR_$(1))/$(1)_$(VERSION)_$(PKGARCH).ipk
95 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
96 KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
97
98 ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
99 do_install=
100 ifdef Package/$(1)/install
101 do_install=yes
102 endif
103 ifdef Package/$(1)/install-overlay
104 do_install=yes
105 endif
106 ifdef do_install
107 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
108 IPKGS += $(1)
109 .compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(PKG_BUILD_DIR)/.pkgdir/$(1).installed
110 compile: $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
111 else
112 $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
113 endif
114
115 .PHONY: $(PKG_INSTALL_STAMP).$(1)
116 compile: $(PKG_INSTALL_STAMP).$(1)
117 $(PKG_INSTALL_STAMP).$(1):
118 if [ -f $(PKG_INSTALL_STAMP).clean ]; then \
119 rm -f \
120 $(PKG_INSTALL_STAMP) \
121 $(PKG_INSTALL_STAMP).clean; \
122 fi
123 ifeq ($(CONFIG_PACKAGE_$(1)),y)
124 echo "$(1)" >> $(PKG_INSTALL_STAMP)
125 endif
126 endif
127 endif
128
129 DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
130 IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
131 IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
132 $(FixupDependencies)
133 $(FixupReverseDependencies)
134
135 $(eval $(call BuildIPKGVariable,$(1),conffiles))
136 $(eval $(call BuildIPKGVariable,$(1),preinst,,1))
137 $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg,1))
138 $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg,1))
139 $(eval $(call BuildIPKGVariable,$(1),postrm,,1))
140
141 $(PKG_BUILD_DIR)/.pkgdir/$(1).installed : export PATH=$$(TARGET_PATH_PKG)
142 $(PKG_BUILD_DIR)/.pkgdir/$(1).installed: $(STAMP_BUILT)
143 rm -rf $$@ $(PKG_BUILD_DIR)/.pkgdir/$(1)
144 mkdir -p $(PKG_BUILD_DIR)/.pkgdir/$(1)
145 $(call Package/$(1)/install,$(PKG_BUILD_DIR)/.pkgdir/$(1))
146 $(call Package/$(1)/install_lib,$(PKG_BUILD_DIR)/.pkgdir/$(1))
147 touch $$@
148
149 $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(PKG_BUILD_DIR)/.pkgdir/$(1).installed
150 mkdir -p $(STAGING_DIR_ROOT)/stamp
151 $(if $(ABI_VERSION),echo '$(ABI_VERSION)' | cmp -s - $$@ || echo '$(ABI_VERSION)' > $$@)
152 $(call locked,$(CP) $(PKG_BUILD_DIR)/.pkgdir/$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
153 touch $$@
154
155 Package/$(1)/DEPENDS := $$(call mergelist,$$(filter-out @%,$$(IDEPEND_$(1))))
156 ifneq ($$(EXTRA_DEPENDS),)
157 Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
158 endif
159
160 $(_define) Package/$(1)/CONTROL
161 Package: $(1)
162 Version: $(VERSION)
163 $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
164 )$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
165 )$$(call addfield,Provides,$$(call mergelist,$(PROVIDES))
166 )$$(call addfield,Source,$(SOURCE)
167 )$$(call addfield,License,$$(PKG_LICENSE)
168 )$$(call addfield,LicenseFiles,$$(PKG_LICENSE_FILES)
169 )$$(call addfield,Section,$(SECTION)
170 )$$(call addfield,Require-User,$(USERID)
171 )$(if $(filter hold,$(PKG_FLAGS)),Status: unknown hold not-installed
172 )$(if $(filter essential,$(PKG_FLAGS)),Essential: yes
173 )$(if $(MAINTAINER),Maintainer: $(MAINTAINER)
174 )Architecture: $(PKGARCH)
175 Installed-Size: 0
176 $(_endef)
177
178 $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1))
179 $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
180 $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
181 $$(IPKG_$(1)) : export PATH=$$(TARGET_PATH_PKG)
182 $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
183 @rm -rf $$(IDIR_$(1)) $$(call opkg_package_files,$(1))
184 mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
185 $(call Package/$(1)/install,$$(IDIR_$(1)))
186 $(if $(Package/$(1)/install-overlay),mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/rootfs-overlay)
187 $(call Package/$(1)/install-overlay,$$(IDIR_$(1))/rootfs-overlay)
188 -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
189 @( \
190 find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
191 for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
192 if [ -f "$$$$file" ]; then \
193 cat $$$$file; \
194 fi; \
195 done; $(Package/$(1)/extra_provides) \
196 ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
197 $(if $(PROVIDES),@for pkg in $(PROVIDES); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
198 $(CheckDependencies)
199
200 $(RSTRIP) $$(IDIR_$(1))
201 (cd $$(IDIR_$(1))/CONTROL; \
202 ( \
203 echo "$$$$CONTROL"; \
204 printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
205 ) > control; \
206 chmod 644 control; \
207 ( \
208 echo "#!/bin/sh"; \
209 echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
210 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
211 echo "default_postinst \$$$$0 \$$$$@"; \
212 ) > postinst; \
213 ( \
214 echo "#!/bin/sh"; \
215 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
216 echo "default_prerm \$$$$0 \$$$$@"; \
217 ) > prerm; \
218 chmod 0755 postinst prerm; \
219 $($(1)_COMMANDS) \
220 )
221
222 ifneq ($$(KEEP_$(1)),)
223 @( \
224 keepfiles=""; \
225 for x in $$(KEEP_$(1)); do \
226 [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
227 done; \
228 [ -z "$$$$keepfiles" ] || { \
229 mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
230 for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
231 }; \
232 )
233 endif
234
235 $(INSTALL_DIR) $$(PDIR_$(1))
236 $(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
237 @[ -f $$(IPKG_$(1)) ]
238
239 $(1)-clean:
240 $$(if $$(call opkg_package_files,$(1)),rm -f $$(call opkg_package_files,$(1)))
241
242 clean: $(1)-clean
243
244 endef
245 endif