2 # Copyright (C) 2006-2014 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 include $(INCLUDE_DIR)/feeds.mk
10 # invoke ipkg-build with some default options
12 $(STAGING_DIR_HOST)/bin/ipkg-build -c -o 0 -g 0
14 IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
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);
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)))
41 $$(if $(1),$$(if $(2),$$(foreach pkg,$(1),$$(IPKG_$$(pkg))): $$(foreach pkg,$(2),$$(IPKG_$$(pkg)))))
44 define FixupReverseDependencies
45 DEPS := $$(filter %:$(1),$$(IDEPEND))
46 DEPS := $$(patsubst %:$(1),%,$$(DEPS))
47 DEPS := $$(filter $$(DEPS),$$(IPKGS))
48 $(call AddDependency,$$(DEPS),$(1))
51 define FixupDependencies
52 DEPS := $$(filter $(1):%,$$(IDEPEND))
53 DEPS := $$(patsubst $(1):%,%,$$(DEPS))
54 DEPS := $$(filter $$(DEPS),$$(IPKGS))
55 $(call AddDependency,$(1),$$(DEPS))
58 ifneq ($(PKG_NAME),toolchain)
59 define CheckDependencies
61 rm -f $(PKG_INFO_DIR)/$(1).missing; \
64 READELF=$(TARGET_CROSS)readelf \
65 OBJCOPY=$(TARGET_CROSS)objcopy \
67 $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
68 ) | while read FILE; do \
69 grep -qxF "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
70 echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
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; \
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))
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))
95 ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
96 ifdef Package/$(1)/install
97 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
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
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 \
110 $(PKG_INSTALL_STAMP) \
111 $(PKG_INSTALL_STAMP).clean; \
113 echo "$(1)" >> $(PKG_INSTALL_STAMP)
116 $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
121 DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
122 IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
123 IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
125 $(FixupReverseDependencies)
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))
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)
142 $(PKG_INFO_DIR)/$(1).version: $$(IPKG_$(1))
143 echo '$(ABI_VERSION)' | cmp -s - $$@ || \
144 echo '$(ABI_VERSION)' > $$@
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))
151 $(_define) Package/$(1)/CONTROL
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)
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
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 \
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)
188 $(RSTRIP) $$(IDIR_$(1))
189 (cd $$(IDIR_$(1))/CONTROL; \
191 echo "$$$$CONTROL"; \
192 printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
197 echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
198 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
199 echo "default_postinst \$$$$0 \$$$$@"; \
203 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
204 echo "default_prerm \$$$$0 \$$$$@"; \
210 ifneq ($$(KEEP_$(1)),)
213 for x in $$(KEEP_$(1)); do \
214 [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
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; \
223 $(INSTALL_DIR) $$(PDIR_$(1))
224 $(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
225 @[ -f $$(IPKG_$(1)) ]
228 rm -f $$(PDIR_$(1))/$(1)_*