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