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