2 # Copyright (C) 2006 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
13 include $(INCLUDE_DIR)/prereq.mk
16 V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
20 $(call shvar,$(1))=$$(call $(1))
21 export $(call shvar,$(1))
24 define Build/DefaultTargets
26 ifeq ($(CONFIG_AUTOREBUILD),y)
28 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
29 _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
30 $(PKG_BUILD_DIR)/.prepared: package-clean
35 $(PKG_BUILD_DIR)/.prepared:
36 @-rm -rf $(PKG_BUILD_DIR)
37 @mkdir -p $(PKG_BUILD_DIR)
41 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
42 $(call Build/Configure)
45 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
49 ifdef Build/InstallDev
50 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed $(PKG_BUILD_DIR)),$(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed)
51 $(PKG_BUILD_DIR)/.built: package-rebuild
54 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
55 mkdir -p $(STAGING_DIR)/stampfiles
56 $(call Build/InstallDev)
59 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
64 $(call Build/UninstallDev)
65 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
67 package-rebuild: FORCE
68 @-rm -f $(PKG_BUILD_DIR)/.built
70 define Build/DefaultTargets
74 define Package/Default
77 CATEGORY:=Extra packages
80 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
81 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
82 ifneq ($(PKG_VERSION),)
83 ifneq ($(PKG_RELEASE),)
84 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
86 VERSION:=$(PKG_VERSION)
89 VERSION:=$(PKG_RELEASE)
101 define BuildDescription
102 ifneq ($(DESCRIPTION),)
103 DESCRIPTION:=$(TITLE)\\ $(DESCRIPTION)
105 DESCRIPTION:=$(TITLE)
109 define BuildIPKGVariable
110 $(call shexport,Package/$(1)/$(2))
111 $(1)_COMMANDS += var2file "$(call shvar,Package/$(1)/$(2))" $(2);
115 $(eval $(call Package/Default))
116 $(eval $(call Package/$(1)))
117 $(eval $(call BuildDescription))
119 $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
121 $$(error Package/$(1) is missing the $(FIELD) field)
125 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
126 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
127 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
129 ifdef Package/$(1)/install
130 ifeq ($(CONFIG_PACKAGE_$(1)),y)
131 install-targets: $$(INFO_$(1))
134 ifneq ($(CONFIG_PACKAGE_$(1)),)
135 compile-targets: $$(IPKG_$(1))
137 compile-targets: $(1)-disabled
139 @echo "WARNING: skipping $(1) -- package not selected"
143 ifeq ($(FORCEREBUILD),y)
147 IDEPEND_$(1):=$$(strip $$(DEPENDS))
151 echo "Package: $(1)";
155 echo "Menu: $(MENU)";
160 echo "Submenu: $(SUBMENU)";
161 ifneq ($(SUBMENUDEP),)
163 echo "Submenu-Depends: $(SUBMENUDEP)";
169 echo "Default: $(DEFAULT)";
173 if [ "$$$$PREREQ_CHECK" = 1 ]; then echo "Prereq-Check: 1"; fi; \
174 echo "Version: $(VERSION)"; \
175 echo "Depends: $$(IDEPEND_$(1))"; \
176 echo "Build-Depends: $(PKG_BUILDDEP)"; \
177 echo "Category: $(CATEGORY)"; \
178 echo "Title: $(TITLE)"; \
179 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g'; \
190 $(call shexport,Package/$(1)/config)
192 if isset $(call shvar,Package/$(1)/config); then echo "Config: "; getvar $(call shvar,Package/$(1)/config); fi; \
197 $(eval $(call BuildIPKGVariable,$(1),conffiles))
198 $(eval $(call BuildIPKGVariable,$(1),preinst))
199 $(eval $(call BuildIPKGVariable,$(1),postinst))
200 $(eval $(call BuildIPKGVariable,$(1),prerm))
201 $(eval $(call BuildIPKGVariable,$(1),postrm))
202 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
203 mkdir -p $$(IDIR_$(1))/CONTROL
204 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
205 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
208 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
209 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
211 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
213 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
214 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
215 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
216 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
217 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
218 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g' | sed -e 's,^[[:space:]]*$$$$, .,g' >> $$(IDIR_$(1))/CONTROL/control
219 chmod 644 $$(IDIR_$(1))/CONTROL/control
220 (cd $$(IDIR_$(1))/CONTROL; \
224 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
225 $(call Package/$(1)/install,$$(IDIR_$(1)))
226 mkdir -p $(PACKAGE_DIR)
227 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
228 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
229 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
230 $(RSTRIP) $$(IDIR_$(1))
231 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
232 @[ -f $$(IPKG_$(1)) ] || false
234 $$(INFO_$(1)): $$(IPKG_$(1))
235 $(IPKG) install $$(IPKG_$(1))
238 rm -f $(PACKAGE_DIR)/$(1)_*
242 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
243 -@rm $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
246 $$(eval $$(call Build/DefaultTargets,$(1)))
248 ifneq ($$(CONFIG_PACKAGE_$(1)),)
249 ifneq ($(MAKECMDGOALS),prereq)
251 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install '$$(IPKG_$(1))' '$(PKG_BUILD_DIR)'),$$(IPKG_$(1)))
252 _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
253 $(PKG_BUILD_DIR)/.built: package-rebuild
257 $$(info Rebuilding $$(_INFO))
264 ifneq ($(strip $(PKG_CAT)),)
265 ifeq ($(PKG_CAT),unzip)
266 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
268 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
270 define Build/Prepare/Default
272 @if [ -d ./patches ]; then \
273 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
279 $(call Build/Prepare/Default,)
282 define Build/Configure/Default
283 (cd $(PKG_BUILD_DIR)/$(3); \
284 if [ -x configure ]; then \
285 $(TARGET_CONFIGURE_OPTS) \
286 CFLAGS="$(TARGET_CFLAGS)" \
287 CXXFLAGS="$(TARGET_CFLAGS)" \
288 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
289 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
290 PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
293 --target=$(GNU_TARGET_NAME) \
294 --host=$(GNU_TARGET_NAME) \
295 --build=$(GNU_HOST_NAME) \
296 --program-prefix="" \
297 --program-suffix="" \
301 --sbindir=/usr/sbin \
302 --libexecdir=/usr/lib \
304 --datadir=/usr/share \
305 --localstatedir=/var \
307 --infodir=/usr/info \
314 define Build/Configure
315 $(call Build/Configure/Default,)
318 define Build/Compile/Default
319 $(MAKE) -C $(PKG_BUILD_DIR) \
320 $(TARGET_CONFIGURE_OPTS) \
321 CROSS="$(TARGET_CROSS)" \
322 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include " \
323 EXTRA_LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib " \
329 $(call Build/Compile/Default,)
339 ifneq ($(strip $(PKG_SOURCE)),)
340 download: $(DL_DIR)/$(PKG_SOURCE)
342 $(DL_DIR)/$(PKG_SOURCE):
344 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
346 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
350 prepare: $(PKG_BUILD_DIR)/.prepared
351 configure: $(PKG_BUILD_DIR)/.configured
354 compile: compile-targets
357 install: install-targets
361 @$(MAKE) clean-targets
363 rm -rf $(PKG_BUILD_DIR)