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