build: reduce the size of package metadata a bit to keep package list files smaller
[openwrt/svn-archive/archive.git] / include / package-ipkg.mk
1 #
2 # Copyright (C) 2006,2007 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 READELF=$(TARGET_CROSS)readelf XARGS="$(XARGS)"; \
58 $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
59 ) | while read FILE; do \
60 grep -q "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
61 echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
62 done; \
63 if [ -f "$(PKG_INFO_DIR)/$(1).missing" ]; then \
64 echo "Package $(1) is missing dependencies for the following libraries:"; \
65 cat "$(PKG_INFO_DIR)/$(1).missing"; \
66 false; \
67 fi; \
68 )
69 endef
70 endif
71
72 ifeq ($(DUMP),)
73 define BuildTarget/ipkg
74 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
75 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
76 KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
77
78 ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
79 ifdef Package/$(1)/install
80 ifneq ($(CONFIG_PACKAGE_$(1))$(SDK)$(DEVELOPER),)
81 IPKGS += $(1)
82 compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
83
84 ifeq ($(CONFIG_PACKAGE_$(1)),y)
85 .PHONY: $(PKG_INSTALL_STAMP).$(1)
86 compile: $(PKG_INSTALL_STAMP).$(1)
87 $(PKG_INSTALL_STAMP).$(1):
88 if [ -f $(PKG_INSTALL_STAMP).clean ]; then \
89 rm -f \
90 $(PKG_INSTALL_STAMP) \
91 $(PKG_INSTALL_STAMP).clean; \
92 fi; \
93 echo "$(1)" >> $(PKG_INSTALL_STAMP)
94 endif
95 else
96 compile: $(1)-disabled
97 $(1)-disabled:
98 @echo "WARNING: skipping $(1) -- package not selected"
99 endif
100 endif
101 endif
102
103 DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
104 IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
105 IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
106 $(FixupDependencies)
107 $(FixupReverseDependencies)
108
109 $(eval $(call BuildIPKGVariable,$(1),conffiles))
110 $(eval $(call BuildIPKGVariable,$(1),preinst))
111 $(eval $(call BuildIPKGVariable,$(1),postinst))
112 $(eval $(call BuildIPKGVariable,$(1),prerm))
113 $(eval $(call BuildIPKGVariable,$(1),postrm))
114
115 $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(STAMP_BUILT)
116 rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
117 mkdir -p $(STAGING_DIR_ROOT)/stamp $(STAGING_DIR_ROOT)/tmp-$(1)
118 $(call Package/$(1)/install,$(STAGING_DIR_ROOT)/tmp-$(1))
119 $(call Package/$(1)/install_lib,$(STAGING_DIR_ROOT)/tmp-$(1))
120 $(call locked,$(CP) $(STAGING_DIR_ROOT)/tmp-$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
121 rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
122 touch $$@
123
124 $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1))
125 $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
126 @rm -rf $(PACKAGE_DIR)/$(1)_* $$(IDIR_$(1))
127 mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
128 $(call Package/$(1)/install,$$(IDIR_$(1)))
129 -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
130 @( \
131 find $$(IDIR_$(1)) -name lib\*.so\* | awk -F/ '{ print $$$$NF }'; \
132 for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
133 if [ -f "$$$$file" ]; then \
134 cat $$$$file; \
135 fi; \
136 done; \
137 ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
138 $(if $(PROVIDES),@for pkg in $(PROVIDES); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
139 $(CheckDependencies)
140
141 $(RSTRIP) $$(IDIR_$(1))
142 ( \
143 echo "Package: $(1)"; \
144 echo "Version: $(VERSION)"; \
145 DEPENDS='$(EXTRA_DEPENDS)'; \
146 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
147 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
148 done; \
149 [ -z "$$$$DEPENDS" ] || echo "Depends: $$$$DEPENDS"; \
150 $(if $(PROVIDES), echo "Provides: $(PROVIDES)"; ) \
151 echo "Source: $(SOURCE)"; \
152 $(if $(PKG_SOURCE), echo "SourceFile: $(PKG_SOURCE)"; ) \
153 $(if $(PKG_SOURCE_URL), echo "SourceURL: $(PKG_SOURCE_URL)"; ) \
154 $(if $(PKG_LICENSE), echo "License: $(PKG_LICENSE)"; ) \
155 $(if $(PKG_LICENSE_FILES), echo "LicenseFiles: $(PKG_LICENSE_FILES)"; ) \
156 echo "Section: $(SECTION)"; \
157 $(if $(filter hold,$(PKG_FLAGS)),echo "Status: unknown hold not-installed"; ) \
158 $(if $(filter essential,$(PKG_FLAGS)), echo "Essential: yes"; ) \
159 $(if $(MAINTAINER),echo "Maintainer: $(MAINTAINER)"; ) \
160 echo "Architecture: $(PKGARCH)"; \
161 echo "Installed-Size: 0"; \
162 echo -n "Description: "; $(SH_FUNC) getvar $(call shvar,Package/$(1)/description) | sed -e 's,^[[:space:]]*, ,g'; \
163 ) > $$(IDIR_$(1))/CONTROL/control
164 chmod 644 $$(IDIR_$(1))/CONTROL/control
165 $(SH_FUNC) (cd $$(IDIR_$(1))/CONTROL; \
166 $($(1)_COMMANDS) \
167 )
168
169 ifneq ($$(KEEP_$(1)),)
170 @( \
171 keepfiles=""; \
172 for x in $$(KEEP_$(1)); do \
173 [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
174 done; \
175 [ -z "$$$$keepfiles" ] || { \
176 mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
177 for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
178 }; \
179 )
180 endif
181
182 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
183 @[ -f $$(IPKG_$(1)) ]
184
185 $(1)-clean:
186 rm -f $(PACKAGE_DIR)/$(1)_*
187
188 clean: $(1)-clean
189
190 endef
191 endif