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