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