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