ea07bd2860f6d185eee8c4c84c9550f66788929f
[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
61 # even though we could use '-include makeopts' here, use a wildcard
62 # lookup anyway, so that make won't try to build makeopts if it doesn't
63 # exist (other rules will force it to be built if needed)
64 ifneq ($(wildcard makeopts),)
65   include makeopts
66 endif
67
68 #Uncomment this to see all build commands instead of 'quiet' output
69 #NOISY_BUILD=yes
70
71 # Create OPTIONS variable
72 OPTIONS=
73
74 ASTTOPDIR:=$(shell pwd)
75
76 # Overwite config files on "make samples"
77 OVERWRITE=y
78
79 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
80 DEBUG=-g3
81
82 # Staging directory
83 # Files are copied here temporarily during the install process
84 # For example, make DESTDIR=/tmp/asterisk woud put things in
85 # /tmp/asterisk/etc/asterisk
86 # !!! Watch out, put no spaces or comments after the value !!!
87 #DESTDIR?=/tmp/asterisk
88
89 # Define standard directories for various platforms
90 # These apply if they are not redefined in asterisk.conf 
91 ifeq ($(OSARCH),SunOS)
92   ASTETCDIR=/var/etc/asterisk
93   ASTLIBDIR=/opt/asterisk/lib
94   ASTVARLIBDIR=/var/opt/asterisk
95   ASTSPOOLDIR=/var/spool/asterisk
96   ASTLOGDIR=/var/log/asterisk
97   ASTHEADERDIR=/opt/asterisk/include
98   ASTBINDIR=/opt/asterisk/bin
99   ASTSBINDIR=/opt/asterisk/sbin
100   ASTVARRUNDIR=/var/run/asterisk
101   ASTMANDIR=/opt/asterisk/man
102 else
103   ASTETCDIR=$(sysconfdir)/asterisk
104   ASTLIBDIR=$(libdir)/asterisk
105   ASTHEADERDIR=$(includedir)/asterisk
106   ASTBINDIR=$(bindir)
107   ASTSBINDIR=$(sbindir)
108   ASTSPOOLDIR=$(localstatedir)/spool/asterisk
109   ASTLOGDIR=$(localstatedir)/log/asterisk
110   ASTVARRUNDIR=$(localstatedir)/run
111   ASTMANDIR=$(mandir)
112 ifeq ($(OSARCH),FreeBSD)
113   ASTVARLIBDIR=$(prefix)/share/asterisk
114 else
115   ASTVARLIBDIR=$(localstatedir)/lib/asterisk
116 endif
117 endif
118 ifeq ($(ASTDATADIR),)
119   ASTDATADIR:=$(ASTVARLIBDIR)
120 endif
121
122 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
123 # when starting Asterisk
124 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
125 MODULES_DIR=$(ASTLIBDIR)/modules
126 AGI_DIR=$(ASTDATADIR)/agi-bin
127
128 # If you use Apache, you may determine by a grep 'DocumentRoot' of your httpd.conf file
129 HTTP_DOCSDIR=/var/www/html
130 # Determine by a grep 'ScriptAlias' of your Apache httpd.conf file
131 HTTP_CGIDIR=/var/www/cgi-bin
132
133 # Uncomment this to use the older DSP routines
134 #ASTCFLAGS+=-DOLD_DSP_ROUTINES
135
136 # If the file .asterisk.makeopts is present in your home directory, you can
137 # include all of your favorite menuselect options so that every time you download
138 # a new version of Asterisk, you don't have to run menuselect to set them. 
139 # The file /etc/asterisk.makeopts will also be included but can be overridden
140 # by the file in your home directory.
141
142 GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts)
143 USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts)
144
145 MOD_SUBDIR_CFLAGS=-I$(ASTTOPDIR)/include
146 OTHER_SUBDIR_CFLAGS=-I$(ASTTOPDIR)/include
147
148 ifeq ($(OSARCH),linux-gnu)
149   ifeq ($(PROC),x86_64)
150     # You must have GCC 3.4 to use k8, otherwise use athlon
151     PROC=k8
152     #PROC=athlon
153   endif
154
155   ifeq ($(PROC),sparc64)
156     #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
157     #This works for even old (2.96) versions of gcc and provides a small boost either way.
158     #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
159     #So we go lowest common available by gcc and go a step down, still a step up from
160     #the default as we now have a better instruction set to work with. - Belgarath
161     PROC=ultrasparc
162     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
163     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
164     OPTIONS+=-fomit-frame-pointer
165   endif
166
167   ifeq ($(PROC),arm)
168     # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
169     ifeq ($(SUB_PROC),maverick)
170       OPTIONS+=-fsigned-char -mcpu=ep9312
171     else
172       ifeq ($(SUB_PROC),xscale)
173         OPTIONS+=-fsigned-char -mcpu=xscale
174       else
175         OPTIONS+=-fsigned-char 
176       endif
177     endif
178   endif
179 endif
180
181 ASTCFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
182
183 ifeq ($(AST_DEVMODE),yes)
184   ASTCFLAGS+=-Werror -Wunused
185 endif
186
187 ifneq ($(findstring BSD,$(OSARCH)),)
188   ASTCFLAGS+=-I/usr/local/include
189   ASTLDFLAGS+=-L/usr/local/lib
190 endif
191
192 ifneq ($(PROC),ultrasparc)
193   ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
194 endif
195
196 ifeq ($(PROC),ppc)
197   ASTCFLAGS+=-fsigned-char
198 endif
199
200 ifeq ($(OSARCH),FreeBSD)
201   # -V is understood by BSD Make, not by GNU make.
202   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
203   ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
204   AST_LIBS+=$(shell if test  $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
205 endif
206
207 ifeq ($(OSARCH),NetBSD)
208   ASTCFLAGS+=-pthread -I/usr/pkg/include
209 endif
210
211 ifeq ($(OSARCH),OpenBSD)
212   ASTCFLAGS+=-pthread
213 endif
214
215 ifeq ($(OSARCH),SunOS)
216   ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include
217 endif
218
219 ASTERISKVERSION:=$(shell build_tools/make_version .)
220
221 ifneq ($(wildcard .version),)
222   ASTERISKVERSIONNUM:=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
223   RPMVERSION:=$(shell sed 's/[-\/:]/_/g' .version)
224 else
225   RPMVERSION=unknown
226 endif
227
228 ifneq ($(wildcard .svn),)
229   ASTERISKVERSIONNUM=999999
230 endif
231
232 ASTCFLAGS+=$(MALLOC_DEBUG)$(BUSYDETECT)$(OPTIONS)
233
234 MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs main
235 OTHER_SUBDIRS:=utils agi
236 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
237 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
238 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
239 SUBDIRS_CLEAN_DEPEND:=$(SUBDIRS:%=%-clean-depend)
240 MOD_SUBDIRS_DEPEND:=$(MOD_SUBDIRS:%=%-depend)
241 OTHER_SUBDIRS_DEPEND:=$(OTHER_SUBDIRS:%=%-depend)
242 SUBDIRS_DEPEND:=$(OTHER_SUBDIRS_DEPEND) $(MOD_SUBDIRS_DEPEND)
243 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
244 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
245 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
246 MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
247
248 ifneq ($(findstring darwin,$(OSARCH)),)
249   ASTCFLAGS+=-D__Darwin__
250   AUDIO_LIBS=-framework CoreAudio
251   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
252 else
253 # These are used for all but Darwin
254   SOLINK=-shared -Xlinker -x
255   ifneq ($(findstring BSD,$(OSARCH)),)
256     LDFLAGS+=-L/usr/local/lib
257   endif
258 endif
259
260 ifeq ($(OSARCH),SunOS)
261   SOLINK=-shared -fpic -L/usr/local/ssl/lib
262 endif
263
264 # This is used when generating the doxygen documentation
265 ifneq ($(DOT),:)
266   HAVEDOT=yes
267 else
268   HAVEDOT=no
269 endif
270
271 all: _all
272         @echo " +--------- Asterisk Build Complete ---------+"  
273         @echo " + Asterisk has successfully been built, and +"  
274         @echo " + can be installed by running:              +"
275         @echo " +                                           +"
276         @echo " +               make install                +"  
277         @echo " +-------------------------------------------+"  
278
279 _all: cleantest $(SUBDIRS)
280
281 makeopts: configure
282         @echo "****"
283         @echo "**** The configure script must be executed before running 'make'."
284         @echo "****"
285         @exit 1
286
287 menuselect.makeopts: menuselect/menuselect menuselect-tree
288         menuselect/menuselect --check-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts
289
290 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
291         @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
292
293 $(MOD_SUBDIRS_EMBED_LDFLAGS):
294         @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
295
296 $(MOD_SUBDIRS_EMBED_LIBS):
297         @echo "EMBED_LIBS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
298
299 makeopts.embed_rules: menuselect.makeopts
300         @echo "Generating embedded module rules ..."
301         @rm -f $@
302         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDSCRIPT)
303         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS)
304         @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS)
305
306 $(SUBDIRS): depend makeopts.embed_rules
307
308 # ensure that all module subdirectories are processed before 'main' during
309 # a parallel build, since if there are modules selected to be embedded the
310 # directories containing them must be completed before the main Asterisk
311 # binary can be built
312 main: $(filter-out main,$(MOD_SUBDIRS))
313
314 $(MOD_SUBDIRS):
315         @ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AST_LIBS="$(AST_LIBS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
316
317 $(OTHER_SUBDIRS):
318         @ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AUDIO_LIBS="$(AUDIO_LIBS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
319
320 defaults.h: makeopts
321         @build_tools/make_defaults_h > $@.tmp
322         @if cmp -s $@.tmp $@ ; then : ; else \
323                 mv $@.tmp $@ ; \
324         fi
325         @rm -f $@.tmp
326
327 include/asterisk/version.h:
328         @build_tools/make_version_h > $@.tmp
329         @if cmp -s $@.tmp $@ ; then : ; else \
330                 mv $@.tmp $@ ; \
331         fi
332         @rm -f $@.tmp
333
334 include/asterisk/buildopts.h: menuselect.makeopts
335         @build_tools/make_buildopts_h > $@.tmp
336         @if cmp -s $@.tmp $@ ; then : ; else \
337                 mv $@.tmp $@ ; \
338         fi
339         @rm -f $@.tmp
340
341 include/asterisk/build.h:
342         @build_tools/make_build_h > $@.tmp
343         @if cmp -s $@.tmp $@ ; then : ; else \
344                 mv $@.tmp $@ ; \
345         fi
346         @rm -f $@.tmp
347
348 $(SUBDIRS_CLEAN_DEPEND):
349         @$(MAKE) --no-print-directory -C $(@:-clean-depend=) clean-depend
350
351 $(SUBDIRS_CLEAN):
352         @$(MAKE) --no-print-directory -C $(@:-clean=) clean
353
354 clean-depend: $(SUBDIRS_CLEAN_DEPEND)
355
356 clean: $(SUBDIRS_CLEAN) clean-depend
357         rm -f defaults.h
358         rm -f include/asterisk/build.h
359         rm -f include/asterisk/version.h
360         rm -f .depend
361         @$(MAKE) -C menuselect clean
362         cp -f .cleancount .lastclean
363
364 dist-clean: distclean
365
366 distclean: clean
367         @$(MAKE) -C menuselect dist-clean
368         @$(MAKE) -C sounds dist-clean
369         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
370         rm -f makeopts.embed_rules
371         rm -f config.log config.status
372         rm -rf autom4te.cache
373         rm -f include/asterisk/autoconfig.h
374         rm -f include/asterisk/buildopts.h
375         rm -rf doc/api
376         rm -f build_tools/menuselect-deps
377
378 datafiles: _all
379         if [ x`$(ID) -un` = xroot ]; then CFLAGS="$(ASTCFLAGS)" sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
380 # Should static HTTP be installed during make samples or even with its own target ala
381 # webvoicemail?  There are portions here that *could* be customized but might also be
382 # improved a lot.  I'll put it here for now.
383         mkdir -p $(DESTDIR)$(ASTDATADIR)/static-http
384         for x in static-http/*; do \
385                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/static-http ; \
386         done
387         mkdir -p $(DESTDIR)$(ASTDATADIR)/images
388         for x in images/*.jpg; do \
389                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/images ; \
390         done
391         mkdir -p $(DESTDIR)$(AGI_DIR)
392         $(MAKE) -C sounds install
393
394 update: 
395         @if [ -d .svn ]; then \
396                 echo "Updating from Subversion..." ; \
397                 svn update | tee update.out; \
398                 rm -f .version; \
399                 if [ `grep -c ^C update.out` -gt 0 ]; then \
400                         echo ; echo "The following files have conflicts:" ; \
401                         grep ^C update.out | cut -b4- ; \
402                 fi ; \
403                 rm -f update.out; \
404                 $(MAKE) clean-depend; \
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 "; Changing the following lines may compromise your security." ; \
545                 echo ";[files]" ; \
546                 echo ";astctlpermissions = 0660" ; \
547                 echo ";astctlowner = root" ; \
548                 echo ";astctlgroup = apache" ; \
549                 echo ";astctl = asterisk.ctl" ; \
550                 echo ";[options]" ; \
551                 echo ";internal_timing = yes" ; \
552                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
553         else \
554                 echo "Skipping asterisk.conf creation"; \
555         fi
556         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
557         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
558         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
559                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
560         done
561         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
562         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
563                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
564         done
565
566 webvmail:
567         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
568         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
569         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
570         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
571         for x in images/*.gif; do \
572                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
573         done
574         @echo " +--------- Asterisk Web Voicemail ----------+"  
575         @echo " +                                           +"
576         @echo " + Asterisk Web Voicemail is installed in    +"
577         @echo " + your cgi-bin directory:                   +"
578         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
579         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
580         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
581         @echo " +                                           +"
582         @echo " + Other static items have been stored in:   +"
583         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
584         @echo " +                                           +"
585         @echo " + If these paths do not match your httpd    +"
586         @echo " + installation, correct the definitions     +"
587         @echo " + in your Makefile of HTTP_CGIDIR and       +"
588         @echo " + HTTP_DOCSDIR                              +"
589         @echo " +                                           +"
590         @echo " +-------------------------------------------+"  
591
592 spec: 
593         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
594
595 rpm: __rpm
596
597 __rpm: include/asterisk/version.h include/asterisk/buildopts.h spec
598         rm -rf /tmp/asterisk ; \
599         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
600         $(MAKE) DESTDIR=/tmp/asterisk install ; \
601         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
602         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
603         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
604         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
605
606 progdocs:
607         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
608         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
609
610 config:
611         @if [ "${OSARCH}" = "linux-gnu" ]; then \
612                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
613                         $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
614                         /sbin/chkconfig --add asterisk; \
615                 elif [ -f /etc/debian_version ]; then \
616                         $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk; \
617                         /usr/sbin/update-rc.d asterisk start 10 2 3 4 5 . stop 91 2 3 4 5 .; \
618                 elif [ -f /etc/gentoo-release ]; then \
619                         $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk /etc/init.d/asterisk; \
620                         /sbin/rc-update add asterisk default; \
621                 elif [ -f /etc/mandrake-release ]; then \
622                         $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk /etc/rc.d/init.d/asterisk; \
623                         /sbin/chkconfig --add asterisk; \
624                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
625                         $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk /etc/init.d/asterisk; \
626                         /sbin/chkconfig --add asterisk; \
627                 elif [ -f /etc/slackware-version ]; then \
628                         echo "Slackware is not currently supported, although an init script does exist for it." \
629                 else \
630                         echo "We could not install init scripts for your distribution."; \
631                 fi \
632         else \
633                 echo "We could not install init scripts for your operating system."; \
634         fi
635
636 $(MOD_SUBDIRS_DEPEND):
637         @ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
638
639 $(OTHER_SUBDIRS_DEPEND):
640         @ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
641
642 depend: include/asterisk/version.h include/asterisk/buildopts.h include/asterisk/build.h defaults.h $(SUBDIRS_DEPEND)
643
644 sounds:
645         $(MAKE) -C sounds all
646
647 # If the cleancount has been changed, force a make clean.
648 # .cleancount is the global clean count, and .lastclean is the 
649 # last clean count we had
650
651 cleantest:
652         @if ! cmp -s .cleancount .lastclean ; then \
653                 $(MAKE) clean;\
654         fi
655
656 $(SUBDIRS_UNINSTALL):
657         @$(MAKE) --no-print-directory -C $(@:-uninstall=) uninstall
658
659 _uninstall: $(SUBDIRS_UNINSTALL)
660         rm -f $(DESTDIR)$(MODULES_DIR)/*
661         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
662         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
663         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
664         rm -rf $(DESTDIR)$(ASTHEADERDIR)
665         rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
666         rm -rf $(DESTDIR)$(ASTMANDIR)/man8
667         $(MAKE) -C sounds uninstall
668
669 uninstall: _uninstall
670         @echo " +--------- Asterisk Uninstall Complete -----+"  
671         @echo " + Asterisk binaries, sounds, man pages,     +"  
672         @echo " + headers, modules, and firmware builds,    +"  
673         @echo " + have all been uninstalled.                +"  
674         @echo " +                                           +"
675         @echo " + To remove ALL traces of Asterisk,         +"
676         @echo " + including configuration, spool            +"
677         @echo " + directories, and logs, run the following  +"
678         @echo " + command:                                  +"
679         @echo " +                                           +"
680         @echo " +            $(MAKE) uninstall-all             +"  
681         @echo " +-------------------------------------------+"  
682
683 uninstall-all: _uninstall
684         rm -rf $(DESTDIR)$(ASTLIBDIR)
685         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
686         rm -rf $(DESTDIR)$(ASTDATADIR)
687         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
688         rm -rf $(DESTDIR)$(ASTETCDIR)
689         rm -rf $(DESTDIR)$(ASTLOGDIR)
690
691 menuconfig: menuselect
692
693 menuselect: menuselect/menuselect menuselect-tree
694         -@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!"
695
696 menuselect/menuselect: makeopts menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
697         @unset CC LD AR RANLIB && $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
698
699 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
700         @echo "Generating input for menuselect ..."
701         @build_tools/prep_moduledeps > $@
702
703 .PHONY: menuselect main sounds clean clean-depend dist-clean distclean all prereqs depend cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_CLEAN_DEPEND) $(SUBDIRS_DEPEND) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS)