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