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
15 define Build/DefaultTargets
17 ifeq ($(CONFIG_AUTOREBUILD),y)
19 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
20 _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
21 $(PKG_BUILD_DIR)/.prepared: package-clean
27 $(PKG_BUILD_DIR)/.prepared:
28 @-rm -rf $(PKG_BUILD_DIR)
29 @mkdir -p $(PKG_BUILD_DIR)
33 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
34 $(call Build/Configure)
37 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
41 ifdef Build/InstallDev
42 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
43 mkdir -p $(STAGING_DIR)/stampfiles
44 $(call Build/InstallDev)
47 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
52 $(call Build/UninstallDev)
53 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
55 package-rebuild: FORCE
56 @-rm -f $(PKG_BUILD_DIR)/.built
58 define Build/DefaultTargets
62 define Package/Default
65 CATEGORY:=Extra packages
68 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
69 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
70 ifneq ($(PKG_VERSION),)
71 ifneq ($(PKG_RELEASE),)
72 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
74 VERSION:=$(PKG_VERSION)
77 VERSION:=$(PKG_RELEASE)
89 define BuildIPKGVariable
90 pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
91 export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
92 $(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi;
96 $(eval $(call Package/Default))
97 $(eval $(call Package/$(1)))
99 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
101 $$(error Package/$(1) is missing the $(FIELD) field)
109 ifeq ($(DESCRIPTION),)
110 $(eval DESCRIPTION:=$(TITLE))
113 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
114 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
115 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
117 ifdef Package/$(1)/install
118 ifeq ($(CONFIG_PACKAGE_$(1)),y)
119 install-targets: $$(INFO_$(1))
122 ifneq ($(CONFIG_PACKAGE_$(1)),)
123 compile-targets: $$(IPKG_$(1))
125 compile-targets: $(1)-disabled
127 @echo "WARNING: skipping $(1) -- package not selected"
131 ifeq ($(FORCEREBUILD),y)
135 IDEPEND_$(1):=$$(strip $$(DEPENDS))
139 echo "Package: $(1)";
143 echo "Menu: $(MENU)";
148 echo "Submenu: $(SUBMENU)";
149 ifneq ($(SUBMENUDEP),)
151 echo "Submenu-Depends: $(SUBMENUDEP)";
157 echo "Default: $(DEFAULT)";
161 echo "Version: $(VERSION)"; \
162 echo "Depends: $$(IDEPEND_$(1))"; \
163 echo "Build-Depends: $(PKG_BUILDDEP)"; \
164 echo "Category: $(CATEGORY)"; \
165 echo "Title: $(TITLE)"; \
166 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
179 echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
184 $(eval $(call BuildIPKGVariable,$(1),conffiles))
185 $(eval $(call BuildIPKGVariable,$(1),preinst))
186 $(eval $(call BuildIPKGVariable,$(1),postinst))
187 $(eval $(call BuildIPKGVariable,$(1),prerm))
188 $(eval $(call BuildIPKGVariable,$(1),postrm))
189 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
190 mkdir -p $$(IDIR_$(1))/CONTROL
191 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
192 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
195 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
196 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
198 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
200 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
201 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
202 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
203 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
204 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
205 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
206 chmod 644 $$(IDIR_$(1))/CONTROL/control
207 (cd $$(IDIR_$(1))/CONTROL; \
211 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
212 $(call Package/$(1)/install,$$(IDIR_$(1)))
213 mkdir -p $(PACKAGE_DIR)
214 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
215 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
216 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
217 $(RSTRIP) $$(IDIR_$(1))
218 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
219 @[ -f $$(IPKG_$(1)) ] || false
221 $$(INFO_$(1)): $$(IPKG_$(1))
222 $(IPKG) install $$(IPKG_$(1))
225 rm -f $(PACKAGE_DIR)/$(1)_*
229 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
230 -@rm $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
233 $$(eval $$(call Build/DefaultTargets,$(1)))
235 ifneq ($$(CONFIG_PACKAGE_$(1)),)
236 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install $$(IPKG_$(1)) $(PKG_BUILD_DIR)),$$(IPKG_$(1)))
237 _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
238 $(PKG_BUILD_DIR)/.built: package-rebuild
241 ifneq ($(MAKECMDGOALS),prereq)
243 $$(info Rebuilding $$(_INFO))
249 ifneq ($(strip $(PKG_CAT)),)
250 ifeq ($(PKG_CAT),unzip)
251 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
253 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
255 define Build/Prepare/Default
257 @if [ -d ./patches ]; then \
258 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
264 $(call Build/Prepare/Default)
267 define Build/Configure/Default
268 @(cd $(PKG_BUILD_DIR)/$(3); \
269 if [ -x configure ]; then \
270 $(TARGET_CONFIGURE_OPTS) \
271 CFLAGS="$(TARGET_CFLAGS)" \
272 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
273 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
276 --target=$(GNU_TARGET_NAME) \
277 --host=$(GNU_TARGET_NAME) \
278 --build=$(GNU_HOST_NAME) \
279 --program-prefix="" \
280 --program-suffix="" \
284 --sbindir=/usr/sbin \
285 --libexecdir=/usr/lib \
287 --datadir=/usr/share \
288 --localstatedir=/var \
290 --infodir=/usr/info \
297 define Build/Configure
298 $(call Build/Configure/Default,)
301 define Build/Compile/Default
302 $(MAKE) -C $(PKG_BUILD_DIR) \
303 $(TARGET_CONFIGURE_OPTS) \
304 CROSS="$(TARGET_CROSS)" \
305 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include" \
311 $(call Build/Compile/Default,)
321 ifneq ($(strip $(PKG_SOURCE)),)
322 download: $(DL_DIR)/$(PKG_SOURCE)
324 $(DL_DIR)/$(PKG_SOURCE):
326 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
328 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
332 prepare: $(PKG_BUILD_DIR)/.prepared
333 configure: $(PKG_BUILD_DIR)/.configured
336 compile: compile-targets
339 install: install-targets
343 @$(MAKE) clean-targets
345 rm -rf $(PKG_BUILD_DIR)