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
14 include $(INCLUDE_DIR)/host.mk
15 include $(INCLUDE_DIR)/unpack.mk
17 export CONFIG_SITE:=$(INCLUDE_DIR)/site/$(REAL_GNU_TARGET_NAME)
20 V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
24 $(call shvar,$(1))=$$(call $(1))
25 export $(call shvar,$(1))
28 define Build/DefaultTargets
30 ifeq ($(CONFIG_AUTOREBUILD),y)
32 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
33 _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
34 $(PKG_BUILD_DIR)/.prepared: package-clean
39 $(PKG_BUILD_DIR)/.prepared:
40 @-rm -rf $(PKG_BUILD_DIR)
41 @mkdir -p $(PKG_BUILD_DIR)
45 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
46 $(call Build/Configure)
49 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
53 ifdef Build/InstallDev
54 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)
55 $(PKG_BUILD_DIR)/.built: package-rebuild
58 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
59 mkdir -p $(STAGING_DIR)/stampfiles
60 $(call Build/InstallDev)
63 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
68 $(call Build/UninstallDev)
69 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
71 package-rebuild: FORCE
72 @-rm -f $(PKG_BUILD_DIR)/.built
74 define Build/DefaultTargets
78 define Package/Default
81 CATEGORY:=Extra packages
85 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
86 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
87 ifneq ($(PKG_VERSION),)
88 ifneq ($(PKG_RELEASE),)
89 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
91 VERSION:=$(PKG_VERSION)
94 VERSION:=$(PKG_RELEASE)
106 define BuildDescription
107 ifneq ($(DESCRIPTION),)
108 DESCRIPTION:=$(TITLE)\\ $(DESCRIPTION)
110 DESCRIPTION:=$(TITLE)
114 define BuildIPKGVariable
115 $(call shexport,Package/$(1)/$(2))
116 $(1)_COMMANDS += var2file "$(call shvar,Package/$(1)/$(2))" $(2);
120 $(eval $(call Package/Default))
121 $(eval $(call Package/$(1)))
122 $(eval $(call BuildDescription))
124 $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
126 $$(error Package/$(1) is missing the $(FIELD) field)
130 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
131 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
132 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
134 ifdef Package/$(1)/install
135 ifeq ($(CONFIG_PACKAGE_$(1)),y)
136 install-targets: $$(INFO_$(1))
139 ifneq ($(CONFIG_PACKAGE_$(1)),)
140 compile-targets: $$(IPKG_$(1))
142 compile-targets: $(1)-disabled
144 @echo "WARNING: skipping $(1) -- package not selected"
148 ifeq ($(FORCEREBUILD),y)
152 IDEPEND_$(1):=$$(strip $$(DEPENDS))
156 echo "Package: $(1)";
160 echo "Menu: $(MENU)";
165 echo "Submenu: $(SUBMENU)";
166 ifneq ($(SUBMENUDEP),)
168 echo "Submenu-Depends: $(SUBMENUDEP)";
174 echo "Default: $(DEFAULT)";
177 $(call shexport,Package/$(1)/description)
180 if [ "$$$$PREREQ_CHECK" = 1 ]; then echo "Prereq-Check: 1"; fi; \
181 echo "Version: $(VERSION)"; \
182 echo "Depends: $$(IDEPEND_$(1))"; \
183 echo "Provides: $(PROVIDES)"; \
184 echo "Build-Depends: $(PKG_BUILDDEP)"; \
185 echo "Category: $(CATEGORY)"; \
186 echo "Title: $(TITLE)"; \
187 if isset $(call shvar,Package/$(1)/description); then \
188 echo -n "Description: "; \
189 getvar $(call shvar,Package/$(1)/description); \
191 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g'; \
203 $(call shexport,Package/$(1)/config)
205 if isset $(call shvar,Package/$(1)/config); then echo "Config: "; getvar $(call shvar,Package/$(1)/config); fi; \
210 $(eval $(call BuildIPKGVariable,$(1),conffiles))
211 $(eval $(call BuildIPKGVariable,$(1),preinst))
212 $(eval $(call BuildIPKGVariable,$(1),postinst))
213 $(eval $(call BuildIPKGVariable,$(1),prerm))
214 $(eval $(call BuildIPKGVariable,$(1),postrm))
215 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
216 mkdir -p $$(IDIR_$(1))/CONTROL
217 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
218 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
221 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
222 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
224 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
226 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
227 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
228 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
229 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
230 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
231 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g' | sed -e 's,^[[:space:]]*$$$$, .,g' >> $$(IDIR_$(1))/CONTROL/control
232 chmod 644 $$(IDIR_$(1))/CONTROL/control
233 (cd $$(IDIR_$(1))/CONTROL; \
237 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
238 $(call Package/$(1)/install,$$(IDIR_$(1)))
239 mkdir -p $(PACKAGE_DIR)
240 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
241 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
242 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
243 $(RSTRIP) $$(IDIR_$(1))
244 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
245 @[ -f $$(IPKG_$(1)) ] || false
247 $$(INFO_$(1)): $$(IPKG_$(1))
248 $(IPKG) install $$(IPKG_$(1))
251 rm -f $(PACKAGE_DIR)/$(1)_*
255 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
256 -@rm -f $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
259 $$(eval $$(call Build/DefaultTargets,$(1)))
261 ifdef Package/$(1)/install
262 ifneq ($$(CONFIG_PACKAGE_$(1)),)
263 ifneq ($(MAKECMDGOALS),prereq)
265 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install '$$(IPKG_$(1))' '$(PKG_BUILD_DIR)'),$$(IPKG_$(1)))
266 _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
267 $(PKG_BUILD_DIR)/.built: package-rebuild
271 $$(info Rebuilding $$(_INFO))
279 ifneq ($(strip $(PKG_UNPACK)),)
280 define Build/Prepare/Default
282 @if [ -d ./patches -a "$$$$(ls ./patches | wc -l)" -gt 0 ]; then \
283 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
289 $(call Build/Prepare/Default,)
292 define Build/Configure/Default
293 (cd $(PKG_BUILD_DIR)/$(3); \
294 if [ -x configure ]; then \
295 $(TARGET_CONFIGURE_OPTS) \
296 CFLAGS="$(TARGET_CFLAGS)" \
297 CXXFLAGS="$(TARGET_CFLAGS)" \
298 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
299 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
300 PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
303 --target=$(GNU_TARGET_NAME) \
304 --host=$(GNU_TARGET_NAME) \
305 --build=$(GNU_HOST_NAME) \
306 --program-prefix="" \
307 --program-suffix="" \
311 --sbindir=/usr/sbin \
312 --libexecdir=/usr/lib \
314 --datadir=/usr/share \
315 --localstatedir=/var \
317 --infodir=/usr/info \
324 define Build/Configure
325 $(call Build/Configure/Default,)
328 define Build/Compile/Default
329 $(MAKE) -C $(PKG_BUILD_DIR) \
330 $(TARGET_CONFIGURE_OPTS) \
331 CROSS="$(TARGET_CROSS)" \
332 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include " \
333 EXTRA_LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib " \
339 $(call Build/Compile/Default,)
349 ifneq ($(strip $(PKG_SOURCE)),)
350 download: $(DL_DIR)/$(PKG_SOURCE)
352 $(DL_DIR)/$(PKG_SOURCE):
354 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
356 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
360 prepare: $(PKG_BUILD_DIR)/.prepared
361 configure: $(PKG_BUILD_DIR)/.configured
364 compile: compile-targets
367 install: install-targets
371 @$(MAKE) clean-targets
373 rm -rf $(PKG_BUILD_DIR)