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