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