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 define Build/DefaultTargets
15 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
16 ifeq ($(CONFIG_AUTOREBUILD),y)
17 $(PKG_BUILD_DIR)/.prepared: package-clean
21 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg $(IPKG_$(1)) $(PKG_BUILD_DIR)),$(IPKG_$(1)))
22 ifeq ($(CONFIG_AUTOREBUILD),y)
23 $(PKG_BUILD_DIR)/.built: package-rebuild
29 $(PKG_BUILD_DIR)/.prepared:
30 @-rm -rf $(PKG_BUILD_DIR)
31 @mkdir -p $(PKG_BUILD_DIR)
35 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
36 $(call Build/Configure)
39 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
43 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
44 $(call Build/InstallDev)
47 ifdef Build/InstallDev
48 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
53 $(call Build/UninstallDev)
54 rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
56 package-rebuild: FORCE
57 @-rm -f $(PKG_BUILD_DIR)/.built
59 define Build/DefaultTargets
63 define Package/Default
66 CATEGORY:=Extra packages
68 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
69 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
70 ifneq ($(PKG_VERSION),)
71 ifneq ($(PKG_RELEASE),)
72 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
74 VERSION:=$(PKG_VERSION)
77 VERSION:=$(PKG_RELEASE)
88 define BuildIPKGVariable
89 pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
90 export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
91 $(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi;
95 $(eval $(call Package/Default))
96 $(eval $(call Package/$(1)))
98 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
100 $$(error Package/$(1) is missing the $(FIELD) field)
108 ifeq ($(DESCRIPTION),)
109 $(eval DESCRIPTION:=$(TITLE))
112 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
113 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
114 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
116 ifeq ($(CONFIG_PACKAGE_$(1)),y)
117 install-targets: $$(INFO_$(1))
120 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
121 compile-targets: $$(IPKG_$(1))
124 IDEPEND_$(1):=$$(strip $$(DEPENDS))
127 echo "Package: $(1)";
131 echo "Menu: $(MENU)";
136 echo "Submenu: $(SUBMENU)";
141 echo "Default: $(DEFAULT)";
145 echo "Version: $(VERSION)"; \
146 echo "Depends: $$(IDEPEND_$(1))"; \
147 echo "Build-Depends: $(PKG_BUILDDEP)"; \
148 echo "Category: $(CATEGORY)"; \
149 echo "Title: $(TITLE)"; \
150 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
163 echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
167 $(eval $(call BuildIPKGVariable,$(1),conffiles))
168 $(eval $(call BuildIPKGVariable,$(1),preinst))
169 $(eval $(call BuildIPKGVariable,$(1),postinst))
170 $(eval $(call BuildIPKGVariable,$(1),prerm))
171 $(eval $(call BuildIPKGVariable,$(1),postrm))
172 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
173 mkdir -p $$(IDIR_$(1))/CONTROL
174 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
175 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
178 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
179 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
181 echo "Depends: $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
183 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
184 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
185 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
186 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
187 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
188 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
189 chmod 644 $$(IDIR_$(1))/CONTROL/control
190 (cd $$(IDIR_$(1))/CONTROL; \
194 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
195 $(call Package/$(1)/install,$$(IDIR_$(1)))
196 mkdir -p $(PACKAGE_DIR)
197 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
198 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
199 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
200 $(RSTRIP) $$(IDIR_$(1))
201 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
203 $$(INFO_$(1)): $$(IPKG_$(1))
204 $(IPKG) install $$(IPKG_$(1))
207 rm -f $(PACKAGE_DIR)/$(1)_*
211 $$(eval $$(call Build/DefaultTargets,$(1)))
215 ifneq ($(strip $(PKG_CAT)),)
216 ifeq ($(PKG_CAT),unzip)
217 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
219 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
221 define Build/Prepare/Default
223 @if [ -d ./patches ]; then \
224 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
230 $(call Build/Prepare/Default)
233 define Build/Configure/Default
234 @(cd $(PKG_BUILD_DIR)/$(3); \
235 [ -x configure ] && \
237 $(TARGET_CONFIGURE_OPTS) \
238 CFLAGS="$(TARGET_CFLAGS)" \
239 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
240 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
242 --target=$(GNU_TARGET_NAME) \
243 --host=$(GNU_TARGET_NAME) \
244 --build=$(GNU_HOST_NAME) \
245 --program-prefix="" \
246 --program-suffix="" \
250 --sbindir=/usr/sbin \
251 --libexecdir=/usr/lib \
253 --datadir=/usr/share \
254 --localstatedir=/var \
256 --infodir=/usr/info \
263 define Build/Configure
264 $(call Build/Configure/Default,)
267 define Build/Compile/Default
268 $(MAKE) -C $(PKG_BUILD_DIR) \
269 $(TARGET_CONFIGURE_OPTS) \
271 CROSS="$(TARGET_CROSS)" \
272 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include" \
278 $(call Build/Compile/Default,)
288 ifneq ($(strip $(PKG_SOURCE)),)
289 source: $(DL_DIR)/$(PKG_SOURCE)
291 $(DL_DIR)/$(PKG_SOURCE):
293 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
295 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
299 prepare: $(PKG_BUILD_DIR)/.prepared
300 configure: $(PKG_BUILD_DIR)/.configured
303 compile: compile-targets
306 install: install-targets
310 @$(MAKE) clean-targets
312 rm -rf $(PKG_BUILD_DIR)