Merged revisions 43524 via svnmerge from
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999-2006, Digium, Inc.
7 #
8 # Mark Spencer <markster@digium.com>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 # All Makefiles use the following variables:
15 #
16 # LDFLAGS - linker flags (not libraries), used for all links
17 # LIBS - additional libraries, at top-level for all links,
18 #      on a single object just for that object
19 # SOLINK - linker flags used only for creating shared objects (.so files),
20 #      used for all .so links
21 #
22
23 .EXPORT_ALL_VARIABLES:
24
25 # even though we could use '-include makeopts' here, use a wildcard
26 # lookup anyway, so that make won't try to build makeopts if it doesn't
27 # exist (other rules will force it to be built if needed)
28 ifneq ($(wildcard makeopts),)
29   include makeopts
30 endif
31
32 #Uncomment this to see all build commands instead of 'quiet' output
33 #NOISY_BUILD=yes
34
35 # Create OPTIONS variable
36 OPTIONS=
37
38 ASTTOPDIR:=$(shell pwd)
39
40 # Overwite config files on "make samples"
41 OVERWRITE=y
42
43 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
44 DEBUG=-g3
45
46 # Staging directory
47 # Files are copied here temporarily during the install process
48 # For example, make DESTDIR=/tmp/asterisk woud put things in
49 # /tmp/asterisk/etc/asterisk
50 # !!! Watch out, put no spaces or comments after the value !!!
51 #DESTDIR?=/tmp/asterisk
52
53 # Define standard directories for various platforms
54 # These apply if they are not redefined in asterisk.conf 
55 ifeq ($(OSARCH),SunOS)
56   ASTETCDIR=/var/etc/asterisk
57   ASTLIBDIR=/opt/asterisk/lib
58   ASTVARLIBDIR=/var/opt/asterisk
59   ASTSPOOLDIR=/var/spool/asterisk
60   ASTLOGDIR=/var/log/asterisk
61   ASTHEADERDIR=/opt/asterisk/include
62   ASTBINDIR=/opt/asterisk/bin
63   ASTSBINDIR=/opt/asterisk/sbin
64   ASTVARRUNDIR=/var/run/asterisk
65   ASTMANDIR=/opt/asterisk/man
66 else
67   ASTETCDIR=$(sysconfdir)/asterisk
68   ASTLIBDIR=$(libdir)/asterisk
69   ASTHEADERDIR=$(includedir)/asterisk
70   ASTBINDIR=$(bindir)
71   ASTSBINDIR=$(sbindir)
72   ASTSPOOLDIR=$(localstatedir)/spool/asterisk
73   ASTLOGDIR=$(localstatedir)/log/asterisk
74   ASTVARRUNDIR=$(localstatedir)/run
75   ASTMANDIR=$(mandir)
76 ifeq ($(OSARCH),FreeBSD)
77   ASTVARLIBDIR=$(prefix)/share/asterisk
78 else
79   ASTVARLIBDIR=$(localstatedir)/lib/asterisk
80 endif
81 endif
82 ASTDATADIR?=$(ASTVARLIBDIR)
83
84 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
85 # when starting Asterisk
86 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
87 MODULES_DIR=$(ASTLIBDIR)/modules
88 AGI_DIR=$(ASTDATADIR)/agi-bin
89
90 # If you use Apache, you may determine by a grep 'DocumentRoot' of your httpd.conf file
91 HTTP_DOCSDIR=/var/www/html
92 # Determine by a grep 'ScriptAlias' of your Apache httpd.conf file
93 HTTP_CGIDIR=/var/www/cgi-bin
94
95 ASTCFLAGS=
96
97 # Uncomment this to use the older DSP routines
98 #ASTCFLAGS+=-DOLD_DSP_ROUTINES
99
100 # If the file .asterisk.makeopts is present in your home directory, you can
101 # include all of your favorite menuselect options so that every time you download
102 # a new version of Asterisk, you don't have to run menuselect to set them. 
103 # The file /etc/asterisk.makeopts will also be included but can be overridden
104 # by the file in your home directory.
105
106 GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts)
107 USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts)
108
109 MOD_SUBDIR_CFLAGS=-I../include
110 OTHER_SUBDIR_CFLAGS=-I../include
111
112 ifeq ($(OSARCH),linux-gnu)
113   ifeq ($(PROC),x86_64)
114     # You must have GCC 3.4 to use k8, otherwise use athlon
115     PROC=k8
116     #PROC=athlon
117   endif
118
119   ifeq ($(PROC),sparc64)
120     #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
121     #This works for even old (2.96) versions of gcc and provides a small boost either way.
122     #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
123     #So we go lowest common available by gcc and go a step down, still a step up from
124     #the default as we now have a better instruction set to work with. - Belgarath
125     PROC=ultrasparc
126     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
127     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
128     OPTIONS+=-fomit-frame-pointer
129   endif
130
131   ifeq ($(PROC),arm)
132     # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
133     ifeq ($(SUB_PROC),maverick)
134       OPTIONS+=-fsigned-char -mcpu=ep9312
135     else
136       ifeq ($(SUB_PROC),xscale)
137         OPTIONS+=-fsigned-char -mcpu=xscale
138       else
139         OPTIONS+=-fsigned-char 
140       endif
141     endif
142   endif
143 endif
144
145 ASTCFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
146
147 ifeq ($(AST_DEVMODE),yes)
148   ASTCFLAGS+=-Werror -Wunused
149 endif
150
151 ifneq ($(findstring BSD,$(OSARCH)),)
152   ASTCFLAGS+=-I/usr/local/include -L/usr/local/lib
153 endif
154
155 ifneq ($(PROC),ultrasparc)
156   ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
157 endif
158
159 ifeq ($(PROC),ppc)
160   ASTCFLAGS+=-fsigned-char
161 endif
162
163 ifeq ($(OSARCH),FreeBSD)
164   # -V is understood by BSD Make, not by GNU make.
165   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
166   ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
167   AST_LIBS+=$(shell if test  $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
168 endif
169
170 ifeq ($(OSARCH),NetBSD)
171   ASTCFLAGS+=-pthread -I/usr/pkg/include
172 endif
173
174 ifeq ($(OSARCH),OpenBSD)
175   ASTCFLAGS+=-pthread
176 endif
177
178 ifeq ($(OSARCH),SunOS)
179   ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include
180 endif
181
182 ASTERISKVERSION:=$(shell build_tools/make_version .)
183
184 ifneq ($(wildcard .version),)
185   ASTERISKVERSIONNUM:=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
186   RPMVERSION:=$(shell sed 's/[-\/:]/_/g' .version)
187 else
188   RPMVERSION=unknown
189 endif
190
191 ifneq ($(wildcard .svn),)
192   ASTERISKVERSIONNUM=999999
193 endif
194
195 ASTCFLAGS+=$(MALLOC_DEBUG)$(BUSYDETECT)$(OPTIONS)
196
197 MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs main
198 OTHER_SUBDIRS:=utils agi
199 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
200 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
201 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
202 SUBDIRS_CLEAN_DEPEND:=$(SUBDIRS:%=%-clean-depend)
203 MOD_SUBDIRS_DEPEND:=$(MOD_SUBDIRS:%=%-depend)
204 OTHER_SUBDIRS_DEPEND:=$(OTHER_SUBDIRS:%=%-depend)
205 SUBDIRS_DEPEND:=$(OTHER_SUBDIRS_DEPEND) $(MOD_SUBDIRS_DEPEND)
206 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
207 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
208 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
209 MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
210
211 ifneq ($(findstring darwin,$(OSARCH)),)
212   ASTCFLAGS+=-D__Darwin__
213   AUDIO_LIBS=-framework CoreAudio
214   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
215 else
216 # These are used for all but Darwin
217   SOLINK=-shared -Xlinker -x
218   ifneq ($(findstring BSD,$(OSARCH)),)
219     LDFLAGS+=-L/usr/local/lib
220   endif
221 endif
222
223 ifeq ($(OSARCH),SunOS)
224   SOLINK=-shared -fpic -L/usr/local/ssl/lib
225 endif
226
227 # This is used when generating the doxygen documentation
228 ifneq ($(DOT),:)
229   HAVEDOT=yes
230 else
231   HAVEDOT=no
232 endif
233
234 all: _all
235         @echo " +--------- Asterisk Build Complete ---------+"  
236         @echo " + Asterisk has successfully been built, and +"  
237         @echo " + can be installed by running:              +"
238         @echo " +                                           +"
239         @echo " +               make install                +"  
240         @echo " +-------------------------------------------+"  
241
242 _all: cleantest $(SUBDIRS)
243
244 makeopts: configure
245         @echo "****"
246         @echo "**** The configure script must be executed before running 'make'."
247         @echo "****"
248         @exit 1
249
250 menuselect.makeopts: menuselect/menuselect menuselect-tree
251         menuselect/menuselect --check-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts
252
253 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
254         @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
255
256 $(MOD_SUBDIRS_EMBED_LDFLAGS):
257         @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
258
259 $(MOD_SUBDIRS_EMBED_LIBS):
260         @echo "EMBED_LIBS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
261
262 makeopts.embed_rules: menuselect.makeopts
263         @echo "Generating embedded module rules ..."
264         @rm -f $@
265         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDSCRIPT)
266         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS)
267         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS)
268
269 $(SUBDIRS): depend makeopts.embed_rules
270
271 # ensure that all module subdirectories are processed before 'main' during
272 # a parallel build, since if there are modules selected to be embedded the
273 # directories containing them must be completed before the main Asterisk
274 # binary can be built
275 main: $(filter-out main,$(MOD_SUBDIRS))
276
277 $(MOD_SUBDIRS):
278         @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
279
280 $(OTHER_SUBDIRS):
281         @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
282
283 defaults.h: makeopts
284         @build_tools/make_defaults_h > $@.tmp
285         @if cmp -s $@.tmp $@ ; then : ; else \
286                 mv $@.tmp $@ ; \
287         fi
288         @rm -f $@.tmp
289
290 include/asterisk/version.h:
291         @build_tools/make_version_h > $@.tmp
292         @if cmp -s $@.tmp $@ ; then : ; else \
293                 mv $@.tmp $@ ; \
294         fi
295         @rm -f $@.tmp
296
297 include/asterisk/buildopts.h: menuselect.makeopts
298         @build_tools/make_buildopts_h > $@.tmp
299         @if cmp -s $@.tmp $@ ; then : ; else \
300                 mv $@.tmp $@ ; \
301         fi
302         @rm -f $@.tmp
303
304 $(SUBDIRS_CLEAN_DEPEND):
305         @$(MAKE) --no-print-directory -C $(@:-clean-depend=) clean-depend
306
307 $(SUBDIRS_CLEAN):
308         @$(MAKE) --no-print-directory -C $(@:-clean=) clean
309
310 clean-depend: $(SUBDIRS_CLEAN_DEPEND)
311
312 clean: $(SUBDIRS_CLEAN) clean-depend
313         rm -f defaults.h
314         rm -f include/asterisk/build.h
315         rm -f include/asterisk/version.h
316         rm -f .depend
317         @$(MAKE) -C menuselect clean
318         cp -f .cleancount .lastclean
319
320 dist-clean: distclean
321
322 distclean: clean
323         @$(MAKE) -C menuselect dist-clean
324         @$(MAKE) -C sounds dist-clean
325         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
326         rm -f makeopts.embed_rules
327         rm -f config.log config.status
328         rm -rf autom4te.cache
329         rm -f include/asterisk/autoconfig.h
330         rm -f include/asterisk/buildopts.h
331         rm -rf doc/api
332         rm -f build_tools/menuselect-deps
333
334 datafiles: _all
335         if [ x`$(ID) -un` = xroot ]; then CFLAGS="$(ASTCFLAGS)" sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
336 # Should static HTTP be installed during make samples or even with its own target ala
337 # webvoicemail?  There are portions here that *could* be customized but might also be
338 # improved a lot.  I'll put it here for now.
339         mkdir -p $(DESTDIR)$(ASTDATADIR)/static-http
340         for x in static-http/*; do \
341                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/static-http ; \
342         done
343         mkdir -p $(DESTDIR)$(ASTDATADIR)/images
344         for x in images/*.jpg; do \
345                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/images ; \
346         done
347         mkdir -p $(DESTDIR)$(AGI_DIR)
348         $(MAKE) -C sounds install
349
350 update: 
351         @if [ -d .svn ]; then \
352                 echo "Updating from Subversion..." ; \
353                 svn update | tee update.out; \
354                 rm -f .version; \
355                 if [ `grep -c ^C update.out` -gt 0 ]; then \
356                         echo ; echo "The following files have conflicts:" ; \
357                         grep ^C update.out | cut -b4- ; \
358                 fi ; \
359                 rm -f update.out; \
360                 $(MAKE) clean-depend; \
361         else \
362                 echo "Not under version control";  \
363         fi
364
365 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
366 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
367
368 bininstall: _all
369         mkdir -p $(DESTDIR)$(MODULES_DIR)
370         mkdir -p $(DESTDIR)$(ASTSBINDIR)
371         mkdir -p $(DESTDIR)$(ASTETCDIR)
372         mkdir -p $(DESTDIR)$(ASTBINDIR)
373         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
374         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
375         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
376         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
377         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
378         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
379         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
380         $(INSTALL) -m 755 main/asterisk $(DESTDIR)$(ASTSBINDIR)/
381         $(LN) -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
382         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
383         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
384         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
385                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
386                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
387         fi
388         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
389         $(INSTALL) -m 644 include/asterisk.h $(DESTDIR)$(includedir)
390         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
391         if [ -n "$(OLDHEADERS)" ]; then \
392                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
393         fi
394         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
395         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
396         mkdir -p $(DESTDIR)$(ASTDATADIR)/keys
397         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware
398         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware/iax
399         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
400         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys
401         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys
402         $(INSTALL) -m 644 doc/asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
403         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
404         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
405         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
406         $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
407
408 $(SUBDIRS_INSTALL):
409         @$(MAKE) -C $(@:-install=) install
410
411 NEWMODS=$(notdir $(wildcard */*.so))
412 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
413
414 oldmodcheck:
415         @if [ -n "$(OLDMODS)" ]; then \
416                 echo " WARNING WARNING WARNING" ;\
417                 echo "" ;\
418                 echo " Your Asterisk modules directory, located at" ;\
419                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
420                 echo " contains modules that were not installed by this " ;\
421                 echo " version of Asterisk. Please ensure that these" ;\
422                 echo " modules are compatible with this version before" ;\
423                 echo " attempting to run Asterisk." ;\
424                 echo "" ;\
425                 for f in $(OLDMODS); do \
426                         echo "    $$f" ;\
427                 done ;\
428                 echo "" ;\
429                 echo " WARNING WARNING WARNING" ;\
430         fi
431
432 install: datafiles bininstall $(SUBDIRS_INSTALL)
433         @if [ -x /usr/sbin/asterisk-post-install ]; then \
434                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
435         fi
436         @echo " +---- Asterisk Installation Complete -------+"  
437         @echo " +                                           +"
438         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
439         @echo " +                                           +"
440         @echo " + Asterisk has successfully been installed. +"  
441         @echo " + If you would like to install the sample   +"  
442         @echo " + configuration files (overwriting any      +"
443         @echo " + existing config files), run:              +"  
444         @echo " +                                           +"
445         @echo " +               $(MAKE) samples                +"
446         @echo " +                                           +"
447         @echo " +-----------------  or ---------------------+"
448         @echo " +                                           +"
449         @echo " + You can go ahead and install the asterisk +"
450         @echo " + program documentation now or later run:   +"
451         @echo " +                                           +"
452         @echo " +              $(MAKE) progdocs                +"
453         @echo " +                                           +"
454         @echo " + **Note** This requires that you have      +"
455         @echo " + doxygen installed on your local system    +"
456         @echo " +-------------------------------------------+"
457         @$(MAKE) -s oldmodcheck
458
459 upgrade: bininstall
460
461 adsi:
462         mkdir -p $(DESTDIR)$(ASTETCDIR)
463         for x in configs/*.adsi; do \
464                 if [ ! -f $(DESTDIR)$(ASTETCDIR)/$$x ]; then \
465                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
466                 fi ; \
467         done
468
469 samples: adsi
470         mkdir -p $(DESTDIR)$(ASTETCDIR)
471         for x in configs/*.sample; do \
472                 if [ -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ]; then \
473                         if [ "$(OVERWRITE)" = "y" ]; then \
474                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $$x ; then \
475                                         echo "Config file $$x is unchanged"; \
476                                         continue; \
477                                 fi ; \
478                                 mv -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`.old ; \
479                         else \
480                                 echo "Skipping config file $$x"; \
481                                 continue; \
482                         fi ;\
483                 fi ; \
484                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ;\
485         done
486         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
487                 ( \
488                 echo "[directories]" ; \
489                 echo "astetcdir => $(ASTETCDIR)" ; \
490                 echo "astmoddir => $(MODULES_DIR)" ; \
491                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
492                 echo "astdatadir => $(ASTDATADIR)" ; \
493                 echo "astagidir => $(AGI_DIR)" ; \
494                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
495                 echo "astrundir => $(ASTVARRUNDIR)" ; \
496                 echo "astlogdir => $(ASTLOGDIR)" ; \
497                 echo "" ; \
498                 echo "; Changing the following lines may compromise your security." ; \
499                 echo ";[files]" ; \
500                 echo ";astctlpermissions = 0660" ; \
501                 echo ";astctlowner = root" ; \
502                 echo ";astctlgroup = apache" ; \
503                 echo ";astctl = asterisk.ctl" ; \
504                 echo ";[options]" ; \
505                 echo ";internal_timing = yes" ; \
506                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
507         else \
508                 echo "Skipping asterisk.conf creation"; \
509         fi
510         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
511         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
512         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
513                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
514         done
515         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
516         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
517                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
518         done
519
520 webvmail:
521         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
522         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
523         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
524         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
525         for x in images/*.gif; do \
526                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
527         done
528         @echo " +--------- Asterisk Web Voicemail ----------+"  
529         @echo " +                                           +"
530         @echo " + Asterisk Web Voicemail is installed in    +"
531         @echo " + your cgi-bin directory:                   +"
532         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
533         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
534         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
535         @echo " +                                           +"
536         @echo " + Other static items have been stored in:   +"
537         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
538         @echo " +                                           +"
539         @echo " + If these paths do not match your httpd    +"
540         @echo " + installation, correct the definitions     +"
541         @echo " + in your Makefile of HTTP_CGIDIR and       +"
542         @echo " + HTTP_DOCSDIR                              +"
543         @echo " +                                           +"
544         @echo " +-------------------------------------------+"  
545
546 spec: 
547         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
548
549 rpm: __rpm
550
551 __rpm: include/asterisk/version.h include/asterisk/buildopts.h spec
552         rm -rf /tmp/asterisk ; \
553         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
554         $(MAKE) DESTDIR=/tmp/asterisk install ; \
555         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
556         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
557         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
558         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
559
560 progdocs:
561         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
562         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
563
564 config:
565         @if [ "${OSARCH}" = "linux-gnu" ]; then \
566                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
567                         $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
568                         /sbin/chkconfig --add asterisk; \
569                 elif [ -f /etc/debian_version ]; then \
570                         $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk; \
571                         /usr/sbin/update-rc.d asterisk start 10 2 3 4 5 . stop 91 2 3 4 5 .; \
572                 elif [ -f /etc/gentoo-release ]; then \
573                         $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk /etc/init.d/asterisk; \
574                         /sbin/rc-update add asterisk default; \
575                 elif [ -f /etc/mandrake-release ]; then \
576                         $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk /etc/rc.d/init.d/asterisk; \
577                         /sbin/chkconfig --add asterisk; \
578                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
579                         $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk /etc/init.d/asterisk; \
580                         /sbin/chkconfig --add asterisk; \
581                 elif [ -f /etc/slackware-version ]; then \
582                         echo "Slackware is not currently supported, although an init script does exist for it." \
583                 else \
584                         echo "We could not install init scripts for your distribution."; \
585                 fi \
586         else \
587                 echo "We could not install init scripts for your operating system."; \
588         fi
589
590 $(MOD_SUBDIRS_DEPEND):
591         @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
592
593 $(OTHER_SUBDIRS_DEPEND):
594         @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
595
596 depend: include/asterisk/version.h include/asterisk/buildopts.h defaults.h $(SUBDIRS_DEPEND)
597
598 sounds:
599         $(MAKE) -C sounds all
600
601 # If the cleancount has been changed, force a make clean.
602 # .cleancount is the global clean count, and .lastclean is the 
603 # last clean count we had
604
605 cleantest:
606         @if ! cmp -s .cleancount .lastclean ; then \
607                 $(MAKE) clean;\
608         fi
609
610 $(SUBDIRS_UNINSTALL):
611         @$(MAKE) --no-print-directory -C $(@:-uninstall=) uninstall
612
613 _uninstall: $(SUBDIRS_UNINSTALL)
614         rm -f $(DESTDIR)$(MODULES_DIR)/*
615         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
616         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
617         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
618         rm -rf $(DESTDIR)$(ASTHEADERDIR)
619         rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
620         rm -rf $(DESTDIR)$(ASTMANDIR)/man8
621         $(MAKE) -C sounds uninstall
622
623 uninstall: _uninstall
624         @echo " +--------- Asterisk Uninstall Complete -----+"  
625         @echo " + Asterisk binaries, sounds, man pages,     +"  
626         @echo " + headers, modules, and firmware builds,    +"  
627         @echo " + have all been uninstalled.                +"  
628         @echo " +                                           +"
629         @echo " + To remove ALL traces of Asterisk,         +"
630         @echo " + including configuration, spool            +"
631         @echo " + directories, and logs, run the following  +"
632         @echo " + command:                                  +"
633         @echo " +                                           +"
634         @echo " +            $(MAKE) uninstall-all             +"  
635         @echo " +-------------------------------------------+"  
636
637 uninstall-all: _uninstall
638         rm -rf $(DESTDIR)$(ASTLIBDIR)
639         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
640         rm -rf $(DESTDIR)$(ASTDATADIR)
641         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
642         rm -rf $(DESTDIR)$(ASTETCDIR)
643         rm -rf $(DESTDIR)$(ASTLOGDIR)
644
645 menuselect: menuselect/menuselect menuselect-tree
646         -@menuselect/menuselect $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
647
648 menuselect/menuselect: makeopts menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
649         @unset CC LD AR RANLIB && $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
650
651 menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc)) build_tools/cflags.xml sounds/sounds.xml build_tools/embed_modules.xml
652         @echo "Generating input for menuselect ..."
653         @build_tools/prep_moduledeps > $@
654
655 .PHONY: menuselect main sounds clean clean-depend dist-clean distclean all prereqs depend cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_CLEAN_DEPEND) $(SUBDIRS_DEPEND) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS)