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