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