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)
18 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
19 $(PKG_BUILD_DIR)/.prepared: package-clean
22 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install $(IPKG_$(1)) $(PKG_BUILD_DIR)),$(IPKG_$(1)))
23 $(PKG_BUILD_DIR)/.built: package-rebuild
28 $(PKG_BUILD_DIR)/.prepared:
29 @-rm -rf $(PKG_BUILD_DIR)
30 @mkdir -p $(PKG_BUILD_DIR)
34 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
35 $(call Build/Configure)
38 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
42 ifdef Build/InstallDev
43 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
44 mkdir -p $(STAGING_DIR)/stampfiles
45 $(call Build/InstallDev)
48 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
53 $(call Build/UninstallDev)
54 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
56 package-rebuild: FORCE
57 @-rm -f $(PKG_BUILD_DIR)/.built
59 define Build/DefaultTargets
63 define Package/Default
66 CATEGORY:=Extra packages
69 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
70 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
71 ifneq ($(PKG_VERSION),)
72 ifneq ($(PKG_RELEASE),)
73 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
75 VERSION:=$(PKG_VERSION)
78 VERSION:=$(PKG_RELEASE)
90 define BuildIPKGVariable
91 pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
92 export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
93 $(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi;
97 $(eval $(call Package/Default))
98 $(eval $(call Package/$(1)))
100 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
102 $$(error Package/$(1) is missing the $(FIELD) field)
110 ifeq ($(DESCRIPTION),)
111 $(eval DESCRIPTION:=$(TITLE))
114 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
115 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
116 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
118 ifdef Package/$(1)/install
119 ifeq ($(CONFIG_PACKAGE_$(1)),y)
120 install-targets: $$(INFO_$(1))
123 ifneq ($(CONFIG_PACKAGE_$(1)),)
124 compile-targets: $$(IPKG_$(1))
128 ifeq ($(FORCEREBUILD),y)
132 IDEPEND_$(1):=$$(strip $$(DEPENDS))
136 echo "Package: $(1)";
140 echo "Menu: $(MENU)";
145 echo "Submenu: $(SUBMENU)";
146 ifneq ($(SUBMENUDEP),)
148 echo "Submenu-Depends: $(SUBMENUDEP)";
154 echo "Default: $(DEFAULT)";
158 echo "Version: $(VERSION)"; \
159 echo "Depends: $$(IDEPEND_$(1))"; \
160 echo "Build-Depends: $(PKG_BUILDDEP)"; \
161 echo "Category: $(CATEGORY)"; \
162 echo "Title: $(TITLE)"; \
163 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
176 echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
181 $(eval $(call BuildIPKGVariable,$(1),conffiles))
182 $(eval $(call BuildIPKGVariable,$(1),preinst))
183 $(eval $(call BuildIPKGVariable,$(1),postinst))
184 $(eval $(call BuildIPKGVariable,$(1),prerm))
185 $(eval $(call BuildIPKGVariable,$(1),postrm))
186 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
187 mkdir -p $$(IDIR_$(1))/CONTROL
188 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
189 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
192 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
193 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
195 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
197 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
198 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
199 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
200 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
201 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
202 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
203 chmod 644 $$(IDIR_$(1))/CONTROL/control
204 (cd $$(IDIR_$(1))/CONTROL; \
208 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
209 $(call Package/$(1)/install,$$(IDIR_$(1)))
210 mkdir -p $(PACKAGE_DIR)
211 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
212 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
213 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
214 $(RSTRIP) $$(IDIR_$(1))
215 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
216 @[ -f $$(IPKG_$(1)) ] || false
218 $$(INFO_$(1)): $$(IPKG_$(1))
219 $(IPKG) install $$(IPKG_$(1))
222 rm -f $(PACKAGE_DIR)/$(1)_*
226 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
227 -rm $(PKG_BUILD_DIR)/.version-$(1)_*
230 $$(eval $$(call Build/DefaultTargets,$(1)))
233 ifneq ($(strip $(PKG_CAT)),)
234 ifeq ($(PKG_CAT),unzip)
235 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
237 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
239 define Build/Prepare/Default
241 @if [ -d ./patches ]; then \
242 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
248 $(call Build/Prepare/Default)
251 define Build/Configure/Default
252 @(cd $(PKG_BUILD_DIR)/$(3); \
253 [ -x configure ] && \
255 $(TARGET_CONFIGURE_OPTS) \
256 CFLAGS="$(TARGET_CFLAGS)" \
257 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
258 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
260 --target=$(GNU_TARGET_NAME) \
261 --host=$(GNU_TARGET_NAME) \
262 --build=$(GNU_HOST_NAME) \
263 --program-prefix="" \
264 --program-suffix="" \
268 --sbindir=/usr/sbin \
269 --libexecdir=/usr/lib \
271 --datadir=/usr/share \
272 --localstatedir=/var \
274 --infodir=/usr/info \
281 define Build/Configure
282 $(call Build/Configure/Default,)
285 define Build/Compile/Default
286 PATH=$(TARGET_PATH) $(MAKE) -C $(PKG_BUILD_DIR) \
287 $(TARGET_CONFIGURE_OPTS) \
288 CROSS="$(TARGET_CROSS)" \
289 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include" \
295 $(call Build/Compile/Default,)
305 ifneq ($(strip $(PKG_SOURCE)),)
306 download: $(DL_DIR)/$(PKG_SOURCE)
308 $(DL_DIR)/$(PKG_SOURCE):
310 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
312 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
316 prepare: $(PKG_BUILD_DIR)/.prepared
317 configure: $(PKG_BUILD_DIR)/.configured
320 compile: compile-targets
323 install: install-targets
327 @$(MAKE) clean-targets
329 rm -rf $(PKG_BUILD_DIR)