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