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
17 V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
21 $(call shvar,$(1))=$$(call $(1))
22 export $(call shvar,$(1))
25 define Build/DefaultTargets
27 ifeq ($(CONFIG_AUTOREBUILD),y)
29 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
30 _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
31 $(PKG_BUILD_DIR)/.prepared: package-clean
36 $(PKG_BUILD_DIR)/.prepared:
37 @-rm -rf $(PKG_BUILD_DIR)
38 @mkdir -p $(PKG_BUILD_DIR)
42 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
43 $(call Build/Configure)
46 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
50 ifdef Build/InstallDev
51 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)
52 $(PKG_BUILD_DIR)/.built: package-rebuild
55 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
56 mkdir -p $(STAGING_DIR)/stampfiles
57 $(call Build/InstallDev)
60 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
65 $(call Build/UninstallDev)
66 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
68 package-rebuild: FORCE
69 @-rm -f $(PKG_BUILD_DIR)/.built
71 define Build/DefaultTargets
75 define Package/Default
78 CATEGORY:=Extra packages
81 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
82 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
83 ifneq ($(PKG_VERSION),)
84 ifneq ($(PKG_RELEASE),)
85 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
87 VERSION:=$(PKG_VERSION)
90 VERSION:=$(PKG_RELEASE)
102 define BuildDescription
103 ifneq ($(DESCRIPTION),)
104 DESCRIPTION:=$(TITLE)\\ $(DESCRIPTION)
106 DESCRIPTION:=$(TITLE)
110 define BuildIPKGVariable
111 $(call shexport,Package/$(1)/$(2))
112 $(1)_COMMANDS += var2file "$(call shvar,Package/$(1)/$(2))" $(2);
116 $(eval $(call Package/Default))
117 $(eval $(call Package/$(1)))
118 $(eval $(call BuildDescription))
120 $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
122 $$(error Package/$(1) is missing the $(FIELD) field)
126 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
127 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
128 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
130 ifdef Package/$(1)/install
131 ifeq ($(CONFIG_PACKAGE_$(1)),y)
132 install-targets: $$(INFO_$(1))
135 ifneq ($(CONFIG_PACKAGE_$(1)),)
136 compile-targets: $$(IPKG_$(1))
138 compile-targets: $(1)-disabled
140 @echo "WARNING: skipping $(1) -- package not selected"
144 ifeq ($(FORCEREBUILD),y)
148 IDEPEND_$(1):=$$(strip $$(DEPENDS))
152 echo "Package: $(1)";
156 echo "Menu: $(MENU)";
161 echo "Submenu: $(SUBMENU)";
162 ifneq ($(SUBMENUDEP),)
164 echo "Submenu-Depends: $(SUBMENUDEP)";
170 echo "Default: $(DEFAULT)";
173 $(call shexport,Package/$(1)/description)
176 if [ "$$$$PREREQ_CHECK" = 1 ]; then echo "Prereq-Check: 1"; fi; \
177 echo "Version: $(VERSION)"; \
178 echo "Depends: $$(IDEPEND_$(1))"; \
179 echo "Build-Depends: $(PKG_BUILDDEP)"; \
180 echo "Category: $(CATEGORY)"; \
181 echo "Title: $(TITLE)"; \
182 if isset $(call shvar,Package/$(1)/description); then \
183 echo -n "Description: "; \
184 getvar $(call shvar,Package/$(1)/description); \
186 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g'; \
198 $(call shexport,Package/$(1)/config)
200 if isset $(call shvar,Package/$(1)/config); then echo "Config: "; getvar $(call shvar,Package/$(1)/config); fi; \
205 $(eval $(call BuildIPKGVariable,$(1),conffiles))
206 $(eval $(call BuildIPKGVariable,$(1),preinst))
207 $(eval $(call BuildIPKGVariable,$(1),postinst))
208 $(eval $(call BuildIPKGVariable,$(1),prerm))
209 $(eval $(call BuildIPKGVariable,$(1),postrm))
210 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
211 mkdir -p $$(IDIR_$(1))/CONTROL
212 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
213 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
216 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
217 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
219 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
221 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
222 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
223 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
224 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
225 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
226 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g' | sed -e 's,^[[:space:]]*$$$$, .,g' >> $$(IDIR_$(1))/CONTROL/control
227 chmod 644 $$(IDIR_$(1))/CONTROL/control
228 (cd $$(IDIR_$(1))/CONTROL; \
232 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
233 $(call Package/$(1)/install,$$(IDIR_$(1)))
234 mkdir -p $(PACKAGE_DIR)
235 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
236 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
237 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
238 $(RSTRIP) $$(IDIR_$(1))
239 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
240 @[ -f $$(IPKG_$(1)) ] || false
242 $$(INFO_$(1)): $$(IPKG_$(1))
243 $(IPKG) install $$(IPKG_$(1))
246 rm -f $(PACKAGE_DIR)/$(1)_*
250 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
251 -@rm $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
254 $$(eval $$(call Build/DefaultTargets,$(1)))
256 ifneq ($$(CONFIG_PACKAGE_$(1)),)
257 ifneq ($(MAKECMDGOALS),prereq)
259 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install '$$(IPKG_$(1))' '$(PKG_BUILD_DIR)'),$$(IPKG_$(1)))
260 _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
261 $(PKG_BUILD_DIR)/.built: package-rebuild
265 $$(info Rebuilding $$(_INFO))
272 ifneq ($(strip $(PKG_CAT)),)
273 ifeq ($(PKG_CAT),unzip)
274 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
276 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
278 define Build/Prepare/Default
280 @if [ -d ./patches ]; then \
281 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
287 $(call Build/Prepare/Default,)
290 define Build/Configure/Default
291 (cd $(PKG_BUILD_DIR)/$(3); \
292 if [ -x configure ]; then \
293 $(TARGET_CONFIGURE_OPTS) \
294 CFLAGS="$(TARGET_CFLAGS)" \
295 CXXFLAGS="$(TARGET_CFLAGS)" \
296 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
297 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
298 PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
301 --target=$(GNU_TARGET_NAME) \
302 --host=$(GNU_TARGET_NAME) \
303 --build=$(GNU_HOST_NAME) \
304 --program-prefix="" \
305 --program-suffix="" \
309 --sbindir=/usr/sbin \
310 --libexecdir=/usr/lib \
312 --datadir=/usr/share \
313 --localstatedir=/var \
315 --infodir=/usr/info \
322 define Build/Configure
323 $(call Build/Configure/Default,)
326 define Build/Compile/Default
327 $(MAKE) -C $(PKG_BUILD_DIR) \
328 $(TARGET_CONFIGURE_OPTS) \
329 CROSS="$(TARGET_CROSS)" \
330 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include " \
331 EXTRA_LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib " \
337 $(call Build/Compile/Default,)
347 ifneq ($(strip $(PKG_SOURCE)),)
348 download: $(DL_DIR)/$(PKG_SOURCE)
350 $(DL_DIR)/$(PKG_SOURCE):
352 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
354 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
358 prepare: $(PKG_BUILD_DIR)/.prepared
359 configure: $(PKG_BUILD_DIR)/.configured
362 compile: compile-targets
365 install: install-targets
369 @$(MAKE) clean-targets
371 rm -rf $(PKG_BUILD_DIR)