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
26 $(PKG_BUILD_DIR)/.prepared:
27 @-rm -rf $(PKG_BUILD_DIR)
28 @mkdir -p $(PKG_BUILD_DIR)
32 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
33 $(call Build/Configure)
36 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
40 ifdef Build/InstallDev
41 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)
42 $(PKG_BUILD_DIR)/.built: package-rebuild
45 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
46 mkdir -p $(STAGING_DIR)/stampfiles
47 $(call Build/InstallDev)
50 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
55 $(call Build/UninstallDev)
56 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
58 package-rebuild: FORCE
59 @-rm -f $(PKG_BUILD_DIR)/.built
61 define Build/DefaultTargets
65 define Package/Default
68 CATEGORY:=Extra packages
71 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
72 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
73 ifneq ($(PKG_VERSION),)
74 ifneq ($(PKG_RELEASE),)
75 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
77 VERSION:=$(PKG_VERSION)
80 VERSION:=$(PKG_RELEASE)
92 define BuildDescription
93 ifneq ($(DESCRIPTION),)
94 DESCRIPTION:=$(TITLE)\\ $(DESCRIPTION)
100 define BuildIPKGVariable
101 pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
102 export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
103 $(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi;
107 $(eval $(call Package/Default))
108 $(eval $(call Package/$(1)))
109 $(eval $(call BuildDescription))
111 $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
113 $$(error Package/$(1) is missing the $(FIELD) field)
117 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
118 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
119 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
121 ifdef Package/$(1)/install
122 ifeq ($(CONFIG_PACKAGE_$(1)),y)
123 install-targets: $$(INFO_$(1))
126 ifneq ($(CONFIG_PACKAGE_$(1)),)
127 compile-targets: $$(IPKG_$(1))
129 compile-targets: $(1)-disabled
131 @echo "WARNING: skipping $(1) -- package not selected"
135 ifeq ($(FORCEREBUILD),y)
139 IDEPEND_$(1):=$$(strip $$(DEPENDS))
143 echo "Package: $(1)";
147 echo "Menu: $(MENU)";
152 echo "Submenu: $(SUBMENU)";
153 ifneq ($(SUBMENUDEP),)
155 echo "Submenu-Depends: $(SUBMENUDEP)";
161 echo "Default: $(DEFAULT)";
165 if [ "$$$$PREREQ_CHECK" = 1 ]; then echo "Prereq-Check: 1"; fi; \
166 echo "Version: $(VERSION)"; \
167 echo "Depends: $$(IDEPEND_$(1))"; \
168 echo "Build-Depends: $(PKG_BUILDDEP)"; \
169 echo "Category: $(CATEGORY)"; \
170 echo "Title: $(TITLE)"; \
171 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
184 echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
189 $(eval $(call BuildIPKGVariable,$(1),conffiles))
190 $(eval $(call BuildIPKGVariable,$(1),preinst))
191 $(eval $(call BuildIPKGVariable,$(1),postinst))
192 $(eval $(call BuildIPKGVariable,$(1),prerm))
193 $(eval $(call BuildIPKGVariable,$(1),postrm))
194 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
195 mkdir -p $$(IDIR_$(1))/CONTROL
196 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
197 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
200 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
201 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
203 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
205 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
206 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
207 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
208 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
209 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
210 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g' | sed -e 's,^[[:space:]]*$$$$, .,g' >> $$(IDIR_$(1))/CONTROL/control
211 chmod 644 $$(IDIR_$(1))/CONTROL/control
212 (cd $$(IDIR_$(1))/CONTROL; \
216 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
217 $(call Package/$(1)/install,$$(IDIR_$(1)))
218 mkdir -p $(PACKAGE_DIR)
219 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
220 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
221 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
222 $(RSTRIP) $$(IDIR_$(1))
223 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
224 @[ -f $$(IPKG_$(1)) ] || false
226 $$(INFO_$(1)): $$(IPKG_$(1))
227 $(IPKG) install $$(IPKG_$(1))
230 rm -f $(PACKAGE_DIR)/$(1)_*
234 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
235 -@rm $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
238 $$(eval $$(call Build/DefaultTargets,$(1)))
240 ifneq ($$(CONFIG_PACKAGE_$(1)),)
241 ifneq ($(MAKECMDGOALS),prereq)
243 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install '$$(IPKG_$(1))' '$(PKG_BUILD_DIR)'),$$(IPKG_$(1)))
244 _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
245 $(PKG_BUILD_DIR)/.built: package-rebuild
249 $$(info Rebuilding $$(_INFO))
256 ifneq ($(strip $(PKG_CAT)),)
257 ifeq ($(PKG_CAT),unzip)
258 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
260 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
262 define Build/Prepare/Default
264 @if [ -d ./patches ]; then \
265 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
271 $(call Build/Prepare/Default,)
274 define Build/Configure/Default
275 (cd $(PKG_BUILD_DIR)/$(3); \
276 if [ -x configure ]; then \
277 $(TARGET_CONFIGURE_OPTS) \
278 CFLAGS="$(TARGET_CFLAGS)" \
279 CXXFLAGS="$(TARGET_CFLAGS)" \
280 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
281 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
282 PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
285 --target=$(GNU_TARGET_NAME) \
286 --host=$(GNU_TARGET_NAME) \
287 --build=$(GNU_HOST_NAME) \
288 --program-prefix="" \
289 --program-suffix="" \
293 --sbindir=/usr/sbin \
294 --libexecdir=/usr/lib \
296 --datadir=/usr/share \
297 --localstatedir=/var \
299 --infodir=/usr/info \
306 define Build/Configure
307 $(call Build/Configure/Default,)
310 define Build/Compile/Default
311 $(MAKE) -C $(PKG_BUILD_DIR) \
312 $(TARGET_CONFIGURE_OPTS) \
313 CROSS="$(TARGET_CROSS)" \
314 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include " \
315 EXTRA_LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib " \
321 $(call Build/Compile/Default,)
331 ifneq ($(strip $(PKG_SOURCE)),)
332 download: $(DL_DIR)/$(PKG_SOURCE)
334 $(DL_DIR)/$(PKG_SOURCE):
336 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
338 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
342 prepare: $(PKG_BUILD_DIR)/.prepared
343 configure: $(PKG_BUILD_DIR)/.configured
346 compile: compile-targets
349 install: install-targets
353 @$(MAKE) clean-targets
355 rm -rf $(PKG_BUILD_DIR)