Permit custom locations for astdb and the keys directory (though default to the curre...
[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_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
264 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
265 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
266 MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
267
268 ifneq ($(findstring darwin,$(OSARCH)),)
269   ASTCFLAGS+=-D__Darwin__
270   AUDIO_LIBS=-framework CoreAudio
271   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
272 else
273 # These are used for all but Darwin
274   SOLINK=-shared -Xlinker -x
275   ifneq ($(findstring BSD,$(OSARCH)),)
276     LDFLAGS+=-L/usr/local/lib
277   endif
278 endif
279
280 ifeq ($(OSARCH),SunOS)
281   SOLINK=-shared -fpic -L/usr/local/ssl/lib
282 endif
283
284 # This is used when generating the doxygen documentation
285 ifneq ($(DOT),:)
286   HAVEDOT=yes
287 else
288   HAVEDOT=no
289 endif
290
291 all: _all
292         @echo " +--------- Asterisk Build Complete ---------+"  
293         @echo " + Asterisk has successfully been built, and +"  
294         @echo " + can be installed by running:              +"
295         @echo " +                                           +"
296 ifeq ($(MAKE), gmake)
297         @echo " +               $(MAKE) install               +"  
298 else
299         @echo " +               $(MAKE) install                +"  
300 endif
301         @echo " +-------------------------------------------+"  
302
303 _all: cleantest $(SUBDIRS)
304
305 makeopts: configure
306         @echo "****"
307         @echo "**** The configure script must be executed before running '$(MAKE)'." 
308         @echo "****               Please run \"./configure\"."
309         @echo "****"
310         @exit 1
311
312 menuselect.makeopts: menuselect/menuselect menuselect-tree
313         menuselect/menuselect --check-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts
314
315 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
316         @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
317
318 $(MOD_SUBDIRS_EMBED_LDFLAGS):
319         @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
320
321 $(MOD_SUBDIRS_EMBED_LIBS):
322         @echo "EMBED_LIBS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
323
324 makeopts.embed_rules: menuselect.makeopts
325         @echo "Generating embedded module rules ..."
326         @rm -f $@
327         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDSCRIPT)
328         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS)
329         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS)
330
331 $(SUBDIRS): include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
332
333 # ensure that all module subdirectories are processed before 'main' during
334 # a parallel build, since if there are modules selected to be embedded the
335 # directories containing them must be completed before the main Asterisk
336 # binary can be built
337 main: $(filter-out main,$(MOD_SUBDIRS))
338
339 $(MOD_SUBDIRS):
340         @ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AST_LIBS="$(AST_LIBS)" $(MAKE) --no-print-directory --no-builtin-rules -C $@ SUBDIR=$@ all
341
342 $(OTHER_SUBDIRS):
343         @ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AUDIO_LIBS="$(AUDIO_LIBS)" $(MAKE) --no-print-directory --no-builtin-rules -C $@ SUBDIR=$@ all
344
345 defaults.h: makeopts
346         @build_tools/make_defaults_h > $@.tmp
347         @if cmp -s $@.tmp $@ ; then : ; else \
348                 mv $@.tmp $@ ; \
349         fi
350         @rm -f $@.tmp
351
352 include/asterisk/version.h:
353         @build_tools/make_version_h > $@.tmp
354         @if cmp -s $@.tmp $@ ; then : ; else \
355                 mv $@.tmp $@ ; \
356         fi
357         @rm -f $@.tmp
358
359 include/asterisk/buildopts.h: menuselect.makeopts
360         @build_tools/make_buildopts_h > $@.tmp
361         @if cmp -s $@.tmp $@ ; then : ; else \
362                 mv $@.tmp $@ ; \
363         fi
364         @rm -f $@.tmp
365
366 include/asterisk/build.h:
367         @build_tools/make_build_h > $@.tmp
368         @if cmp -s $@.tmp $@ ; then : ; else \
369                 mv $@.tmp $@ ; \
370         fi
371         @rm -f $@.tmp
372
373 $(SUBDIRS_CLEAN):
374         @$(MAKE) --no-print-directory -C $(@:-clean=) clean
375
376 clean: $(SUBDIRS_CLEAN)
377         rm -f defaults.h
378         rm -f include/asterisk/build.h
379         rm -f include/asterisk/version.h
380         @$(MAKE) -C menuselect clean
381         cp -f .cleancount .lastclean
382
383 dist-clean: distclean
384
385 distclean: clean
386         @$(MAKE) -C menuselect dist-clean
387         @$(MAKE) -C sounds dist-clean
388         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
389         rm -f makeopts.embed_rules
390         rm -f config.log config.status
391         rm -rf autom4te.cache
392         rm -f include/asterisk/autoconfig.h
393         rm -f include/asterisk/buildopts.h
394         rm -rf doc/api
395         rm -f build_tools/menuselect-deps
396
397 datafiles: _all
398         if [ x`$(ID) -un` = xroot ]; then CFLAGS="$(ASTCFLAGS)" sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
399 # Should static HTTP be installed during make samples or even with its own target ala
400 # webvoicemail?  There are portions here that *could* be customized but might also be
401 # improved a lot.  I'll put it here for now.
402         mkdir -p $(DESTDIR)$(ASTDATADIR)/static-http
403         for x in static-http/*; do \
404                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/static-http ; \
405         done
406         mkdir -p $(DESTDIR)$(ASTDATADIR)/images
407         for x in images/*.jpg; do \
408                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/images ; \
409         done
410         mkdir -p $(DESTDIR)$(AGI_DIR)
411         $(MAKE) -C sounds install
412
413 update: 
414         @if [ -d .svn ]; then \
415                 echo "Updating from Subversion..." ; \
416                 svn update | tee update.out; \
417                 rm -f .version; \
418                 if [ `grep -c ^C update.out` -gt 0 ]; then \
419                         echo ; echo "The following files have conflicts:" ; \
420                         grep ^C update.out | cut -b4- ; \
421                 fi ; \
422                 rm -f update.out; \
423         else \
424                 echo "Not under version control";  \
425         fi
426
427 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
428 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
429
430 bininstall: _all
431         mkdir -p $(DESTDIR)$(MODULES_DIR)
432         mkdir -p $(DESTDIR)$(ASTSBINDIR)
433         mkdir -p $(DESTDIR)$(ASTETCDIR)
434         mkdir -p $(DESTDIR)$(ASTBINDIR)
435         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
436         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
437         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
438         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
439         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
440         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
441         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
442         $(INSTALL) -m 755 main/asterisk $(DESTDIR)$(ASTSBINDIR)/
443         $(LN) -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
444         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
445         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
446         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
447                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
448                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
449         fi
450         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
451         $(INSTALL) -m 644 include/asterisk.h $(DESTDIR)$(includedir)
452         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
453         if [ -n "$(OLDHEADERS)" ]; then \
454                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
455         fi
456         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
457         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
458         mkdir -p $(DESTDIR)$(ASTDATADIR)/keys
459         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware
460         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware/iax
461         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
462         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys
463         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys
464         $(INSTALL) -m 644 doc/asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
465         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
466         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
467         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
468         if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
469                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
470         fi
471
472 $(SUBDIRS_INSTALL):
473         @DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" $(MAKE) -C $(@:-install=) install
474
475 NEWMODS=$(notdir $(wildcard */*.so))
476 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
477
478 oldmodcheck:
479         @if [ -n "$(OLDMODS)" ]; then \
480                 echo " WARNING WARNING WARNING" ;\
481                 echo "" ;\
482                 echo " Your Asterisk modules directory, located at" ;\
483                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
484                 echo " contains modules that were not installed by this " ;\
485                 echo " version of Asterisk. Please ensure that these" ;\
486                 echo " modules are compatible with this version before" ;\
487                 echo " attempting to run Asterisk." ;\
488                 echo "" ;\
489                 for f in $(OLDMODS); do \
490                         echo "    $$f" ;\
491                 done ;\
492                 echo "" ;\
493                 echo " WARNING WARNING WARNING" ;\
494         fi
495
496 install: datafiles bininstall $(SUBDIRS_INSTALL)
497         @if [ -x /usr/sbin/asterisk-post-install ]; then \
498                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
499         fi
500         @echo " +---- Asterisk Installation Complete -------+"  
501         @echo " +                                           +"
502         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
503         @echo " +                                           +"
504         @echo " + Asterisk has successfully been installed. +"  
505         @echo " + If you would like to install the sample   +"  
506         @echo " + configuration files (overwriting any      +"
507         @echo " + existing config files), run:              +"  
508         @echo " +                                           +"
509 ifeq ($(MAKE), gmake)
510         @echo " +               $(MAKE) samples               +"
511 else
512         @echo " +               $(MAKE) samples                +"
513 endif
514         @echo " +                                           +"
515         @echo " +-----------------  or ---------------------+"
516         @echo " +                                           +"
517         @echo " + You can go ahead and install the asterisk +"
518         @echo " + program documentation now or later run:   +"
519         @echo " +                                           +"
520 ifeq ($(MAKE), gmake)
521         @echo " +              $(MAKE) progdocs               +"
522 else
523         @echo " +              $(MAKE) progdocs                +"
524 endif
525         @echo " +                                           +"
526         @echo " + **Note** This requires that you have      +"
527         @echo " + doxygen installed on your local system    +"
528         @echo " +-------------------------------------------+"
529         @$(MAKE) -s oldmodcheck
530
531 upgrade: bininstall
532
533 adsi:
534         mkdir -p $(DESTDIR)$(ASTETCDIR)
535         for x in configs/*.adsi; do \
536                 if [ ! -f $(DESTDIR)$(ASTETCDIR)/$$x ]; then \
537                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
538                 fi ; \
539         done
540
541 samples: adsi
542         mkdir -p $(DESTDIR)$(ASTETCDIR)
543         for x in configs/*.sample; do \
544                 if [ -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ]; then \
545                         if [ "$(OVERWRITE)" = "y" ]; then \
546                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $$x ; then \
547                                         echo "Config file $$x is unchanged"; \
548                                         continue; \
549                                 fi ; \
550                                 mv -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`.old ; \
551                         else \
552                                 echo "Skipping config file $$x"; \
553                                 continue; \
554                         fi ;\
555                 fi ; \
556                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ;\
557         done
558         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
559                 ( \
560                 echo "[directories]" ; \
561                 echo "astetcdir => $(ASTETCDIR)" ; \
562                 echo "astmoddir => $(MODULES_DIR)" ; \
563                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
564                 echo "astdbdir => $(ASTDBDIR)" ; \
565                 echo "astkeydir => $(ASTKEYDIR)" ; \
566                 echo "astdatadir => $(ASTDATADIR)" ; \
567                 echo "astagidir => $(AGI_DIR)" ; \
568                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
569                 echo "astrundir => $(ASTVARRUNDIR)" ; \
570                 echo "astlogdir => $(ASTLOGDIR)" ; \
571                 echo "" ; \
572                 echo ";[options]" ; \
573                 echo ";internal_timing = yes" ; \
574                 echo ";systemname = my_system_name ; prefix uniqueid with a system name for global uniqueness issues" ; \
575                 echo ";autosystemname = yes ; automatically set systemname to hostname - uses 'localhost' on failure, or systemname if set" ; \
576                 echo "; Changing the following lines may compromise your security." ; \
577                 echo ";[files]" ; \
578                 echo ";astctlpermissions = 0660" ; \
579                 echo ";astctlowner = root" ; \
580                 echo ";astctlgroup = apache" ; \
581                 echo ";astctl = asterisk.ctl" ; \
582                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
583         else \
584                 echo "Skipping asterisk.conf creation"; \
585         fi
586         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
587         build_tools/make_sample_voicemail $(DESTDIR)/$(ASTDATADIR) $(DESTDIR)/$(ASTSPOOLDIR)
588
589 webvmail:
590         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
591         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
592         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
593         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
594         for x in images/*.gif; do \
595                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
596         done
597         @echo " +--------- Asterisk Web Voicemail ----------+"  
598         @echo " +                                           +"
599         @echo " + Asterisk Web Voicemail is installed in    +"
600         @echo " + your cgi-bin directory:                   +"
601         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
602         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
603         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
604         @echo " +                                           +"
605         @echo " + Other static items have been stored in:   +"
606         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
607         @echo " +                                           +"
608         @echo " + If these paths do not match your httpd    +"
609         @echo " + installation, correct the definitions     +"
610         @echo " + in your Makefile of HTTP_CGIDIR and       +"
611         @echo " + HTTP_DOCSDIR                              +"
612         @echo " +                                           +"
613         @echo " +-------------------------------------------+"  
614
615 spec: 
616         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
617
618 rpm: __rpm
619
620 __rpm: include/asterisk/version.h include/asterisk/buildopts.h spec
621         rm -rf /tmp/asterisk ; \
622         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
623         $(MAKE) DESTDIR=/tmp/asterisk install ; \
624         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
625         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
626         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
627         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
628
629 progdocs:
630         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
631         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
632
633 config:
634         @if [ "${OSARCH}" = "linux-gnu" ]; then \
635                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
636                         $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
637                         /sbin/chkconfig --add asterisk; \
638                 elif [ -f /etc/debian_version ]; then \
639                         $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk; \
640                         /usr/sbin/update-rc.d asterisk start 10 2 3 4 5 . stop 91 2 3 4 5 .; \
641                 elif [ -f /etc/gentoo-release ]; then \
642                         $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk /etc/init.d/asterisk; \
643                         /sbin/rc-update add asterisk default; \
644                 elif [ -f /etc/mandrake-release ]; then \
645                         $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk /etc/rc.d/init.d/asterisk; \
646                         /sbin/chkconfig --add asterisk; \
647                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
648                         $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk /etc/init.d/asterisk; \
649                         /sbin/chkconfig --add asterisk; \
650                 elif [ -f /etc/slackware-version ]; then \
651                         echo "Slackware is not currently supported, although an init script does exist for it." \
652                 else \
653                         echo "We could not install init scripts for your distribution."; \
654                 fi \
655         else \
656                 echo "We could not install init scripts for your operating system."; \
657         fi
658
659 sounds:
660         $(MAKE) -C sounds all
661
662 # If the cleancount has been changed, force a make clean.
663 # .cleancount is the global clean count, and .lastclean is the 
664 # last clean count we had
665
666 cleantest:
667         @cmp -s .cleancount .lastclean || $(MAKE) clean
668
669 $(SUBDIRS_UNINSTALL):
670         @$(MAKE) --no-print-directory -C $(@:-uninstall=) uninstall
671
672 _uninstall: $(SUBDIRS_UNINSTALL)
673         rm -f $(DESTDIR)$(MODULES_DIR)/*
674         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
675         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
676         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
677         rm -rf $(DESTDIR)$(ASTHEADERDIR)
678         rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
679         rm -f $(DESTDIR)$(ASTMANDIR)/man8/asterisk.8
680         rm -f $(DESTDIR)$(ASTMANDIR)/man8/astgenkey.8
681         rm -f $(DESTDIR)$(ASTMANDIR)/man8/autosupport.8
682         rm -f $(DESTDIR)$(ASTMANDIR)/man8/safe_asterisk.8
683         $(MAKE) -C sounds uninstall
684
685 uninstall: _uninstall
686         @echo " +--------- Asterisk Uninstall Complete -----+"  
687         @echo " + Asterisk binaries, sounds, man pages,     +"  
688         @echo " + headers, modules, and firmware builds,    +"  
689         @echo " + have all been uninstalled.                +"  
690         @echo " +                                           +"
691         @echo " + To remove ALL traces of Asterisk,         +"
692         @echo " + including configuration, spool            +"
693         @echo " + directories, and logs, run the following  +"
694         @echo " + command:                                  +"
695         @echo " +                                           +"
696 ifeq ($(MAKE), gmake)
697         @echo " +            $(MAKE) uninstall-all            +"  
698 else
699         @echo " +            $(MAKE) uninstall-all             +"  
700 endif
701         @echo " +-------------------------------------------+"  
702
703 uninstall-all: _uninstall
704         rm -rf $(DESTDIR)$(ASTLIBDIR)
705         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
706         rm -rf $(DESTDIR)$(ASTDATADIR)
707         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
708         rm -rf $(DESTDIR)$(ASTETCDIR)
709         rm -rf $(DESTDIR)$(ASTLOGDIR)
710
711 menuconfig: menuselect
712
713 gmenuconfig: gmenuselect
714
715 menuselect: menuselect/menuselect menuselect-tree
716         -@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!"
717
718 gmenuselect: menuselect/gmenuselect menuselect-tree
719         -@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!"
720
721 menuselect/menuselect: makeopts menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
722         @CC="$(HOST_CC)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
723
724 menuselect/gmenuselect: makeopts menuselect/menuselect.c menuselect/menuselect_gtk.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
725         @CC="$(HOST_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect _gmenuselect CONFIGURE_SILENT="--silent"
726
727 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
728         @echo "Generating input for menuselect ..."
729         @build_tools/prep_moduledeps > $@
730
731 asterisk.pdf:
732         $(MAKE) -C doc/tex asterisk.pdf
733
734 .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) menuselect.makeopts