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