fix DESCRIPTION use in menuconfig and ipkg control files
[openwrt.git] / include / package.mk
1
2 # Copyright (C) 2006 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 ifneq ($(DUMP),)
8   all: dumpinfo
9 else
10   all: compile
11 endif
12
13 include $(INCLUDE_DIR)/prereq.mk
14
15 define Build/DefaultTargets
16   ifeq ($(DUMP),)
17     ifeq ($(CONFIG_AUTOREBUILD),y)
18       _INFO:=
19       ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
20         _INFO+=$(subst $(TOPDIR)/,,$(PKG_BUILD_DIR))
21         $(PKG_BUILD_DIR)/.prepared: package-clean
22       endif
23
24     endif
25   endif
26
27   $(PKG_BUILD_DIR)/.prepared:
28         @-rm -rf $(PKG_BUILD_DIR)
29         @mkdir -p $(PKG_BUILD_DIR)
30         $(call Build/Prepare)
31         touch $$@
32
33   $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
34         $(call Build/Configure)
35         touch $$@
36
37   $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
38         $(call Build/Compile)
39         touch $$@
40
41   ifdef Build/InstallDev
42     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)
43       $(PKG_BUILD_DIR)/.built: package-rebuild
44     endif
45
46     $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
47         mkdir -p $(STAGING_DIR)/stampfiles
48         $(call Build/InstallDev)
49         touch $$@
50         
51     compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
52   endif
53
54   package-clean: FORCE
55         $(call Build/Clean)
56         $(call Build/UninstallDev)
57         -rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
58
59   package-rebuild: FORCE
60         @-rm -f $(PKG_BUILD_DIR)/.built
61
62   define Build/DefaultTargets
63   endef
64 endef
65
66 define Package/Default
67   CONFIGFILE:=
68   SECTION:=opt
69   CATEGORY:=Extra packages
70   DEPENDS:=
71   EXTRA_DEPENDS:=
72   MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
73   SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
74   ifneq ($(PKG_VERSION),)
75     ifneq ($(PKG_RELEASE),)
76       VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
77     else
78       VERSION:=$(PKG_VERSION)
79     endif
80   else
81     VERSION:=$(PKG_RELEASE)
82   endif
83   PKGARCH:=$(ARCH)
84   PRIORITY:=optional
85   DEFAULT:=
86   MENU:=
87   SUBMENU:=
88   SUBMENUDEP:=
89   TITLE:=
90   DESCRIPTION:=
91 endef
92
93 define BuildDescription
94   ifneq ($(DESCRIPTION),)
95     DESCRIPTION:=$(TITLE)\\ $(DESCRIPTION)
96   else
97     DESCRIPTION:=$(TITLE)
98   endif
99 endef
100
101 define BuildIPKGVariable
102   pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
103   export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
104   $(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi;
105 endef
106
107 define BuildPackage
108   $(eval $(call Package/Default))
109   $(eval $(call Package/$(1)))
110   $(eval $(call BuildDescription))
111
112   $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
113     ifeq ($($(FIELD)),)
114       $$(error Package/$(1) is missing the $(FIELD) field)
115     endif
116   )
117
118   IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
119   IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
120   INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
121
122   ifdef Package/$(1)/install
123     ifeq ($(CONFIG_PACKAGE_$(1)),y)
124       install-targets: $$(INFO_$(1))
125     endif
126
127     ifneq ($(CONFIG_PACKAGE_$(1)),)
128       compile-targets: $$(IPKG_$(1))
129     else
130       compile-targets: $(1)-disabled
131       $(1)-disabled:
132         @echo "WARNING: skipping $(1) -- package not selected"
133     endif
134   endif
135
136   ifeq ($(FORCEREBUILD),y)
137     $$(IPKG_$(1)): FORCE
138   endif
139
140   IDEPEND_$(1):=$$(strip $$(DEPENDS))
141
142   ifneq ($(DUMP),)
143     DUMPINFO += \
144         echo "Package: $(1)"; 
145
146     ifneq ($(MENU),)
147       DUMPINFO += \
148         echo "Menu: $(MENU)";
149     endif
150
151     ifneq ($(SUBMENU),)
152       DUMPINFO += \
153         echo "Submenu: $(SUBMENU)";
154       ifneq ($(SUBMENUDEP),)
155         DUMPINFO += \
156           echo "Submenu-Depends: $(SUBMENUDEP)";
157       endif
158     endif
159
160     ifneq ($(DEFAULT),)
161       DUMPINFO += \
162         echo "Default: $(DEFAULT)";
163     endif
164
165     DUMPINFO += \
166         echo "Version: $(VERSION)"; \
167         echo "Depends: $$(IDEPEND_$(1))"; \
168         echo "Build-Depends: $(PKG_BUILDDEP)"; \
169         echo "Category: $(CATEGORY)"; \
170         echo "Title: $(TITLE)"; \
171         echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
172
173     ifneq ($(URL),)
174       DUMPINFO += \
175         echo; \
176         echo "$(URL)";
177     endif
178
179     DUMPINFO += \
180         echo "@@";
181
182     ifneq ($(CONFIG),)
183       DUMPINFO += \
184         echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
185         echo "@@";
186     endif
187   endif
188
189   $(eval $(call BuildIPKGVariable,$(1),conffiles))
190   $(eval $(call BuildIPKGVariable,$(1),preinst))
191   $(eval $(call BuildIPKGVariable,$(1),postinst))
192   $(eval $(call BuildIPKGVariable,$(1),prerm))
193   $(eval $(call BuildIPKGVariable,$(1),postrm))
194   $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH)
195         mkdir -p $$(IDIR_$(1))/CONTROL
196         echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
197         echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
198         ( \
199                 DEPENDS=; \
200                 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
201                         DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
202                 done; \
203                 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
204         )
205         echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
206         echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
207         echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
208         echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
209         echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
210         echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g' | sed -e 's,^[[:space:]]*$$$$, .,g' >> $$(IDIR_$(1))/CONTROL/control
211         chmod 644 $$(IDIR_$(1))/CONTROL/control
212         (cd $$(IDIR_$(1))/CONTROL; \
213                 $($(1)_COMMANDS) \
214         )
215
216   $$(IPKG_$(1)): $(PKG_BUILD_DIR)/.built $$(IDIR_$(1))/CONTROL/control
217         $(call Package/$(1)/install,$$(IDIR_$(1)))
218         mkdir -p $(PACKAGE_DIR)
219         -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
220         -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
221         -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
222         $(RSTRIP) $$(IDIR_$(1))
223         $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
224         @[ -f $$(IPKG_$(1)) ] || false 
225
226   $$(INFO_$(1)): $$(IPKG_$(1))
227         $(IPKG) install $$(IPKG_$(1))
228
229   $(1)-clean:
230         rm -f $(PACKAGE_DIR)/$(1)_*
231
232   clean: $(1)-clean
233
234   $(PKG_BUILD_DIR)/.version-$(1)_$(VERSION)_$(PKGARCH): $(PKG_BUILD_DIR)/.prepared
235         -@rm $(PKG_BUILD_DIR)/.version-$(1)_* 2>/dev/null
236         @touch $$@
237
238   $$(eval $$(call Build/DefaultTargets,$(1)))
239
240   ifneq ($$(CONFIG_PACKAGE_$(1)),)
241     ifneq ($(MAKECMDGOALS),prereq)
242       ifneq ($(DUMP),1)
243         ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg -x ipkg-install '$$(IPKG_$(1))' '$(PKG_BUILD_DIR)'),$$(IPKG_$(1)))
244           _INFO+=$(subst $(TOPDIR)/,,$$(IPKG_$(1)))
245           $(PKG_BUILD_DIR)/.built: package-rebuild
246         endif
247
248         ifneq ($$(_INFO),)
249           $$(info Rebuilding $$(_INFO))
250         endif
251       endif
252     endif
253   endif
254 endef
255
256 ifneq ($(strip $(PKG_CAT)),)
257   ifeq ($(PKG_CAT),unzip)
258     UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
259   else
260     UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
261   endif
262   define Build/Prepare/Default
263         $(UNPACK)
264         @if [ -d ./patches ]; then \
265                 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
266         fi
267   endef
268 endif
269
270 define Build/Prepare
271   $(call Build/Prepare/Default,)
272 endef
273
274 define Build/Configure/Default
275         (cd $(PKG_BUILD_DIR)/$(3); \
276         if [ -x configure ]; then \
277                 $(TARGET_CONFIGURE_OPTS) \
278                 CFLAGS="$(TARGET_CFLAGS)" \
279                 CXXFLAGS="$(TARGET_CFLAGS)" \
280                 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
281                 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
282                 PKG_CONFIG_PATH="$(STAGING_DIR)/usr/lib/pkgconfig" \
283                 $(2) \
284                 ./configure \
285                 --target=$(GNU_TARGET_NAME) \
286                 --host=$(GNU_TARGET_NAME) \
287                 --build=$(GNU_HOST_NAME) \
288                 --program-prefix="" \
289                 --program-suffix="" \
290                 --prefix=/usr \
291                 --exec-prefix=/usr \
292                 --bindir=/usr/bin \
293                 --sbindir=/usr/sbin \
294                 --libexecdir=/usr/lib \
295                 --sysconfdir=/etc \
296                 --datadir=/usr/share \
297                 --localstatedir=/var \
298                 --mandir=/usr/man \
299                 --infodir=/usr/info \
300                 $(DISABLE_NLS) \
301                 $(1); \
302         fi; \
303         )
304 endef
305
306 define Build/Configure
307   $(call Build/Configure/Default,)
308 endef
309
310 define Build/Compile/Default
311         $(MAKE) -C $(PKG_BUILD_DIR) \
312                 $(TARGET_CONFIGURE_OPTS) \
313                 CROSS="$(TARGET_CROSS)" \
314                 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include " \
315                 EXTRA_LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib " \
316                 ARCH="$(ARCH)" \
317                 $(1);
318 endef
319
320 define Build/Compile
321   $(call Build/Compile/Default,)
322 endef
323
324 ifneq ($(DUMP),)
325   dumpinfo: FORCE
326         @$(DUMPINFO)
327 else
328   $(PACKAGE_DIR):
329         mkdir -p $@
330                 
331   ifneq ($(strip $(PKG_SOURCE)),)
332     download: $(DL_DIR)/$(PKG_SOURCE)
333
334     $(DL_DIR)/$(PKG_SOURCE):
335                 mkdir -p $(DL_DIR)
336                 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
337
338     $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
339   endif
340
341   download:
342   prepare: $(PKG_BUILD_DIR)/.prepared
343   configure: $(PKG_BUILD_DIR)/.configured
344
345   compile-targets:
346   compile: compile-targets
347
348   install-targets:
349   install: install-targets
350
351   clean-targets:
352   clean: FORCE
353         @$(MAKE) clean-targets
354         $(call Build/Clean)
355         rm -rf $(PKG_BUILD_DIR)
356 endif