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