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