kernel: bump 4.14 to 4.14.89
[openwrt/staging/chunkeey.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 $(_pkg_target)compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(PKG_BUILD_DIR)/.pkgdir/$(1).installed
110 prepare-package-install: $$(IPKG_$(1))
111 compile: $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
112 else
113 $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
114 endif
115
116 .PHONY: $(PKG_INSTALL_STAMP).$(1)
117 ifeq ($(CONFIG_PACKAGE_$(1)),y)
118 compile: $(PKG_INSTALL_STAMP).$(1)
119 endif
120 $(PKG_INSTALL_STAMP).$(1): prepare-package-install
121 echo "$(1)" >> $(PKG_INSTALL_STAMP)
122 endif
123 endif
124
125 DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
126 IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
127 IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
128 $(FixupDependencies)
129 $(FixupReverseDependencies)
130
131 $(eval $(call BuildIPKGVariable,$(1),conffiles))
132 $(eval $(call BuildIPKGVariable,$(1),preinst,,1))
133 $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg,1))
134 $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg,1))
135 $(eval $(call BuildIPKGVariable,$(1),postrm,,1))
136
137 $(PKG_BUILD_DIR)/.pkgdir/$(1).installed : export PATH=$$(TARGET_PATH_PKG)
138 $(PKG_BUILD_DIR)/.pkgdir/$(1).installed: $(STAMP_BUILT)
139 rm -rf $$@ $(PKG_BUILD_DIR)/.pkgdir/$(1)
140 mkdir -p $(PKG_BUILD_DIR)/.pkgdir/$(1)
141 $(call Package/$(1)/install,$(PKG_BUILD_DIR)/.pkgdir/$(1))
142 $(call Package/$(1)/install_lib,$(PKG_BUILD_DIR)/.pkgdir/$(1))
143 touch $$@
144
145 $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(PKG_BUILD_DIR)/.pkgdir/$(1).installed
146 mkdir -p $(STAGING_DIR_ROOT)/stamp
147 $(if $(ABI_VERSION),echo '$(ABI_VERSION)' | cmp -s - $(PKG_INFO_DIR)/$(1).version || echo '$(ABI_VERSION)' > $(PKG_INFO_DIR)/$(1).version)
148 $(call locked,$(CP) $(PKG_BUILD_DIR)/.pkgdir/$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
149 touch $$@
150
151 Package/$(1)/DEPENDS := $$(call mergelist,$$(filter-out @%,$$(IDEPEND_$(1))))
152 ifneq ($$(EXTRA_DEPENDS),)
153 Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
154 endif
155
156 $(_define) Package/$(1)/CONTROL
157 Package: $(1)
158 Version: $(VERSION)
159 $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
160 )$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
161 )$$(call addfield,Provides,$$(call mergelist,$(PROVIDES))
162 )$$(call addfield,Alternatives,$$(call mergelist,$(ALTERNATIVES))
163 )$$(call addfield,Source,$(SOURCE)
164 )$$(call addfield,License,$(LICENSE)
165 )$$(call addfield,LicenseFiles,$(LICENSE_FILES)
166 )$$(call addfield,Section,$(SECTION)
167 )$$(call addfield,Require-User,$(USERID)
168 )$(if $(filter hold,$(PKG_FLAGS)),Status: unknown hold not-installed
169 )$(if $(filter essential,$(PKG_FLAGS)),Essential: yes
170 )$(if $(MAINTAINER),Maintainer: $(MAINTAINER)
171 )Architecture: $(PKGARCH)
172 Installed-Size: 0
173 $(_endef)
174
175 $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
176 $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
177 $$(IPKG_$(1)) : export PATH=$$(TARGET_PATH_PKG)
178 $(PKG_INFO_DIR)/$(1).provides $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
179 @rm -rf $$(IDIR_$(1)) $$(call opkg_package_files,$(1))
180 mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
181 $(call Package/$(1)/install,$$(IDIR_$(1)))
182 $(if $(Package/$(1)/install-overlay),mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/rootfs-overlay)
183 $(call Package/$(1)/install-overlay,$$(IDIR_$(1))/rootfs-overlay)
184 -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
185 @( \
186 find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
187 for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
188 if [ -f "$$$$file" ]; then \
189 cat $$$$file; \
190 fi; \
191 done; $(Package/$(1)/extra_provides) \
192 ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
193 $(if $(PROVIDES),@for pkg in $(filter-out $(1),$(PROVIDES)); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
194 $(CheckDependencies)
195
196 $(RSTRIP) $$(IDIR_$(1))
197 (cd $$(IDIR_$(1))/CONTROL; \
198 ( \
199 echo "$$$$CONTROL"; \
200 printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
201 ) > control; \
202 chmod 644 control; \
203 ( \
204 echo "#!/bin/sh"; \
205 echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
206 echo "[ -x "\$$$${IPKG_INSTROOT}/lib/functions.sh" ] || exit 0"; \
207 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
208 echo "default_postinst \$$$$0 \$$$$@"; \
209 ) > postinst; \
210 ( \
211 echo "#!/bin/sh"; \
212 echo "[ -x "\$$$${IPKG_INSTROOT}/lib/functions.sh" ] || exit 0"; \
213 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
214 echo "default_prerm \$$$$0 \$$$$@"; \
215 ) > prerm; \
216 chmod 0755 postinst prerm; \
217 $($(1)_COMMANDS) \
218 )
219
220 ifneq ($$(KEEP_$(1)),)
221 @( \
222 keepfiles=""; \
223 for x in $$(KEEP_$(1)); do \
224 [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
225 done; \
226 [ -z "$$$$keepfiles" ] || { \
227 mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
228 for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
229 }; \
230 )
231 endif
232
233 $(INSTALL_DIR) $$(PDIR_$(1))
234 $(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
235 @[ -f $$(IPKG_$(1)) ]
236
237 $(1)-clean:
238 $$(if $$(call opkg_package_files,$(1)),rm -f $$(call opkg_package_files,$(1)))
239
240 clean: $(1)-clean
241
242 endef
243 endif