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.
9 include $(INCLUDE_DIR)/feeds.mk
12 # invoke ipkg-build with some default options
14 $(SCRIPT_DIR)/ipkg-build -c -o 0 -g 0
17 $(SCRIPT_DIR)/ipkg-remove
19 IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
25 define BuildIPKGVariable
26 ifdef Package/$(1)/$(2)
27 $$(IPKG_$(1)) : VAR_$(2)$(3)=$$(Package/$(1)/$(2))
28 $(call shexport,Package/$(1)/$(2))
29 $(1)_COMMANDS += echo "$$$$$$$$$(call shvar,Package/$(1)/$(2))" > $(2)$(3); $(if $(4),chmod 0755 $(2)$(3);)
36 dep_split=$(subst :,$(space),$(1))
37 dep_rem=$(subst !,,$(subst $(strip $(PARENL)),,$(subst $(strip $(PARENR)),,$(word 1,$(call dep_split,$(1))))))
38 dep_and=dep_and_res:=$$(and $(subst $(space),$(comma),$(foreach cond,$(subst &&, ,$(1)),$$(CONFIG_$(cond)))))
39 dep_confvar=$(strip $(foreach cond,$(subst ||, ,$(call dep_rem,$(1))),$(eval $(call dep_and,$(cond)))$(dep_and_res)))
40 dep_pos=$(if $(call dep_confvar,$(1)),$(call dep_val,$(1)))
41 dep_neg=$(if $(call dep_confvar,$(1)),,$(call dep_val,$(1)))
42 dep_if=$(if $(findstring !,$(1)),$(call dep_neg,$(1)),$(call dep_pos,$(1)))
43 dep_val=$(word 2,$(call dep_split,$(1)))
44 strip_deps=$(strip $(subst +,,$(filter-out @%,$(1))))
45 filter_deps=$(foreach dep,$(call strip_deps,$(1)),$(if $(findstring :,$(dep)),$(call dep_if,$(dep)),$(dep)))
48 $$(if $(1),$$(if $(2),$$(foreach pkg,$(1),$$(IPKG_$$(pkg))): $$(foreach pkg,$(2),$$(IPKG_$$(pkg)))))
51 define FixupReverseDependencies
52 DEPS := $$(filter %:$(1),$$(IDEPEND))
53 DEPS := $$(patsubst %:$(1),%,$$(DEPS))
54 DEPS := $$(filter $$(DEPS),$$(IPKGS))
55 $(call AddDependency,$$(DEPS),$(1))
58 define FixupDependencies
59 DEPS := $$(filter $(1):%,$$(IDEPEND))
60 DEPS := $$(patsubst $(1):%,%,$$(DEPS))
61 DEPS := $$(filter $$(DEPS),$$(IPKGS))
62 $(call AddDependency,$(1),$$(DEPS))
65 ifneq ($(PKG_NAME),toolchain)
66 define CheckDependencies
68 rm -f $(PKG_INFO_DIR)/$(1).missing; \
71 READELF=$(TARGET_CROSS)readelf \
72 OBJCOPY=$(TARGET_CROSS)objcopy \
74 $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
75 ) | while read FILE; do \
76 grep -qxF "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
77 echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
79 if [ -f "$(PKG_INFO_DIR)/$(1).missing" ]; then \
80 echo "Package $(1) is missing dependencies for the following libraries:" >&2; \
81 cat "$(PKG_INFO_DIR)/$(1).missing" >&2; \
88 _addsep=$(word 1,$(1))$(foreach w,$(wordlist 2,$(words $(1)),$(1)),$(strip $(2) $(w)))
89 _cleansep=$(subst $(space)$(2)$(space),$(2)$(space),$(1))
90 mergelist=$(call _cleansep,$(call _addsep,$(1),$(comma)),$(comma))
91 addfield=$(if $(strip $(2)),$(1): $(2))
96 define BuildTarget/ipkg
97 ABIV_$(1):=$(call GetABISuffix,$(1))
98 PDIR_$(1):=$(call FeedPackageDir,$(1))
99 IPKG_$(1):=$$(PDIR_$(1))/$(1)$$(ABIV_$(1))_$(VERSION)_$(PKGARCH).ipk
100 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
101 KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
103 ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
105 ifdef Package/$(1)/install
108 ifdef Package/$(1)/install-overlay
112 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
114 $(_pkg_target)compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(PKG_BUILD_DIR)/.pkgdir/$(1).installed
115 prepare-package-install: $$(IPKG_$(1))
116 compile: $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
118 $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
121 .PHONY: $(PKG_INSTALL_STAMP).$(1)
122 ifeq ($(CONFIG_PACKAGE_$(1)),y)
123 compile: $(PKG_INSTALL_STAMP).$(1)
125 $(PKG_INSTALL_STAMP).$(1): prepare-package-install
126 echo "$(1)" >> $(PKG_INSTALL_STAMP)
128 $(if $(CONFIG_PACKAGE_$(1)),$$(warning WARNING: skipping $(1) -- package has no install section))
132 DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
133 IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
134 IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
136 $(FixupReverseDependencies)
138 $(eval $(call BuildIPKGVariable,$(1),conffiles))
139 $(eval $(call BuildIPKGVariable,$(1),preinst,,1))
140 $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg,1))
141 $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg,1))
142 $(eval $(call BuildIPKGVariable,$(1),postrm,,1))
144 $(PKG_BUILD_DIR)/.pkgdir/$(1).installed : export PATH=$$(TARGET_PATH_PKG)
145 $(PKG_BUILD_DIR)/.pkgdir/$(1).installed: $(STAMP_BUILT)
146 rm -rf $$@ $(PKG_BUILD_DIR)/.pkgdir/$(1)
147 mkdir -p $(PKG_BUILD_DIR)/.pkgdir/$(1)
148 $(call Package/$(1)/install,$(PKG_BUILD_DIR)/.pkgdir/$(1))
149 $(call Package/$(1)/install_lib,$(PKG_BUILD_DIR)/.pkgdir/$(1))
152 $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(PKG_BUILD_DIR)/.pkgdir/$(1).installed
153 mkdir -p $(STAGING_DIR_ROOT)/stamp
154 $(if $(ABI_VERSION),echo '$(ABI_VERSION)' | cmp -s - $(PKG_INFO_DIR)/$(1).version || echo '$(ABI_VERSION)' > $(PKG_INFO_DIR)/$(1).version)
155 $(call locked,$(CP) $(PKG_BUILD_DIR)/.pkgdir/$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
158 Package/$(1)/DEPENDS := $$(call mergelist,$$(foreach dep,$$(filter-out @%,$$(IDEPEND_$(1))),$$(dep)$$(call GetABISuffix,$$(dep))))
159 ifneq ($$(EXTRA_DEPENDS),)
160 Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
163 $(_define) Package/$(1)/CONTROL
164 Package: $(1)$$(ABIV_$(1))
166 $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
167 )$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
168 )$$(call addfield,Provides,$$(call mergelist,$$(filter-out $(1)$$(ABIV_$(1)),$(PROVIDES)$$(if $$(ABIV_$(1)), $(1) $(foreach provide,$(PROVIDES),$(provide)$$(call GetABISuffix,$(provide))))))
169 )$$(call addfield,Alternatives,$$(call mergelist,$(ALTERNATIVES))
170 )$$(call addfield,Source,$(SOURCE)
171 )$$(call addfield,SourceName,$(1)
172 )$$(call addfield,License,$(LICENSE)
173 )$$(call addfield,LicenseFiles,$(LICENSE_FILES)
174 )$$(call addfield,Section,$(SECTION)
175 )$$(call addfield,Require-User,$(USERID)
176 )$(if $(filter hold,$(PKG_FLAGS)),Status: unknown hold not-installed
177 )$(if $(filter essential,$(PKG_FLAGS)),Essential: yes
178 )$(if $(MAINTAINER),Maintainer: $(MAINTAINER)
179 )Architecture: $(PKGARCH)
183 $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
184 $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
185 $$(IPKG_$(1)) : export PATH=$$(TARGET_PATH_PKG)
186 $(PKG_INFO_DIR)/$(1).provides $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
187 @rm -rf $$(IDIR_$(1)) $$(if $$(call opkg_package_files,$(1)*),; $$(IPKG_REMOVE) $(1) $$(call opkg_package_files,$(1)*))
188 mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
189 $(call Package/$(1)/install,$$(IDIR_$(1)))
190 $(if $(Package/$(1)/install-overlay),mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/rootfs-overlay)
191 $(call Package/$(1)/install-overlay,$$(IDIR_$(1))/rootfs-overlay)
192 -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
194 find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
195 for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
196 if [ -f "$$$$file" ]; then \
199 done; $(Package/$(1)/extra_provides) \
200 ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
201 $(if $(PROVIDES),@for pkg in $(filter-out $(1),$(PROVIDES)); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
204 $(RSTRIP) $$(IDIR_$(1))
206 ifneq ($$(CONFIG_IPK_FILES_CHECKSUMS),)
209 find . -type f \! -path ./CONTROL/\* -exec sha256sum \{\} \; 2> /dev/null | \
210 sed 's|\([[:blank:]]\)\./|\1/|' > $$(IDIR_$(1))/CONTROL/files-sha256sum \
214 (cd $$(IDIR_$(1))/CONTROL; \
216 echo "$$$$CONTROL"; \
217 printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
222 echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
223 echo "[ -x "\$$$${IPKG_INSTROOT}/lib/functions.sh" ] || exit 0"; \
224 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
225 echo "default_postinst \$$$$0 \$$$$@"; \
229 echo "[ -x "\$$$${IPKG_INSTROOT}/lib/functions.sh" ] || exit 0"; \
230 echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
231 echo "default_prerm \$$$$0 \$$$$@"; \
233 chmod 0755 postinst prerm; \
237 ifneq ($$(KEEP_$(1)),)
240 for x in $$(KEEP_$(1)); do \
241 [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
243 [ -z "$$$$keepfiles" ] || { \
244 mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
245 for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
250 $(INSTALL_DIR) $$(PDIR_$(1))
251 $(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
252 @[ -f $$(IPKG_$(1)) ]
255 $$(if $$(call opkg_package_files,$(1)*),$$(IPKG_REMOVE) $(1) $$(call opkg_package_files,$(1)*))