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
24 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install $(IPKG_$(1)) $(PKG_BUILD_DIR)),$(IPKG_$(1)))
25 _INFO+=$(subst $(TOPDIR)/,,$(IPKG_$(1)))
26 $(PKG_BUILD_DIR)/.built: package-rebuild
29 ifneq ($(MAKECMDGOALS),prereq)
31 $$(info Rebuilding $$(_INFO))
37 $(PKG_BUILD_DIR)/.prepared:
38 @-rm -rf $(PKG_BUILD_DIR)
39 @mkdir -p $(PKG_BUILD_DIR)
43 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
44 $(call Build/Configure)
47 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
51 ifdef Build/InstallDev
52 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
53 mkdir -p $(STAGING_DIR)/stampfiles
54 $(call Build/InstallDev)
57 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
62 $(call Build/UninstallDev)
63 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
65 package-rebuild: FORCE
66 @-rm -f $(PKG_BUILD_DIR)/.built
68 define Build/DefaultTargets
72 define Package/Default
75 CATEGORY:=Extra packages
78 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
79 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
80 ifneq ($(PKG_VERSION),)
81 ifneq ($(PKG_RELEASE),)
82 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
84 VERSION:=$(PKG_VERSION)
87 VERSION:=$(PKG_RELEASE)
99 define BuildIPKGVariable
100 pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
101 export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
102 $(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi;
106 $(eval $(call Package/Default))
107 $(eval $(call Package/$(1)))
109 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
111 $$(error Package/$(1) is missing the $(FIELD) field)
119 ifeq ($(DESCRIPTION),)
120 $(eval DESCRIPTION:=$(TITLE))
123 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
124 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
125 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
127 ifdef Package/$(1)/install
128 ifeq ($(CONFIG_PACKAGE_$(1)),y)
129 install-targets: $$(INFO_$(1))
132 ifneq ($(CONFIG_PACKAGE_$(1)),)
133 compile-targets: $$(IPKG_$(1))
135 compile-targets: $(1)-disabled
137 @echo "WARNING: skipping $(1) -- package not selected"
141 ifeq ($(FORCEREBUILD),y)
145 IDEPEND_$(1):=$$(strip $$(DEPENDS))
149 echo "Package: $(1)";
153 echo "Menu: $(MENU)";
158 echo "Submenu: $(SUBMENU)";
159 ifneq ($(SUBMENUDEP),)
161 echo "Submenu-Depends: $(SUBMENUDEP)";
167 echo "Default: $(DEFAULT)";
171 echo "Version: $(VERSION)"; \
172 echo "Depends: $$(IDEPEND_$(1))"; \
173 echo "Build-Depends: $(PKG_BUILDDEP)"; \
174 echo "Category: $(CATEGORY)"; \
175 echo "Title: $(TITLE)"; \
176 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
189 echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
194 $(eval $(call BuildIPKGVariable,$(1),conffiles))
195 $(eval $(call BuildIPKGVariable,$(1),preinst))
196 $(eval $(call BuildIPKGVariable,$(1),postinst))
197 $(eval $(call BuildIPKGVariable,$(1),prerm))
198 $(eval $(call BuildIPKGVariable,$(1),postrm))
199 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
200 mkdir -p $$(IDIR_$(1))/CONTROL
201 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
202 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
205 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
206 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
208 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
210 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
211 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
212 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
213 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
214 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
215 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
216 chmod 644 $$(IDIR_$(1))/CONTROL/control
217 (cd $$(IDIR_$(1))/CONTROL; \
221 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
222 $(call Package/$(1)/install,$$(IDIR_$(1)))
223 mkdir -p $(PACKAGE_DIR)
224 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
225 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
226 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
227 $(RSTRIP) $$(IDIR_$(1))
228 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
229 @[ -f $$(IPKG_$(1)) ] || false
231 $$(INFO_$(1)): $$(IPKG_$(1))
232 $(IPKG) install $$(IPKG_$(1))
235 rm -f $(PACKAGE_DIR)/$(1)_*
239 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
240 -rm $(PKG_BUILD_DIR)/.version-$(1)_*
243 $$(eval $$(call Build/DefaultTargets,$(1)))
246 ifneq ($(strip $(PKG_CAT)),)
247 ifeq ($(PKG_CAT),unzip)
248 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
250 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
252 define Build/Prepare/Default
254 @if [ -d ./patches ]; then \
255 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
261 $(call Build/Prepare/Default)
264 define Build/Configure/Default
265 @(cd $(PKG_BUILD_DIR)/$(3); \
266 [ -x configure ] && \
267 $(TARGET_CONFIGURE_OPTS) \
268 CFLAGS="$(TARGET_CFLAGS)" \
269 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
270 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
273 --target=$(GNU_TARGET_NAME) \
274 --host=$(GNU_TARGET_NAME) \
275 --build=$(GNU_HOST_NAME) \
276 --program-prefix="" \
277 --program-suffix="" \
281 --sbindir=/usr/sbin \
282 --libexecdir=/usr/lib \
284 --datadir=/usr/share \
285 --localstatedir=/var \
287 --infodir=/usr/info \
294 define Build/Configure
295 $(call Build/Configure/Default,)
298 define Build/Compile/Default
299 $(MAKE) -C $(PKG_BUILD_DIR) \
300 $(TARGET_CONFIGURE_OPTS) \
301 CROSS="$(TARGET_CROSS)" \
302 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include" \
308 $(call Build/Compile/Default,)
318 ifneq ($(strip $(PKG_SOURCE)),)
319 download: $(DL_DIR)/$(PKG_SOURCE)
321 $(DL_DIR)/$(PKG_SOURCE):
323 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
325 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
329 prepare: $(PKG_BUILD_DIR)/.prepared
330 configure: $(PKG_BUILD_DIR)/.configured
333 compile: compile-targets
336 install: install-targets
340 @$(MAKE) clean-targets
342 rm -rf $(PKG_BUILD_DIR)