e0153444df7869a276a1b97bcb24068e40ddc28b
[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 ifeq ($(findstring -save-temps,$(ASTCFLAGS)),)
204 ASTCFLAGS+=-pipe
205 endif
206
207 ASTCFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
208
209 ASTCFLAGS+=-include $(ASTTOPDIR)/include/asterisk/autoconfig.h
210
211 ifeq ($(AST_DEVMODE),yes)
212   ASTCFLAGS+=-Werror -Wunused -Wundef $(AST_DECLARATION_AFTER_STATEMENT)
213 endif
214
215 ifneq ($(findstring BSD,$(OSARCH)),)
216   ASTCFLAGS+=-I/usr/local/include
217   ASTLDFLAGS+=-L/usr/local/lib
218 endif
219
220 ifneq ($(PROC),ultrasparc)
221   ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
222 endif
223
224 ifeq ($(PROC),ppc)
225   ASTCFLAGS+=-fsigned-char
226 endif
227
228 ifeq ($(OSARCH),FreeBSD)
229   # -V is understood by BSD Make, not by GNU make.
230   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
231   ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
232   AST_LIBS+=$(shell if test  $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
233 endif
234
235 ifeq ($(OSARCH),NetBSD)
236   ASTCFLAGS+=-pthread -I/usr/pkg/include
237 endif
238
239 ifeq ($(OSARCH),OpenBSD)
240   ASTCFLAGS+=-pthread
241 endif
242
243 ifeq ($(OSARCH),SunOS)
244   ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include
245 endif
246
247 ASTERISKVERSION:=$(shell build_tools/make_version .)
248
249 ifneq ($(wildcard .version),)
250   ASTERISKVERSIONNUM:=$(shell awk -F. '{printf "%01d%02d%02d", $$1, $$2, $$3}' .version)
251   RPMVERSION:=$(shell sed 's/[-\/:]/_/g' .version)
252 else
253   RPMVERSION=unknown
254 endif
255
256 ifneq ($(wildcard .svn),)
257   ASTERISKVERSIONNUM=999999
258 endif
259
260 ASTCFLAGS+=$(MALLOC_DEBUG)$(BUSYDETECT)$(OPTIONS)
261
262 MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs main
263 OTHER_SUBDIRS:=utils agi
264 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
265 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
266 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
267 SUBDIRS_DIST_CLEAN:=$(SUBDIRS:%=%-dist-clean)
268 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
269 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
270 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
271 MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
272
273 ifneq ($(findstring darwin,$(OSARCH)),)
274   ASTCFLAGS+=-D__Darwin__
275   AUDIO_LIBS=-framework CoreAudio
276   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
277 else
278 # These are used for all but Darwin
279   SOLINK=-shared -Xlinker -x
280   ifneq ($(findstring BSD,$(OSARCH)),)
281     LDFLAGS+=-L/usr/local/lib
282   endif
283 endif
284
285 ifeq ($(OSARCH),SunOS)
286   SOLINK=-shared -fpic -L/usr/local/ssl/lib
287 endif
288
289 # This is used when generating the doxygen documentation
290 ifneq ($(DOT),:)
291   HAVEDOT=yes
292 else
293   HAVEDOT=no
294 endif
295
296 all: _all
297         @echo " +--------- Asterisk Build Complete ---------+"  
298         @echo " + Asterisk has successfully been built, and +"  
299         @echo " + can be installed by running:              +"
300         @echo " +                                           +"
301 ifeq ($(MAKE), gmake)
302         @echo " +               $(MAKE) install               +"  
303 else
304         @echo " +               $(MAKE) install                +"  
305 endif
306         @echo " +-------------------------------------------+"  
307
308 _all: cleantest $(SUBDIRS)
309
310 makeopts: configure
311         @echo "****"
312         @echo "**** The configure script must be executed before running '$(MAKE)'." 
313         @echo "****               Please run \"./configure\"."
314         @echo "****"
315         @exit 1
316
317 menuselect.makeopts: menuselect/menuselect menuselect-tree
318         menuselect/menuselect --check-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts
319
320 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
321         @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
322
323 $(MOD_SUBDIRS_EMBED_LDFLAGS):
324         @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
325
326 $(MOD_SUBDIRS_EMBED_LIBS):
327         @echo "EMBED_LIBS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
328
329 makeopts.embed_rules: menuselect.makeopts
330         @echo "Generating embedded module rules ..."
331         @rm -f $@
332         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDSCRIPT)
333         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS)
334         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS)
335
336 $(SUBDIRS): include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
337
338 # ensure that all module subdirectories are processed before 'main' during
339 # a parallel build, since if there are modules selected to be embedded the
340 # directories containing them must be completed before the main Asterisk
341 # binary can be built
342 main: $(filter-out main,$(MOD_SUBDIRS))
343
344 $(MOD_SUBDIRS):
345         @echo "   [enter MOD_SUBDIR $@/]"
346         @ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AST_LIBS="$(AST_LIBS)" $(MAKE) --no-print-directory --no-builtin-rules -C $@ SUBDIR=$@ all
347         @echo "   [exit MOD_SUBDIR $@/]"
348
349 $(OTHER_SUBDIRS):
350         @echo "   [enter SUBDIR $@/]"
351         @ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AUDIO_LIBS="$(AUDIO_LIBS)" $(MAKE) --no-print-directory --no-builtin-rules -C $@ SUBDIR=$@ all
352         @echo "   [exit SUBDIR $@/]"
353
354 defaults.h: makeopts
355         @build_tools/make_defaults_h > $@.tmp
356         @if cmp -s $@.tmp $@ ; then : ; else \
357                 mv $@.tmp $@ ; \
358         fi
359         @rm -f $@.tmp
360
361 include/asterisk/version.h:
362         @build_tools/make_version_h > $@.tmp
363         @if cmp -s $@.tmp $@ ; then : ; else \
364                 mv $@.tmp $@ ; \
365         fi
366         @rm -f $@.tmp
367
368 include/asterisk/buildopts.h: menuselect.makeopts
369         @build_tools/make_buildopts_h > $@.tmp
370         @if cmp -s $@.tmp $@ ; then : ; else \
371                 mv $@.tmp $@ ; \
372         fi
373         @rm -f $@.tmp
374
375 include/asterisk/build.h:
376         @build_tools/make_build_h > $@.tmp
377         @if cmp -s $@.tmp $@ ; then : ; else \
378                 mv $@.tmp $@ ; \
379         fi
380         @rm -f $@.tmp
381
382 $(SUBDIRS_CLEAN):
383         @$(MAKE) --no-print-directory -C $(@:-clean=) clean
384
385 $(SUBDIRS_DIST_CLEAN):
386         @$(MAKE) --no-print-directory -C $(@:-dist-clean=) dist-clean
387
388 clean: $(SUBDIRS_CLEAN)
389         rm -f defaults.h
390         rm -f include/asterisk/build.h
391         rm -f include/asterisk/version.h
392         @$(MAKE) -C menuselect clean
393         cp -f .cleancount .lastclean
394
395 dist-clean: distclean
396
397 distclean: $(SUBDIRS_DIST_CLEAN) clean
398         @$(MAKE) -C menuselect dist-clean
399         @$(MAKE) -C sounds dist-clean
400         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
401         rm -f makeopts.embed_rules
402         rm -f config.log config.status
403         rm -rf autom4te.cache
404         rm -f include/asterisk/autoconfig.h
405         rm -f include/asterisk/buildopts.h
406         rm -rf doc/api
407         rm -f build_tools/menuselect-deps
408
409 datafiles: _all
410         if [ x`$(ID) -un` = xroot ]; then CFLAGS="$(ASTCFLAGS)" sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
411 # Should static HTTP be installed during make samples or even with its own target ala
412 # webvoicemail?  There are portions here that *could* be customized but might also be
413 # improved a lot.  I'll put it here for now.
414         mkdir -p $(DESTDIR)$(ASTDATADIR)/static-http
415         for x in static-http/*; do \
416                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/static-http ; \
417         done
418         mkdir -p $(DESTDIR)$(ASTDATADIR)/images
419         for x in images/*.jpg; do \
420                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/images ; \
421         done
422         mkdir -p $(DESTDIR)$(AGI_DIR)
423         $(MAKE) -C sounds install
424
425 update: 
426         @if [ -d .svn ]; then \
427                 echo "Updating from Subversion..." ; \
428                 svn update | tee update.out; \
429                 rm -f .version; \
430                 if [ `grep -c ^C update.out` -gt 0 ]; then \
431                         echo ; echo "The following files have conflicts:" ; \
432                         grep ^C update.out | cut -b4- ; \
433                 fi ; \
434                 rm -f update.out; \
435         else \
436                 echo "Not under version control";  \
437         fi
438
439 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
440 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
441
442 bininstall: _all
443         mkdir -p $(DESTDIR)$(MODULES_DIR)
444         mkdir -p $(DESTDIR)$(ASTSBINDIR)
445         mkdir -p $(DESTDIR)$(ASTETCDIR)
446         mkdir -p $(DESTDIR)$(ASTBINDIR)
447         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
448         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
449         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
450         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
451         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
452         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
453         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
454         $(INSTALL) -m 755 main/asterisk $(DESTDIR)$(ASTSBINDIR)/
455         $(LN) -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
456         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
457         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
458         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
459                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
460                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
461         fi
462         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
463         $(INSTALL) -m 644 include/asterisk.h $(DESTDIR)$(includedir)
464         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
465         if [ -n "$(OLDHEADERS)" ]; then \
466                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
467         fi
468         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
469         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
470         mkdir -p $(DESTDIR)$(ASTDATADIR)/keys
471         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware
472         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware/iax
473         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
474         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys
475         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys
476         $(INSTALL) -m 644 doc/asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
477         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
478         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
479         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
480         if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
481                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
482         fi
483
484 $(SUBDIRS_INSTALL):
485         @DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" $(MAKE) -C $(@:-install=) install
486
487 NEWMODS=$(notdir $(wildcard */*.so))
488 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
489
490 oldmodcheck:
491         @if [ -n "$(OLDMODS)" ]; then \
492                 echo " WARNING WARNING WARNING" ;\
493                 echo "" ;\
494                 echo " Your Asterisk modules directory, located at" ;\
495                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
496                 echo " contains modules that were not installed by this " ;\
497                 echo " version of Asterisk. Please ensure that these" ;\
498                 echo " modules are compatible with this version before" ;\
499                 echo " attempting to run Asterisk." ;\
500                 echo "" ;\
501                 for f in $(OLDMODS); do \
502                         echo "    $$f" ;\
503                 done ;\
504                 echo "" ;\
505                 echo " WARNING WARNING WARNING" ;\
506         fi
507
508 install: datafiles bininstall $(SUBDIRS_INSTALL)
509         @if [ -x /usr/sbin/asterisk-post-install ]; then \
510                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
511         fi
512         @echo " +---- Asterisk Installation Complete -------+"  
513         @echo " +                                           +"
514         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
515         @echo " +                                           +"
516         @echo " + Asterisk has successfully been installed. +"  
517         @echo " + If you would like to install the sample   +"  
518         @echo " + configuration files (overwriting any      +"
519         @echo " + existing config files), run:              +"  
520         @echo " +                                           +"
521 ifeq ($(MAKE), gmake)
522         @echo " +               $(MAKE) samples               +"
523 else
524         @echo " +               $(MAKE) samples                +"
525 endif
526         @echo " +                                           +"
527         @echo " +-----------------  or ---------------------+"
528         @echo " +                                           +"
529         @echo " + You can go ahead and install the asterisk +"
530         @echo " + program documentation now or later run:   +"
531         @echo " +                                           +"
532 ifeq ($(MAKE), gmake)
533         @echo " +              $(MAKE) progdocs               +"
534 else
535         @echo " +              $(MAKE) progdocs                +"
536 endif
537         @echo " +                                           +"
538         @echo " + **Note** This requires that you have      +"
539         @echo " + doxygen installed on your local system    +"
540         @echo " +-------------------------------------------+"
541         @$(MAKE) -s oldmodcheck
542
543 upgrade: bininstall
544
545 adsi:
546         mkdir -p $(DESTDIR)$(ASTETCDIR)
547         for x in configs/*.adsi; do \
548                 if [ ! -f $(DESTDIR)$(ASTETCDIR)/$$x ]; then \
549                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
550                 fi ; \
551         done
552
553 samples: adsi
554         mkdir -p $(DESTDIR)$(ASTETCDIR)
555         for x in configs/*.sample; do \
556                 if [ -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ]; then \
557                         if [ "$(OVERWRITE)" = "y" ]; then \
558                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $$x ; then \
559                                         echo "Config file $$x is unchanged"; \
560                                         continue; \
561                                 fi ; \
562                                 mv -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`.old ; \
563                         else \
564                                 echo "Skipping config file $$x"; \
565                                 continue; \
566                         fi ;\
567                 fi ; \
568                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ;\
569         done
570         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
571                 ( \
572                 echo "[directories]" ; \
573                 echo "astetcdir => $(ASTETCDIR)" ; \
574                 echo "astmoddir => $(MODULES_DIR)" ; \
575                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
576                 echo "astdbdir => $(ASTDBDIR)" ; \
577                 echo "astkeydir => $(ASTKEYDIR)" ; \
578                 echo "astdatadir => $(ASTDATADIR)" ; \
579                 echo "astagidir => $(AGI_DIR)" ; \
580                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
581                 echo "astrundir => $(ASTVARRUNDIR)" ; \
582                 echo "astlogdir => $(ASTLOGDIR)" ; \
583                 echo "" ; \
584                 echo ";[options]" ; \
585                 echo ";verbose = 3" ; \
586                 echo ";debug = 3" ; \
587                 echo ";alwaysfork = yes ; same as -F at startup" ; \
588                 echo ";nofork = yes ; same as -f at startup" ; \
589                 echo ";quiet = yes ; same as -q at startup" ; \
590                 echo ";timestamp = yes ; same as -T at startup" ; \
591                 echo ";execincludes = yes ; support #exec in config files" ; \
592                 echo ";console = yes ; Run as console (same as -c at startup)" ; \
593                 echo ";highpriority = yes ; Run realtime priority (same as -p at startup)" ; \
594                 echo ";initcrypto = yes ; Initialize crypto keys (same as -i at startup)" ; \
595                 echo ";nocolor = yes ; Disable console colors" ; \
596                 echo ";dontwarn = yes ; Disable some warnings" ; \
597                 echo ";dumpcore = yes ; Dump core on crash (same as -g at startup)" ; \
598                 echo ";languageprefix = yes ; Use the new sound prefix path syntax" ; \
599                 echo ";internal_timing = yes" ; \
600                 echo ";systemname = my_system_name ; prefix uniqueid with a system name for global uniqueness issues" ; \
601                 echo ";autosystemname = yes ; automatically set systemname to hostname - uses 'localhost' on failure, or systemname if set" ; \
602                 echo ";maxcalls = 10 ; Maximum amount of calls allowed" ; \
603                 echo ";maxload = 0.9 ; Asterisk stops accepting new calls if the load average exceed this limit" ; \
604                 echo ";maxfiles = 1000 ; Maximum amount of openfiles" ; \
605                 echo ";minmemfree = 1 ; in MBs, Asterisk stops accepting new calls if the amount of free memory falls below this watermark" ; \
606                 echo ";cache_record_files = yes ; Cache recorded sound files to another directory during recording" ; \
607                 echo ";record_cache_dir = /tmp ; Specify cache directory (used in cnjunction with cache_record_files)" ; \
608                 echo ";transmit_silence_during_record = yes ; Transmit SLINEAR silence while a channel is being recorded" ; \
609                 echo ";transcode_via_sln = yes ; Build transcode paths via SLINEAR, instead of directly" ; \
610                 echo ";runuser = asterisk ; The user to run as" ; \
611                 echo ";rungroup = asterisk ; The group to run as" ; \
612                 echo "" ; \
613                 echo "; Changing the following lines may compromise your security." ; \
614                 echo ";[files]" ; \
615                 echo ";astctlpermissions = 0660" ; \
616                 echo ";astctlowner = root" ; \
617                 echo ";astctlgroup = apache" ; \
618                 echo ";astctl = asterisk.ctl" ; \
619                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
620         else \
621                 echo "Skipping asterisk.conf creation"; \
622         fi
623         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
624         build_tools/make_sample_voicemail $(DESTDIR)/$(ASTDATADIR) $(DESTDIR)/$(ASTSPOOLDIR)
625
626 webvmail:
627         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
628         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
629         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
630         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
631         for x in images/*.gif; do \
632                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
633         done
634         @echo " +--------- Asterisk Web Voicemail ----------+"  
635         @echo " +                                           +"
636         @echo " + Asterisk Web Voicemail is installed in    +"
637         @echo " + your cgi-bin directory:                   +"
638         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
639         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
640         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
641         @echo " +                                           +"
642         @echo " + Other static items have been stored in:   +"
643         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
644         @echo " +                                           +"
645         @echo " + If these paths do not match your httpd    +"
646         @echo " + installation, correct the definitions     +"
647         @echo " + in your Makefile of HTTP_CGIDIR and       +"
648         @echo " + HTTP_DOCSDIR                              +"
649         @echo " +                                           +"
650         @echo " +-------------------------------------------+"  
651
652 spec: 
653         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
654
655 rpm: __rpm
656
657 __rpm: include/asterisk/version.h include/asterisk/buildopts.h spec
658         rm -rf /tmp/asterisk ; \
659         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
660         $(MAKE) DESTDIR=/tmp/asterisk install ; \
661         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
662         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
663         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
664         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
665
666 progdocs:
667         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
668         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
669
670 config:
671         @if [ "${OSARCH}" = "linux-gnu" ]; then \
672                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
673                         $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk $(DESTDIR)/etc/rc.d/init.d/asterisk; \
674                         if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
675                 elif [ -f /etc/debian_version ]; then \
676                         $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk $(DESTDIR)/etc/init.d/asterisk; \
677                         if [ -z "$(DESTDIR)" ]; then /usr/sbin/update-rc.d asterisk start 10 2 3 4 5 . stop 91 2 3 4 5 .; fi; \
678                 elif [ -f /etc/gentoo-release ]; then \
679                         $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk $(DESTDIR)/etc/init.d/asterisk; \
680                         if [ -z "$(DESTDIR)" ]; then /sbin/rc-update add asterisk default; fi; \
681                 elif [ -f /etc/mandrake-release ]; then \
682                         $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk $(DESTDIR)/etc/rc.d/init.d/asterisk; \
683                         if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
684                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
685                         $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk $(DESTDIR)/etc/init.d/asterisk; \
686                         if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
687                 elif [ -f /etc/slackware-version ]; then \
688                         echo "Slackware is not currently supported, although an init script does exist for it." \
689                 else \
690                         echo "We could not install init scripts for your distribution."; \
691                 fi \
692         else \
693                 echo "We could not install init scripts for your operating system."; \
694         fi
695
696 sounds:
697         $(MAKE) -C sounds all
698
699 # If the cleancount has been changed, force a make clean.
700 # .cleancount is the global clean count, and .lastclean is the 
701 # last clean count we had
702
703 cleantest:
704         @cmp -s .cleancount .lastclean || $(MAKE) clean
705
706 $(SUBDIRS_UNINSTALL):
707         @$(MAKE) --no-print-directory -C $(@:-uninstall=) uninstall
708
709 _uninstall: $(SUBDIRS_UNINSTALL)
710         rm -f $(DESTDIR)$(MODULES_DIR)/*
711         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
712         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
713         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
714         rm -rf $(DESTDIR)$(ASTHEADERDIR)
715         rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
716         rm -f $(DESTDIR)$(ASTMANDIR)/man8/asterisk.8
717         rm -f $(DESTDIR)$(ASTMANDIR)/man8/astgenkey.8
718         rm -f $(DESTDIR)$(ASTMANDIR)/man8/autosupport.8
719         rm -f $(DESTDIR)$(ASTMANDIR)/man8/safe_asterisk.8
720         $(MAKE) -C sounds uninstall
721
722 uninstall: _uninstall
723         @echo " +--------- Asterisk Uninstall Complete -----+"  
724         @echo " + Asterisk binaries, sounds, man pages,     +"  
725         @echo " + headers, modules, and firmware builds,    +"  
726         @echo " + have all been uninstalled.                +"  
727         @echo " +                                           +"
728         @echo " + To remove ALL traces of Asterisk,         +"
729         @echo " + including configuration, spool            +"
730         @echo " + directories, and logs, run the following  +"
731         @echo " + command:                                  +"
732         @echo " +                                           +"
733 ifeq ($(MAKE), gmake)
734         @echo " +            $(MAKE) uninstall-all            +"  
735 else
736         @echo " +            $(MAKE) uninstall-all             +"  
737 endif
738         @echo " +-------------------------------------------+"  
739
740 uninstall-all: _uninstall
741         rm -rf $(DESTDIR)$(ASTLIBDIR)
742         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
743         rm -rf $(DESTDIR)$(ASTDATADIR)
744         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
745         rm -rf $(DESTDIR)$(ASTETCDIR)
746         rm -rf $(DESTDIR)$(ASTLOGDIR)
747
748 menuconfig: menuselect
749
750 gmenuconfig: gmenuselect
751
752 menuselect: menuselect/menuselect menuselect-tree
753         -@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!"
754
755 gmenuselect: menuselect/gmenuselect menuselect-tree
756         -@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!"
757
758 menuselect/menuselect: makeopts menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
759         @CC="$(HOST_CC)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
760
761 menuselect/gmenuselect: makeopts menuselect/menuselect.c menuselect/menuselect_gtk.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
762         @CC="$(HOST_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect _gmenuselect CONFIGURE_SILENT="--silent"
763
764 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
765         @echo "Generating input for menuselect ..."
766         @build_tools/prep_moduledeps > $@
767
768 asterisk.pdf:
769         $(MAKE) -C doc/tex asterisk.pdf
770
771 .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