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