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
18 V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
22 $(call shvar,$(1))=$$(call $(1))
23 export $(call shvar,$(1))
26 define Build/DefaultTargets
28 ifeq ($(CONFIG_AUTOREBUILD),y)
30 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
31 _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
32 $(PKG_BUILD_DIR)/.prepared: package-clean
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 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)
53 $(PKG_BUILD_DIR)/.built: package-rebuild
56 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
57 mkdir -p $(STAGING_DIR)/stampfiles
58 $(call Build/InstallDev)
61 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
66 $(call Build/UninstallDev)
67 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
69 package-rebuild: FORCE
70 @-rm -f $(PKG_BUILD_DIR)/.built
72 define Build/DefaultTargets
76 define Package/Default
79 CATEGORY:=Extra packages
82 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
83 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
84 ifneq ($(PKG_VERSION),)
85 ifneq ($(PKG_RELEASE),)
86 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
88 VERSION:=$(PKG_VERSION)
91 VERSION:=$(PKG_RELEASE)
103 define BuildDescription
104 ifneq ($(DESCRIPTION),)
105 DESCRIPTION:=$(TITLE)\\ $(DESCRIPTION)
107 DESCRIPTION:=$(TITLE)
111 define BuildIPKGVariable
112 $(call shexport,Package/$(1)/$(2))
113 $(1)_COMMANDS += var2file "$(call shvar,Package/$(1)/$(2))" $(2);
117 $(eval $(call Package/Default))
118 $(eval $(call Package/$(1)))
119 $(eval $(call BuildDescription))
121 $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
123 $$(error Package/$(1) is missing the $(FIELD) field)
127 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
128 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
129 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
131 ifdef Package/$(1)/install
132 ifeq ($(CONFIG_PACKAGE_$(1)),y)
133 install-targets: $$(INFO_$(1))
136 ifneq ($(CONFIG_PACKAGE_$(1)),)
137 compile-targets: $$(IPKG_$(1))
139 compile-targets: $(1)-disabled
141 @echo "WARNING: skipping $(1) -- package not selected"
145 ifeq ($(FORCEREBUILD),y)
149 IDEPEND_$(1):=$$(strip $$(DEPENDS))
153 echo "Package: $(1)";
157 echo "Menu: $(MENU)";
162 echo "Submenu: $(SUBMENU)";
163 ifneq ($(SUBMENUDEP),)
165 echo "Submenu-Depends: $(SUBMENUDEP)";
171 echo "Default: $(DEFAULT)";
174 $(call shexport,Package/$(1)/description)
177 if [ "$$$$PREREQ_CHECK" = 1 ]; then echo "Prereq-Check: 1"; fi; \
178 echo "Version: $(VERSION)"; \
179 echo "Depends: $$(IDEPEND_$(1))"; \
180 echo "Build-Depends: $(PKG_BUILDDEP)"; \
181 echo "Category: $(CATEGORY)"; \
182 echo "Title: $(TITLE)"; \
183 if isset $(call shvar,Package/$(1)/description); then \
184 echo -n "Description: "; \
185 getvar $(call shvar,Package/$(1)/description); \
187 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g'; \
199 $(call shexport,Package/$(1)/config)
201 if isset $(call shvar,Package/$(1)/config); then echo "Config: "; getvar $(call shvar,Package/$(1)/config); fi; \
206 $(eval $(call BuildIPKGVariable,$(1),conffiles))
207 $(eval $(call BuildIPKGVariable,$(1),preinst))
208 $(eval $(call BuildIPKGVariable,$(1),postinst))
209 $(eval $(call BuildIPKGVariable,$(1),prerm))
210 $(eval $(call BuildIPKGVariable,$(1),postrm))
211 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
212 mkdir -p $$(IDIR_$(1))/CONTROL
213 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
214 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
217 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
218 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
220 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
222 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
223 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
224 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
225 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
226 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
227 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g' | sed -e 's,^[[:space:]]*$$$$, .,g' >> $$(IDIR_$(1))/CONTROL/control
228 chmod 644 $$(IDIR_$(1))/CONTROL/control
229 (cd $$(IDIR_$(1))/CONTROL; \
233 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
234 $(call Package/$(1)/install,$$(IDIR_$(1)))
235 mkdir -p $(PACKAGE_DIR)
236 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
237 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
238 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
239 $(RSTRIP) $$(IDIR_$(1))
240 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
241 @[ -f $$(IPKG_$(1)) ] || false
243 $$(INFO_$(1)): $$(IPKG_$(1))
244 $(IPKG) install $$(IPKG_$(1))
247 rm -f $(PACKAGE_DIR)/$(1)_*
251 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
252 -@rm $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
255 $$(eval $$(call Build/DefaultTargets,$(1)))
257 ifneq ($$(CONFIG_PACKAGE_$(1)),)
258 ifneq ($(MAKECMDGOALS),prereq)
260 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install '$$(IPKG_$(1))' '$(PKG_BUILD_DIR)'),$$(IPKG_$(1)))
261 _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
262 $(PKG_BUILD_DIR)/.built: package-rebuild
266 $$(info Rebuilding $$(_INFO))
273 ifneq ($(strip $(PKG_UNPACK)),)
274 define Build/Prepare/Default
276 @if [ -d ./patches ]; then \
277 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
283 $(call Build/Prepare/Default,)
286 define Build/Configure/Default
287 (cd $(PKG_BUILD_DIR)/$(3); \
288 if [ -x configure ]; then \
289 $(TARGET_CONFIGURE_OPTS) \
290 CFLAGS="$(TARGET_CFLAGS)" \
291 CXXFLAGS="$(TARGET_CFLAGS)" \
292 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
293 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
294 PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
297 --target=$(GNU_TARGET_NAME) \
298 --host=$(GNU_TARGET_NAME) \
299 --build=$(GNU_HOST_NAME) \
300 --program-prefix="" \
301 --program-suffix="" \
305 --sbindir=/usr/sbin \
306 --libexecdir=/usr/lib \
308 --datadir=/usr/share \
309 --localstatedir=/var \
311 --infodir=/usr/info \
318 define Build/Configure
319 $(call Build/Configure/Default,)
322 define Build/Compile/Default
323 $(MAKE) -C $(PKG_BUILD_DIR) \
324 $(TARGET_CONFIGURE_OPTS) \
325 CROSS="$(TARGET_CROSS)" \
326 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include " \
327 EXTRA_LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib " \
333 $(call Build/Compile/Default,)
343 ifneq ($(strip $(PKG_SOURCE)),)
344 download: $(DL_DIR)/$(PKG_SOURCE)
346 $(DL_DIR)/$(PKG_SOURCE):
348 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
350 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
354 prepare: $(PKG_BUILD_DIR)/.prepared
355 configure: $(PKG_BUILD_DIR)/.configured
358 compile: compile-targets
361 install: install-targets
365 @$(MAKE) clean-targets
367 rm -rf $(PKG_BUILD_DIR)