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 ipkg-build -c -o 0 -g 0
14 IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
16 define BuildIPKGVariable
17 ifdef Package/$(1)/$(2)
18 $(call shexport,Package/$(1)/$(2))
19 $(1)_COMMANDS += var2file "$(call shvar,Package/$(1)/$(2))" $(2);
26 dep_split=$(subst :,$(space),$(1))
27 dep_rem=$(subst !,,$(subst $(strip $(PARENL)),,$(subst $(strip $(PARENR)),,$(word 1,$(call dep_split,$(1))))))
28 dep_confvar=$(strip $(foreach cond,$(subst ||, ,$(call dep_rem,$(1))),$(CONFIG_$(cond))))
29 dep_pos=$(if $(call dep_confvar,$(1)),$(call dep_val,$(1)))
30 dep_neg=$(if $(call dep_confvar,$(1)),,$(call dep_val,$(1)))
31 dep_if=$(if $(findstring !,$(1)),$(call dep_neg,$(1)),$(call dep_pos,$(1)))
32 dep_val=$(word 2,$(call dep_split,$(1)))
33 strip_deps=$(strip $(subst +,,$(filter-out @%,$(1))))
34 filter_deps=$(foreach dep,$(call strip_deps,$(1)),$(if $(findstring :,$(dep)),$(call dep_if,$(dep)),$(dep)))
37 $$(if $(1),$$(if $(2),$$(foreach pkg,$(1),$$(IPKG_$$(pkg))): $$(foreach pkg,$(2),$$(IPKG_$$(pkg)))))
40 define FixupReverseDependencies
41 DEPS := $$(filter %:$(1),$$(IDEPEND))
42 DEPS := $$(patsubst %:$(1),%,$$(DEPS))
43 DEPS := $$(filter $$(DEPS),$$(IPKGS))
44 $(call AddDependency,$$(DEPS),$(1))
47 define FixupDependencies
48 DEPS := $$(filter $(1):%,$$(IDEPEND))
49 DEPS := $$(patsubst $(1):%,%,$$(DEPS))
50 DEPS := $$(filter $$(DEPS),$$(IPKGS))
51 $(call AddDependency,$(1),$$(DEPS))
54 ifneq ($(PKG_NAME),toolchain)
55 define CheckDependencies
57 rm -f $(PKG_INFO_DIR)/$(1).missing; \
60 READELF=$(TARGET_CROSS)readelf \
61 OBJCOPY=$(TARGET_CROSS)objcopy \
63 $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
64 ) | while read FILE; do \
65 grep -q "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
66 echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
68 if [ -f "$(PKG_INFO_DIR)/$(1).missing" ]; then \
69 echo "Package $(1) is missing dependencies for the following libraries:" >&2; \
70 cat "$(PKG_INFO_DIR)/$(1).missing" >&2; \
78 define BuildTarget/ipkg
79 PDIR_$(1):=$(call FeedPackageDir,$(1))
80 IPKG_$(1):=$$(PDIR_$(1))/$(1)_$(VERSION)_$(PKGARCH).ipk
81 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
82 KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
84 ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
85 ifdef Package/$(1)/install
86 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
88 compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
89 ifneq ($(ABI_VERSION),)
90 compile: $(PKG_INFO_DIR)/$(1).version
93 ifeq ($(CONFIG_PACKAGE_$(1)),y)
94 .PHONY: $(PKG_INSTALL_STAMP).$(1)
95 compile: $(PKG_INSTALL_STAMP).$(1)
96 $(PKG_INSTALL_STAMP).$(1):
97 if [ -f $(PKG_INSTALL_STAMP).clean ]; then \
99 $(PKG_INSTALL_STAMP) \
100 $(PKG_INSTALL_STAMP).clean; \
102 echo "$(1)" >> $(PKG_INSTALL_STAMP)
105 compile: $(1)-disabled
107 @echo "WARNING: skipping $(1) -- package not selected" >&2
112 DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
113 IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
114 IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
116 $(FixupReverseDependencies)
118 $(eval $(call BuildIPKGVariable,$(1),conffiles))
119 $(eval $(call BuildIPKGVariable,$(1),preinst))
120 $(eval $(call BuildIPKGVariable,$(1),postinst))
121 $(eval $(call BuildIPKGVariable,$(1),prerm))
122 $(eval $(call BuildIPKGVariable,$(1),postrm))
124 $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(STAMP_BUILT)
125 rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
126 mkdir -p $(STAGING_DIR_ROOT)/stamp $(STAGING_DIR_ROOT)/tmp-$(1)
127 $(call Package/$(1)/install,$(STAGING_DIR_ROOT)/tmp-$(1))
128 $(call Package/$(1)/install_lib,$(STAGING_DIR_ROOT)/tmp-$(1))
129 $(call locked,$(CP) $(STAGING_DIR_ROOT)/tmp-$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
130 rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
133 $(PKG_INFO_DIR)/$(1).version: $$(IPKG_$(1))
134 echo '$(ABI_VERSION)' | cmp -s - $$@ || \
135 echo '$(ABI_VERSION)' > $$@
137 $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1))
138 $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
139 @rm -rf $(PACKAGE_DIR)/$(1)_* $$(IDIR_$(1))
140 mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
141 $(call Package/$(1)/install,$$(IDIR_$(1)))
142 -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
144 find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
145 for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
146 if [ -f "$$$$file" ]; then \
149 done; $(Package/$(1)/extra_provides) \
150 ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
151 $(if $(PROVIDES),@for pkg in $(PROVIDES); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
154 $(RSTRIP) $$(IDIR_$(1))
156 echo "Package: $(1)"; \
157 echo "Version: $(VERSION)"; \
158 DEPENDS='$(EXTRA_DEPENDS)'; \
159 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
160 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
162 [ -z "$$$$DEPENDS" ] || echo "Depends: $$$$DEPENDS"; \
163 $(if $(PROVIDES), echo "Provides: $(PROVIDES)"; ) \
164 echo "Source: $(SOURCE)"; \
165 $(if $(PKG_LICENSE), echo "License: $(PKG_LICENSE)"; ) \
166 $(if $(PKG_LICENSE_FILES), echo "LicenseFiles: $(PKG_LICENSE_FILES)"; ) \
167 echo "Section: $(SECTION)"; \
168 $(if $(filter hold,$(PKG_FLAGS)),echo "Status: unknown hold not-installed"; ) \
169 $(if $(filter essential,$(PKG_FLAGS)), echo "Essential: yes"; ) \
170 $(if $(MAINTAINER),echo "Maintainer: $(MAINTAINER)"; ) \
171 echo "Architecture: $(PKGARCH)"; \
172 echo "Installed-Size: 0"; \
173 echo -n "Description: "; $(SH_FUNC) getvar $(call shvar,Package/$(1)/description) | sed -e 's,^[[:space:]]*, ,g'; \
174 ) > $$(IDIR_$(1))/CONTROL/control
175 chmod 644 $$(IDIR_$(1))/CONTROL/control
176 $(SH_FUNC) (cd $$(IDIR_$(1))/CONTROL; \
180 ifneq ($$(KEEP_$(1)),)
183 for x in $$(KEEP_$(1)); do \
184 [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
186 [ -z "$$$$keepfiles" ] || { \
187 mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
188 for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
193 $(INSTALL_DIR) $$(PDIR_$(1))
194 $(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
195 @[ -f $$(IPKG_$(1)) ]
198 rm -f $$(PDIR_$(1))/$(1)_*