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 export CONFIG_SITE:=$(INCLUDE_DIR)/site/$(REAL_GNU_TARGET_NAME)
20 define Build/DefaultTargets
22 ifeq ($(CONFIG_AUTOREBUILD),y)
24 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) . $(PKG_FILE_DEPEND)),$(PKG_BUILD_DIR))
25 _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
26 $(PKG_BUILD_DIR)/.prepared: package-clean
31 $(PKG_BUILD_DIR)/.prepared:
32 @-rm -rf $(PKG_BUILD_DIR)
33 @mkdir -p $(PKG_BUILD_DIR)
37 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
38 $(call Build/Configure)
41 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
45 ifdef Build/InstallDev
46 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)
47 $(PKG_BUILD_DIR)/.built: package-rebuild
50 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
51 mkdir -p $(STAGING_DIR)/stampfiles
52 $(call Build/InstallDev)
55 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
60 $(call Build/UninstallDev)
61 -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
63 package-rebuild: FORCE
64 @-rm -f $(PKG_BUILD_DIR)/.built
66 define Build/DefaultTargets
70 define Package/Default
73 CATEGORY:=Extra packages
77 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
78 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
79 ifneq ($(PKG_VERSION),)
80 ifneq ($(PKG_RELEASE),)
81 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
83 VERSION:=$(PKG_VERSION)
86 VERSION:=$(PKG_RELEASE)
98 define BuildDescription
99 ifneq ($(DESCRIPTION),)
100 DESCRIPTION:=$(TITLE)\\ $(DESCRIPTION)
102 DESCRIPTION:=$(TITLE)
106 define BuildIPKGVariable
107 $(call shexport,Package/$(1)/$(2))
108 $(1)_COMMANDS += var2file "$(call shvar,Package/$(1)/$(2))" $(2);
112 $(eval $(call Package/Default))
113 $(eval $(call Package/$(1)))
114 $(eval $(call BuildDescription))
116 $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
118 $$(error Package/$(1) is missing the $(FIELD) field)
122 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
123 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
124 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
126 ifdef Package/$(1)/install
127 ifeq ($(CONFIG_PACKAGE_$(1)),y)
128 install-targets: $$(INFO_$(1))
131 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER)$(SDK),)
132 compile-targets: $$(IPKG_$(1))
134 compile-targets: $(1)-disabled
136 @echo "WARNING: skipping $(1) -- package not selected"
140 ifeq ($(FORCEREBUILD),y)
144 IDEPEND_$(1):=$$(strip $$(DEPENDS))
147 dumpinfo: dumpinfo-$(1)
149 @$$(DUMPINFO_$(call shvar,$(1)))
151 DUMPINFO_$(call shvar,$(1)) += \
152 echo "Package: $(1)";
155 DUMPINFO_$(call shvar,$(1)) += \
156 echo "Menu: $(MENU)";
160 DUMPINFO_$(call shvar,$(1)) += \
161 echo "Submenu: $(SUBMENU)";
162 ifneq ($(SUBMENUDEP),)
163 DUMPINFO_$(call shvar,$(1)) += \
164 echo "Submenu-Depends: $(SUBMENUDEP)";
169 DUMPINFO_$(call shvar,$(1)) += \
170 echo "Default: $(DEFAULT)";
173 $(call shexport,Package/$(1)/description)
175 DUMPINFO_$(call shvar,$(1)) += \
176 if [ "$$$$PREREQ_CHECK" = 1 ]; then echo "Prereq-Check: 1"; fi; \
177 echo "Version: $(VERSION)"; \
178 echo "Depends: $$(IDEPEND_$(1))"; \
179 echo "Provides: $(PROVIDES)"; \
180 echo "Build-Depends: $(PKG_BUILDDEP)"; \
181 echo "Section: $(SECTION)"; \
182 echo "Category: $(CATEGORY)"; \
183 echo "Title: $(TITLE)"; \
184 echo "Maintainer: $(MAINTAINER)"; \
185 if isset $(call shvar,Package/$(1)/description); then \
186 echo -n "Description: "; \
187 getvar $(call shvar,Package/$(1)/description); \
189 echo "Description: $(patsubst \\,\\\\,$(DESCRIPTION))" | perl -ne 's/\\/\n/g, print'; \
193 DUMPINFO_$(call shvar,$(1)) += \
198 DUMPINFO_$(call shvar,$(1)) += \
201 $(call shexport,Package/$(1)/config)
202 DUMPINFO_$(call shvar,$(1)) += \
203 if isset $(call shvar,Package/$(1)/config); then \
205 getvar $(call shvar,Package/$(1)/config); \
211 $(eval $(call BuildIPKGVariable,$(1),conffiles))
212 $(eval $(call BuildIPKGVariable,$(1),preinst))
213 $(eval $(call BuildIPKGVariable,$(1),postinst))
214 $(eval $(call BuildIPKGVariable,$(1),prerm))
215 $(eval $(call BuildIPKGVariable,$(1),postrm))
216 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
217 mkdir -p $$(IDIR_$(1))/CONTROL
218 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
219 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
221 DEPENDS='$(EXTRA_DEPENDS)'; \
222 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
223 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
225 echo "Depends: $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
227 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
228 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
229 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
230 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
231 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
232 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g' | sed -e 's,^[[:space:]]*$$$$, .,g' >> $$(IDIR_$(1))/CONTROL/control
233 chmod 644 $$(IDIR_$(1))/CONTROL/control
234 (cd $$(IDIR_$(1))/CONTROL; \
238 $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
239 $(call Package/$(1)/install,$$(IDIR_$(1)))
240 mkdir -p $(PACKAGE_DIR)
241 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
242 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
243 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
244 $(RSTRIP) $$(IDIR_$(1))
245 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
246 @[ -f $$(IPKG_$(1)) ] || false
248 $$(INFO_$(1)): $$(IPKG_$(1))
249 $(IPKG) install $$(IPKG_$(1))
252 rm -f $(PACKAGE_DIR)/$(1)_*
256 $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
257 -@rm -f $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
260 $$(eval $$(call Build/DefaultTargets,$(1)))
262 ifdef Package/$(1)/install
263 ifneq ($$(CONFIG_PACKAGE_$(1))$(DEVELOPER)$(SDK),)
264 ifneq ($(MAKECMDGOALS),prereq)
266 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install '$$(IPKG_$(1))' '$(PKG_BUILD_DIR)'),$$(IPKG_$(1)))
267 _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
268 $(PKG_BUILD_DIR)/.built: package-rebuild
272 $$(info Rebuilding $$(_INFO))
280 ifneq ($(strip $(PKG_UNPACK)),)
281 define Build/Prepare/Default
283 @if [ -d ./patches -a "$$$$(ls ./patches | wc -l)" -gt 0 ]; then \
284 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
290 $(call Build/Prepare/Default,)
293 define Build/Configure/Default
294 (cd $(PKG_BUILD_DIR)/$(strip $(3)); \
295 if [ -x configure ]; then \
296 $(TARGET_CONFIGURE_OPTS) \
297 CFLAGS="$(TARGET_CFLAGS)" \
298 CXXFLAGS="$(TARGET_CFLAGS)" \
299 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
300 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
301 PKG_CONFIG_LIBDIR="$(STAGING_DIR)/usr/lib/pkgconfig" \
303 $(PKG_CONFIG_PATH)/configure \
304 --target=$(GNU_TARGET_NAME) \
305 --host=$(GNU_TARGET_NAME) \
306 --build=$(GNU_HOST_NAME) \
307 --program-prefix="" \
308 --program-suffix="" \
312 --sbindir=/usr/sbin \
313 --libexecdir=/usr/lib \
315 --datadir=/usr/share \
316 --localstatedir=/var \
318 --infodir=/usr/info \
325 define Build/Configure
326 $(call Build/Configure/Default,)
329 define Build/Compile/Default
330 $(MAKE) -C $(PKG_BUILD_DIR) \
331 $(TARGET_CONFIGURE_OPTS) \
332 CROSS="$(TARGET_CROSS)" \
333 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include " \
334 EXTRA_LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib " \
340 $(call Build/Compile/Default,)
349 ifneq ($(strip $(PKG_SOURCE_URL)),)
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)