Merged revisions 48525 via svnmerge from
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999-2006, Digium, Inc.
7 #
8 # Mark Spencer <markster@digium.com>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 # All Makefiles use the following variables:
15 #
16 # ASTCFLAGS - compiler options
17 # ASTLDFLAGS - linker flags (not libraries)
18 # AST_LIBS - libraries to build binaries XXX
19 # LIBS - additional libraries, at top-level for all links,
20 #      on a single object just for that object
21 # SOLINK - linker flags used only for creating shared objects (.so files),
22 #      used for all .so links
23 #
24 # Default values fo ASTCFLAGS and ASTLDFLAGS can be specified in the
25 # environment when running make, as follows:
26 #
27 # $ ASTCFLAGS="-Werror" make
28
29 export ASTTOPDIR
30 export ASTERISKVERSION
31 export ASTERISKVERSIONNUM
32 export INSTALL_PATH
33 export ASTETCDIR
34 export ASTVARRUNDIR
35 export MODULES_DIR
36 export ASTSPOOLDIR
37 export ASTVARLIBDIR
38 export ASTDATADIR
39 export ASTLOGDIR
40 export ASTLIBDIR
41 export ASTMANDIR
42 export ASTHEADERDIR
43 export ASTBINDIR
44 export ASTSBINDIR
45 export AGI_DIR
46 export ASTCONFPATH
47 export NOISY_BUILD
48 export MENUSELECT_CFLAGS
49 export CC
50 export CXX
51 export AR
52 export RANLIB
53 export HOST_CC
54 export STATIC_BUILD
55 export INSTALL
56 export DESTDIR
57 export PROC
58 export SOLINK
59 export STRIP
60 export DOWNLOAD
61
62 # even though we could use '-include makeopts' here, use a wildcard
63 # lookup anyway, so that make won't try to build makeopts if it doesn't
64 # exist (other rules will force it to be built if needed)
65 ifneq ($(wildcard makeopts),)
66   include makeopts
67 endif
68
69 #Uncomment this to see all build commands instead of 'quiet' output
70 #NOISY_BUILD=yes
71
72 # Create OPTIONS variable
73 OPTIONS=
74
75 ASTTOPDIR:=$(shell pwd)
76
77 # Overwite config files on "make samples"
78 OVERWRITE=y
79
80 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
81 DEBUG=-g3
82
83 # Staging directory
84 # Files are copied here temporarily during the install process
85 # For example, make DESTDIR=/tmp/asterisk woud put things in
86 # /tmp/asterisk/etc/asterisk
87 # !!! Watch out, put no spaces or comments after the value !!!
88 #DESTDIR?=/tmp/asterisk
89
90 # Define standard directories for various platforms
91 # These apply if they are not redefined in asterisk.conf 
92 ifeq ($(OSARCH),SunOS)
93   ASTETCDIR=/var/etc/asterisk
94   ASTLIBDIR=/opt/asterisk/lib
95   ASTVARLIBDIR=/var/opt/asterisk
96   ASTSPOOLDIR=/var/spool/asterisk
97   ASTLOGDIR=/var/log/asterisk
98   ASTHEADERDIR=/opt/asterisk/include
99   ASTBINDIR=/opt/asterisk/bin
100   ASTSBINDIR=/opt/asterisk/sbin
101   ASTVARRUNDIR=/var/run/asterisk
102   ASTMANDIR=/opt/asterisk/man
103 else
104   ASTETCDIR=$(sysconfdir)/asterisk
105   ASTLIBDIR=$(libdir)/asterisk
106   ASTHEADERDIR=$(includedir)/asterisk
107   ASTBINDIR=$(bindir)
108   ASTSBINDIR=$(sbindir)
109   ASTSPOOLDIR=$(localstatedir)/spool/asterisk
110   ASTLOGDIR=$(localstatedir)/log/asterisk
111   ASTVARRUNDIR=$(localstatedir)/run
112   ASTMANDIR=$(mandir)
113 ifeq ($(OSARCH),FreeBSD)
114   ASTVARLIBDIR=$(prefix)/share/asterisk
115 else
116   ASTVARLIBDIR=$(localstatedir)/lib/asterisk
117 endif
118 endif
119 ifeq ($(ASTDATADIR),)
120   ASTDATADIR:=$(ASTVARLIBDIR)
121 endif
122
123 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
124 # when starting Asterisk
125 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
126 MODULES_DIR=$(ASTLIBDIR)/modules
127 AGI_DIR=$(ASTDATADIR)/agi-bin
128
129 # If you use Apache, you may determine by a grep 'DocumentRoot' of your httpd.conf file
130 HTTP_DOCSDIR=/var/www/html
131 # Determine by a grep 'ScriptAlias' of your Apache httpd.conf file
132 HTTP_CGIDIR=/var/www/cgi-bin
133
134 # Uncomment this to use the older DSP routines
135 #ASTCFLAGS+=-DOLD_DSP_ROUTINES
136
137 # If the file .asterisk.makeopts is present in your home directory, you can
138 # include all of your favorite menuselect options so that every time you download
139 # a new version of Asterisk, you don't have to run menuselect to set them. 
140 # The file /etc/asterisk.makeopts will also be included but can be overridden
141 # by the file in your home directory.
142
143 GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts)
144 USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts)
145
146 MOD_SUBDIR_CFLAGS=-I$(ASTTOPDIR)/include
147 OTHER_SUBDIR_CFLAGS=-I$(ASTTOPDIR)/include
148
149 ifeq ($(OSARCH),linux-gnu)
150   ifeq ($(PROC),x86_64)
151     # You must have GCC 3.4 to use k8, otherwise use athlon
152     PROC=k8
153     #PROC=athlon
154   endif
155
156   ifeq ($(PROC),sparc64)
157     #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
158     #This works for even old (2.96) versions of gcc and provides a small boost either way.
159     #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
160     #So we go lowest common available by gcc and go a step down, still a step up from
161     #the default as we now have a better instruction set to work with. - Belgarath
162     PROC=ultrasparc
163     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
164     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
165     OPTIONS+=-fomit-frame-pointer
166   endif
167
168   ifeq ($(PROC),arm)
169     # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
170     ifeq ($(SUB_PROC),maverick)
171       OPTIONS+=-fsigned-char -mcpu=ep9312
172     else
173       ifeq ($(SUB_PROC),xscale)
174         OPTIONS+=-fsigned-char -mcpu=xscale
175       else
176         OPTIONS+=-fsigned-char 
177       endif
178     endif
179   endif
180 endif
181
182 ASTCFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
183
184 ASTCFLAGS+=-include $(ASTTOPDIR)/include/asterisk/autoconfig.h
185
186 ifeq ($(AST_DEVMODE),yes)
187   ASTCFLAGS+=-Werror -Wunused
188 endif
189
190 ifneq ($(findstring BSD,$(OSARCH)),)
191   ASTCFLAGS+=-I/usr/local/include
192   ASTLDFLAGS+=-L/usr/local/lib
193 endif
194
195 ifneq ($(PROC),ultrasparc)
196   ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
197 endif
198
199 ifeq ($(PROC),ppc)
200   ASTCFLAGS+=-fsigned-char
201 endif
202
203 ifeq ($(OSARCH),FreeBSD)
204   # -V is understood by BSD Make, not by GNU make.
205   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
206   ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
207   AST_LIBS+=$(shell if test  $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
208 endif
209
210 ifeq ($(OSARCH),NetBSD)
211   ASTCFLAGS+=-pthread -I/usr/pkg/include
212 endif
213
214 ifeq ($(OSARCH),OpenBSD)
215   ASTCFLAGS+=-pthread
216 endif
217
218 ifeq ($(OSARCH),SunOS)
219   ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include
220 endif
221
222 ASTERISKVERSION:=$(shell build_tools/make_version .)
223
224 ifneq ($(wildcard .version),)
225   ASTERISKVERSIONNUM:=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
226   RPMVERSION:=$(shell sed 's/[-\/:]/_/g' .version)
227 else
228   RPMVERSION=unknown
229 endif
230
231 ifneq ($(wildcard .svn),)
232   ASTERISKVERSIONNUM=999999
233 endif
234
235 ASTCFLAGS+=$(MALLOC_DEBUG)$(BUSYDETECT)$(OPTIONS)
236
237 MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs main
238 OTHER_SUBDIRS:=utils agi
239 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
240 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
241 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
242 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
243 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
244 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
245 MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
246
247 ifneq ($(findstring darwin,$(OSARCH)),)
248   ASTCFLAGS+=-D__Darwin__
249   AUDIO_LIBS=-framework CoreAudio
250   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
251 else
252 # These are used for all but Darwin
253   SOLINK=-shared -Xlinker -x
254   ifneq ($(findstring BSD,$(OSARCH)),)
255     LDFLAGS+=-L/usr/local/lib
256   endif
257 endif
258
259 ifeq ($(OSARCH),SunOS)
260   SOLINK=-shared -fpic -L/usr/local/ssl/lib
261 endif
262
263 # This is used when generating the doxygen documentation
264 ifneq ($(DOT),:)
265   HAVEDOT=yes
266 else
267   HAVEDOT=no
268 endif
269
270 all: _all
271         @echo " +--------- Asterisk Build Complete ---------+"  
272         @echo " + Asterisk has successfully been built, and +"  
273         @echo " + can be installed by running:              +"
274         @echo " +                                           +"
275         @echo " +               $(MAKE) install                +"  
276         @echo " +-------------------------------------------+"  
277
278 _all: cleantest $(SUBDIRS)
279
280 makeopts: configure
281         @echo "****"
282         @echo "**** The configure script must be executed before running '$(MAKE)'."
283         @echo "****"
284         @exit 1
285
286 menuselect.makeopts: menuselect/menuselect menuselect-tree
287         menuselect/menuselect --check-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts
288
289 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
290         @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
291
292 $(MOD_SUBDIRS_EMBED_LDFLAGS):
293         @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
294
295 $(MOD_SUBDIRS_EMBED_LIBS):
296         @echo "EMBED_LIBS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
297
298 makeopts.embed_rules: menuselect.makeopts
299         @echo "Generating embedded module rules ..."
300         @rm -f $@
301         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDSCRIPT)
302         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS)
303         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS)
304
305 $(SUBDIRS): include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
306
307 # ensure that all module subdirectories are processed before 'main' during
308 # a parallel build, since if there are modules selected to be embedded the
309 # directories containing them must be completed before the main Asterisk
310 # binary can be built
311 main: $(filter-out main,$(MOD_SUBDIRS))
312
313 $(MOD_SUBDIRS):
314         @ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AST_LIBS="$(AST_LIBS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
315
316 $(OTHER_SUBDIRS):
317         @ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AUDIO_LIBS="$(AUDIO_LIBS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
318
319 defaults.h: makeopts
320         @build_tools/make_defaults_h > $@.tmp
321         @if cmp -s $@.tmp $@ ; then : ; else \
322                 mv $@.tmp $@ ; \
323         fi
324         @rm -f $@.tmp
325
326 include/asterisk/version.h:
327         @build_tools/make_version_h > $@.tmp
328         @if cmp -s $@.tmp $@ ; then : ; else \
329                 mv $@.tmp $@ ; \
330         fi
331         @rm -f $@.tmp
332
333 include/asterisk/buildopts.h: menuselect.makeopts
334         @build_tools/make_buildopts_h > $@.tmp
335         @if cmp -s $@.tmp $@ ; then : ; else \
336                 mv $@.tmp $@ ; \
337         fi
338         @rm -f $@.tmp
339
340 include/asterisk/build.h:
341         @build_tools/make_build_h > $@.tmp
342         @if cmp -s $@.tmp $@ ; then : ; else \
343                 mv $@.tmp $@ ; \
344         fi
345         @rm -f $@.tmp
346
347 $(SUBDIRS_CLEAN):
348         @$(MAKE) --no-print-directory -C $(@:-clean=) clean
349
350 clean: $(SUBDIRS_CLEAN)
351         rm -f defaults.h
352         rm -f include/asterisk/build.h
353         rm -f include/asterisk/version.h
354         @$(MAKE) -C menuselect clean
355         cp -f .cleancount .lastclean
356
357 dist-clean: distclean
358
359 distclean: clean
360         @$(MAKE) -C menuselect dist-clean
361         @$(MAKE) -C sounds dist-clean
362         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
363         rm -f makeopts.embed_rules
364         rm -f config.log config.status
365         rm -rf autom4te.cache
366         rm -f include/asterisk/autoconfig.h
367         rm -f include/asterisk/buildopts.h
368         rm -rf doc/api
369         rm -f build_tools/menuselect-deps
370
371 datafiles: _all
372         if [ x`$(ID) -un` = xroot ]; then CFLAGS="$(ASTCFLAGS)" sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
373 # Should static HTTP be installed during make samples or even with its own target ala
374 # webvoicemail?  There are portions here that *could* be customized but might also be
375 # improved a lot.  I'll put it here for now.
376         mkdir -p $(DESTDIR)$(ASTDATADIR)/static-http
377         for x in static-http/*; do \
378                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/static-http ; \
379         done
380         mkdir -p $(DESTDIR)$(ASTDATADIR)/images
381         for x in images/*.jpg; do \
382                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/images ; \
383         done
384         mkdir -p $(DESTDIR)$(AGI_DIR)
385         $(MAKE) -C sounds install
386
387 update: 
388         @if [ -d .svn ]; then \
389                 echo "Updating from Subversion..." ; \
390                 svn update | tee update.out; \
391                 rm -f .version; \
392                 if [ `grep -c ^C update.out` -gt 0 ]; then \
393                         echo ; echo "The following files have conflicts:" ; \
394                         grep ^C update.out | cut -b4- ; \
395                 fi ; \
396                 rm -f update.out; \
397         else \
398                 echo "Not under version control";  \
399         fi
400
401 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
402 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
403
404 bininstall: _all
405         mkdir -p $(DESTDIR)$(MODULES_DIR)
406         mkdir -p $(DESTDIR)$(ASTSBINDIR)
407         mkdir -p $(DESTDIR)$(ASTETCDIR)
408         mkdir -p $(DESTDIR)$(ASTBINDIR)
409         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
410         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
411         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
412         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
413         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
414         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
415         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
416         $(INSTALL) -m 755 main/asterisk $(DESTDIR)$(ASTSBINDIR)/
417         $(LN) -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
418         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
419         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
420         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
421                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
422                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
423         fi
424         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
425         $(INSTALL) -m 644 include/asterisk.h $(DESTDIR)$(includedir)
426         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
427         if [ -n "$(OLDHEADERS)" ]; then \
428                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
429         fi
430         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
431         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
432         mkdir -p $(DESTDIR)$(ASTDATADIR)/keys
433         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware
434         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware/iax
435         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
436         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys
437         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys
438         $(INSTALL) -m 644 doc/asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
439         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
440         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
441         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
442         if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
443                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
444         fi
445
446 $(SUBDIRS_INSTALL):
447         @DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" $(MAKE) -C $(@:-install=) install
448
449 NEWMODS=$(notdir $(wildcard */*.so))
450 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
451
452 oldmodcheck:
453         @if [ -n "$(OLDMODS)" ]; then \
454                 echo " WARNING WARNING WARNING" ;\
455                 echo "" ;\
456                 echo " Your Asterisk modules directory, located at" ;\
457                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
458                 echo " contains modules that were not installed by this " ;\
459                 echo " version of Asterisk. Please ensure that these" ;\
460                 echo " modules are compatible with this version before" ;\
461                 echo " attempting to run Asterisk." ;\
462                 echo "" ;\
463                 for f in $(OLDMODS); do \
464                         echo "    $$f" ;\
465                 done ;\
466                 echo "" ;\
467                 echo " WARNING WARNING WARNING" ;\
468         fi
469
470 install: datafiles bininstall $(SUBDIRS_INSTALL)
471         @if [ -x /usr/sbin/asterisk-post-install ]; then \
472                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
473         fi
474         @echo " +---- Asterisk Installation Complete -------+"  
475         @echo " +                                           +"
476         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
477         @echo " +                                           +"
478         @echo " + Asterisk has successfully been installed. +"  
479         @echo " + If you would like to install the sample   +"  
480         @echo " + configuration files (overwriting any      +"
481         @echo " + existing config files), run:              +"  
482         @echo " +                                           +"
483         @echo " +               $(MAKE) samples                +"
484         @echo " +                                           +"
485         @echo " +-----------------  or ---------------------+"
486         @echo " +                                           +"
487         @echo " + You can go ahead and install the asterisk +"
488         @echo " + program documentation now or later run:   +"
489         @echo " +                                           +"
490         @echo " +              $(MAKE) progdocs                +"
491         @echo " +                                           +"
492         @echo " + **Note** This requires that you have      +"
493         @echo " + doxygen installed on your local system    +"
494         @echo " +-------------------------------------------+"
495         @$(MAKE) -s oldmodcheck
496
497 upgrade: bininstall
498
499 adsi:
500         mkdir -p $(DESTDIR)$(ASTETCDIR)
501         for x in configs/*.adsi; do \
502                 if [ ! -f $(DESTDIR)$(ASTETCDIR)/$$x ]; then \
503                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
504                 fi ; \
505         done
506
507 samples: adsi
508         mkdir -p $(DESTDIR)$(ASTETCDIR)
509         for x in configs/*.sample; do \
510                 if [ -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ]; then \
511                         if [ "$(OVERWRITE)" = "y" ]; then \
512                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $$x ; then \
513                                         echo "Config file $$x is unchanged"; \
514                                         continue; \
515                                 fi ; \
516                                 mv -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`.old ; \
517                         else \
518                                 echo "Skipping config file $$x"; \
519                                 continue; \
520                         fi ;\
521                 fi ; \
522                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ;\
523         done
524         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
525                 ( \
526                 echo "[directories]" ; \
527                 echo "astetcdir => $(ASTETCDIR)" ; \
528                 echo "astmoddir => $(MODULES_DIR)" ; \
529                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
530                 echo "astdatadir => $(ASTDATADIR)" ; \
531                 echo "astagidir => $(AGI_DIR)" ; \
532                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
533                 echo "astrundir => $(ASTVARRUNDIR)" ; \
534                 echo "astlogdir => $(ASTLOGDIR)" ; \
535                 echo "" ; \
536                 echo "; Changing the following lines may compromise your security." ; \
537                 echo ";[files]" ; \
538                 echo ";astctlpermissions = 0660" ; \
539                 echo ";astctlowner = root" ; \
540                 echo ";astctlgroup = apache" ; \
541                 echo ";astctl = asterisk.ctl" ; \
542                 echo ";[options]" ; \
543                 echo ";internal_timing = yes" ; \
544                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
545         else \
546                 echo "Skipping asterisk.conf creation"; \
547         fi
548         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
549         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
550         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
551                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
552         done
553         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
554         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
555                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
556         done
557
558 webvmail:
559         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
560         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
561         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
562         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
563         for x in images/*.gif; do \
564                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
565         done
566         @echo " +--------- Asterisk Web Voicemail ----------+"  
567         @echo " +                                           +"
568         @echo " + Asterisk Web Voicemail is installed in    +"
569         @echo " + your cgi-bin directory:                   +"
570         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
571         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
572         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
573         @echo " +                                           +"
574         @echo " + Other static items have been stored in:   +"
575         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
576         @echo " +                                           +"
577         @echo " + If these paths do not match your httpd    +"
578         @echo " + installation, correct the definitions     +"
579         @echo " + in your Makefile of HTTP_CGIDIR and       +"
580         @echo " + HTTP_DOCSDIR                              +"
581         @echo " +                                           +"
582         @echo " +-------------------------------------------+"  
583
584 spec: 
585         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
586
587 rpm: __rpm
588
589 __rpm: include/asterisk/version.h include/asterisk/buildopts.h spec
590         rm -rf /tmp/asterisk ; \
591         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
592         $(MAKE) DESTDIR=/tmp/asterisk install ; \
593         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
594         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
595         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
596         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
597
598 progdocs:
599         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
600         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
601
602 config:
603         @if [ "${OSARCH}" = "linux-gnu" ]; then \
604                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
605                         $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
606                         /sbin/chkconfig --add asterisk; \
607                 elif [ -f /etc/debian_version ]; then \
608                         $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk; \
609                         /usr/sbin/update-rc.d asterisk start 10 2 3 4 5 . stop 91 2 3 4 5 .; \
610                 elif [ -f /etc/gentoo-release ]; then \
611                         $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk /etc/init.d/asterisk; \
612                         /sbin/rc-update add asterisk default; \
613                 elif [ -f /etc/mandrake-release ]; then \
614                         $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk /etc/rc.d/init.d/asterisk; \
615                         /sbin/chkconfig --add asterisk; \
616                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
617                         $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk /etc/init.d/asterisk; \
618                         /sbin/chkconfig --add asterisk; \
619                 elif [ -f /etc/slackware-version ]; then \
620                         echo "Slackware is not currently supported, although an init script does exist for it." \
621                 else \
622                         echo "We could not install init scripts for your distribution."; \
623                 fi \
624         else \
625                 echo "We could not install init scripts for your operating system."; \
626         fi
627
628 sounds:
629         $(MAKE) -C sounds all
630
631 # If the cleancount has been changed, force a make clean.
632 # .cleancount is the global clean count, and .lastclean is the 
633 # last clean count we had
634
635 cleantest:
636         @if ! cmp -s .cleancount .lastclean ; then \
637                 $(MAKE) clean;\
638         fi
639
640 $(SUBDIRS_UNINSTALL):
641         @$(MAKE) --no-print-directory -C $(@:-uninstall=) uninstall
642
643 _uninstall: $(SUBDIRS_UNINSTALL)
644         rm -f $(DESTDIR)$(MODULES_DIR)/*
645         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
646         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
647         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
648         rm -rf $(DESTDIR)$(ASTHEADERDIR)
649         rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
650         rm -rf $(DESTDIR)$(ASTMANDIR)/man8
651         $(MAKE) -C sounds uninstall
652
653 uninstall: _uninstall
654         @echo " +--------- Asterisk Uninstall Complete -----+"  
655         @echo " + Asterisk binaries, sounds, man pages,     +"  
656         @echo " + headers, modules, and firmware builds,    +"  
657         @echo " + have all been uninstalled.                +"  
658         @echo " +                                           +"
659         @echo " + To remove ALL traces of Asterisk,         +"
660         @echo " + including configuration, spool            +"
661         @echo " + directories, and logs, run the following  +"
662         @echo " + command:                                  +"
663         @echo " +                                           +"
664         @echo " +            $(MAKE) uninstall-all             +"  
665         @echo " +-------------------------------------------+"  
666
667 uninstall-all: _uninstall
668         rm -rf $(DESTDIR)$(ASTLIBDIR)
669         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
670         rm -rf $(DESTDIR)$(ASTDATADIR)
671         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
672         rm -rf $(DESTDIR)$(ASTETCDIR)
673         rm -rf $(DESTDIR)$(ASTLOGDIR)
674
675 menuconfig: menuselect
676
677 menuselect: menuselect/menuselect menuselect-tree
678         -@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!"
679
680 menuselect/menuselect: makeopts menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
681         @unset CC LD AR RANLIB && $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
682
683 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
684         @echo "Generating input for menuselect ..."
685         @build_tools/prep_moduledeps > $@
686
687 .PHONY: menuselect main sounds clean dist-clean distclean all prereqs cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS)