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