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