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