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