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