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