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 $(SCRIPT_DIR)/ipkg-build -c -o 0 -g 0
14 IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
20 define BuildIPKGVariable
21 ifdef Package/$(1)/$(2)
22 $$(IPKG_$(1)) : VAR_$(2)$(3)=$$(Package/$(1)/$(2))
23 $(call shexport,Package/$(1)/$(2))
24 $(1)_COMMANDS += echo "$$$$$$$$$(call shvar,Package/$(1)/$(2))" > $(2)$(3); $(if $(4),chmod 0755 $(2)$(3);)
31 dep_split=$(subst :,$(space),$(1))
32 dep_rem=$(subst !,,$(subst $(strip $(PARENL)),,$(subst $(strip $(PARENR)),,$(word 1,$(call dep_split,$(1))))))
33 dep_confvar=$(strip $(foreach cond,$(subst ||, ,$(call dep_rem,$(1))),$(CONFIG_$(cond))))
34 dep_pos=$(if $(call dep_confvar,$(1)),$(call dep_val,$(1)))
35 dep_neg=$(if $(call dep_confvar,$(1)),,$(call dep_val,$(1)))
36 dep_if=$(if $(findstring !,$(1)),$(call dep_neg,$(1)),$(call dep_pos,$(1)))
37 dep_val=$(word 2,$(call dep_split,$(1)))
38 strip_deps=$(strip $(subst +,,$(filter-out @%,$(1))))
39 filter_deps=$(foreach dep,$(call strip_deps,$(1)),$(if $(findstring :,$(dep)),$(call dep_if,$(dep)),$(dep)))
42 $$(if $(1),$$(if $(2),$$(foreach pkg,$(1),$$(IPKG_$$(pkg))): $$(foreach pkg,$(2),$$(IPKG_$$(pkg)))))
45 define FixupReverseDependencies
46 DEPS := $$(filter %:$(1),$$(IDEPEND))
47 DEPS := $$(patsubst %:$(1),%,$$(DEPS))
48 DEPS := $$(filter $$(DEPS),$$(IPKGS))
49 $(call AddDependency,$$(DEPS),$(1))
52 define FixupDependencies
53 DEPS := $$(filter $(1):%,$$(IDEPEND))
54 DEPS := $$(patsubst $(1):%,%,$$(DEPS))
55 DEPS := $$(filter $$(DEPS),$$(IPKGS))
56 $(call AddDependency,$(1),$$(DEPS))
59 ifneq ($(PKG_NAME),toolchain)
60 define CheckDependencies
62 rm -f $(PKG_INFO_DIR)/$(1).missing; \
65 READELF=$(TARGET_CROSS)readelf \
66 OBJCOPY=$(TARGET_CROSS)objcopy \
68 $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
69 ) | while read FILE; do \
70 grep -qxF "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
71 echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
73 if [ -f "$(PKG_INFO_DIR)/$(1).missing" ]; then \
74 echo "Package $(1) is missing dependencies for the following libraries:" >&2; \
75 cat "$(PKG_INFO_DIR)/$(1).missing" >&2; \
82 _addsep=$(word 1,$(1))$(foreach w,$(wordlist 2,$(words $(1)),$(1)),$(strip $(2) $(w)))
83 _cleansep=$(subst $(space)$(2)$(space),$(2)$(space),$(1))
84 mergelist=$(call _cleansep,$(call _addsep,$(1),$(comma)),$(comma))
85 addfield=$(if $(strip $(2)),$(1): $(2))
90 define BuildTarget/ipkg
91 PDIR_$(1):=$(call FeedPackageDir,$(1))
92 IPKG_$(1):=$$(PDIR_$(1))/$(1)_$(VERSION)_$(PKGARCH).ipk
93 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
94 KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
96 ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
97 ifdef Package/$(1)/install
98 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
100 compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
101 ifneq ($(ABI_VERSION),)
102 compile: $(PKG_INFO_DIR)/$(1).version
105 ifeq ($(CONFIG_PACKAGE_$(1)),y)
106 .PHONY: $(PKG_INSTALL_STAMP).$(1)
107 compile: $(PKG_INSTALL_STAMP).$(1)
108 $(PKG_INSTALL_STAMP).$(1):
109 if [ -f $(PKG_INSTALL_STAMP).clean ]; then \
111 $(PKG_INSTALL_STAMP) \
112 $(PKG_INSTALL_STAMP).clean; \
114 echo "$(1)" >> $(PKG_INSTALL_STAMP)
117 $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
122 DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
123 IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
124 IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
126 $(FixupReverseDependencies)
128 $(eval $(call BuildIPKGVariable,$(1),conffiles))
129 $(eval $(call BuildIPKGVariable,$(1),preinst,,1))
130 $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg,1))
131 $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg,1))
132 $(eval $(call BuildIPKGVariable,$(1),postrm,,1))
134 $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(STAMP_BUILT)
135 rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
136 mkdir -p $(STAGING_DIR_ROOT)/stamp $(STAGING_DIR_ROOT)/tmp-$(1)
137 $(call Package/$(1)/install,$(STAGING_DIR_ROOT)/tmp-$(1))
138 $(call Package/$(1)/install_lib,$(STAGING_DIR_ROOT)/tmp-$(1))
139 $(call locked,$(CP) $(STAGING_DIR_ROOT)/tmp-$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
140 rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
143 $(PKG_INFO_DIR)/$(1).version: $$(IPKG_$(1))
144 echo '$(ABI_VERSION)' | cmp -s - $$@ || \
145 echo '$(ABI_VERSION)' > $$@
147 Package/$(1)/DEPENDS := $$(call mergelist,$$(filter-out @%,$$(IDEPEND_$(1))))
148 ifneq ($$(EXTRA_DEPENDS),)
149 Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
152 $(_define) Package/$(1)/CONTROL
155 $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
156 )$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
157 )$$(call addfield,Provides,$(PROVIDES)
158 )$$(call addfield,Source,$(SOURCE)
159 )$$(call addfield,License,$$(PKG_LICENSE)
160 )$$(call addfield,LicenseFiles,$$(PKG_LICENSE_FILES)
161 )$$(call addfield,Section,$(SECTION)
162 )$$(call addfield,Require-User,$(USERID)
163 )$(if $(filter hold,$(PKG_FLAGS)),Status: unknown hold not-installed
164 )$(if $(filter essential,$(PKG_FLAGS)),Essential: yes
165 )$(if $(MAINTAINER),Maintainer: $(MAINTAINER)
166 )Architecture: $(PKGARCH)
170 $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1))
171 $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
172 $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
173 $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
174 @rm -rf $$(PDIR_$(1))/$(1)_* $$(IDIR_$(1))
175 mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
176 $(call Package/$(1)/install,$$(IDIR_$(1)))
177 -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
179 find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
180 for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
181 if [ -f "$$$$file" ]; then \
184 done; $(Package/$(1)/extra_provides) \
185 ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
186 $(if $(PROVIDES),@for pkg in $(PROVIDES); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
189 $(RSTRIP) $$(IDIR_$(1))
190 (cd $$(IDIR_$(1))/CONTROL; \
192 echo "$$$$CONTROL"; \
193 printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
198 echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
199 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
200 echo "default_postinst \$$$$0 \$$$$@"; \
204 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
205 echo "default_prerm \$$$$0 \$$$$@"; \
207 chmod 0755 postinst prerm; \
211 ifneq ($$(KEEP_$(1)),)
214 for x in $$(KEEP_$(1)); do \
215 [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
217 [ -z "$$$$keepfiles" ] || { \
218 mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
219 for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
224 $(INSTALL_DIR) $$(PDIR_$(1))
225 $(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
226 @[ -f $$(IPKG_$(1)) ]
229 rm -f $$(PDIR_$(1))/$(1)_*