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