will i ever get precedences for windows right ?
[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 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
281   SOLINK=-Xlinker -r
282 endif
283
284 # This is used when generating the doxygen documentation
285 ifneq ($(DOT),:)
286   HAVEDOT=yes
287 else
288   HAVEDOT=no
289 endif
290
291 # $(MAKE) is printed in several places, and we want it to be a
292 # fixed size string. Define a variable whose name has also the
293 # same size, so we can easily align text.
294 ifeq ($(MAKE), gmake)
295         mK="gmake"
296 else
297         mK=" make"
298 endif
299
300 # comment to print directories during submakes
301 PRINT_DIR:= --no-print-directory
302
303 all: _all
304         @echo " +--------- Asterisk Build Complete ---------+"  
305         @echo " + Asterisk has successfully been built, and +"  
306         @echo " + can be installed by running:              +"
307         @echo " +                                           +"
308         @echo " +               $(mK) install               +"  
309         @echo " +-------------------------------------------+"  
310
311 _all: cleantest $(SUBDIRS)
312
313 makeopts: configure
314         @echo "****"
315         @echo "**** The configure script must be executed before running '$(MAKE)'." 
316         @echo "****               Please run \"./configure\"."
317         @echo "****"
318         @exit 1
319
320 menuselect.makeopts: menuselect/menuselect menuselect-tree
321         menuselect/menuselect --check-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts
322
323 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
324         @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet $(PRINT_DIR) -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
325
326 $(MOD_SUBDIRS_EMBED_LDFLAGS):
327         @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet $(PRINT_DIR) -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
328
329 $(MOD_SUBDIRS_EMBED_LIBS):
330         @echo "EMBED_LIBS+="`$(MAKE) --quiet $(PRINT_DIR) -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
331
332 makeopts.embed_rules: menuselect.makeopts
333         @echo "Generating embedded module rules ..."
334         @rm -f $@
335         @$(MAKE) $(PRINT_DIR) $(MOD_SUBDIRS_EMBED_LDSCRIPT)
336         @$(MAKE) $(PRINT_DIR) $(MOD_SUBDIRS_EMBED_LDFLAGS)
337         @$(MAKE) $(PRINT_DIR) $(MOD_SUBDIRS_EMBED_LIBS)
338
339 $(SUBDIRS): include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
340
341 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
342     # Non-windows:
343     # ensure that all module subdirectories are processed before 'main' during
344     # a parallel build, since if there are modules selected to be embedded the
345     # directories containing them must be completed before the main Asterisk
346     # binary can be built
347 main: $(filter-out main,$(MOD_SUBDIRS))
348 else
349     # Windows: we need to build main (i.e. the asterisk dll) first,
350     # followed by res, followed by the other directories, because
351     # dll symbols must be resolved during linking and not at runtime.
352 D1:= $(filter-out main,$(MOD_SUBDIRS))
353 D1:= $(filter-out res,$(D1))
354
355 $(D1): res
356 res:    main
357 endif
358
359 $(MOD_SUBDIRS):
360         @ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(MAKE) $(PRINT_DIR) --no-builtin-rules -C $@ SUBDIR=$@ all
361
362 $(OTHER_SUBDIRS):
363         @ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(MAKE) $(PRINT_DIR) --no-builtin-rules -C $@ SUBDIR=$@ all
364
365 defaults.h: makeopts
366         @build_tools/make_defaults_h > $@.tmp
367         @if cmp -s $@.tmp $@ ; then : ; else \
368                 mv $@.tmp $@ ; \
369         fi
370         @rm -f $@.tmp
371
372 include/asterisk/version.h:
373         @build_tools/make_version_h > $@.tmp
374         @if cmp -s $@.tmp $@ ; then : ; else \
375                 mv $@.tmp $@ ; \
376         fi
377         @rm -f $@.tmp
378
379 include/asterisk/buildopts.h: menuselect.makeopts
380         @build_tools/make_buildopts_h > $@.tmp
381         @if cmp -s $@.tmp $@ ; then : ; else \
382                 mv $@.tmp $@ ; \
383         fi
384         @rm -f $@.tmp
385
386 include/asterisk/build.h:
387         @build_tools/make_build_h > $@.tmp
388         @if cmp -s $@.tmp $@ ; then : ; else \
389                 mv $@.tmp $@ ; \
390         fi
391         @rm -f $@.tmp
392
393 $(SUBDIRS_CLEAN):
394         @$(MAKE) $(PRINT_DIR) -C $(@:-clean=) clean
395
396 $(SUBDIRS_DIST_CLEAN):
397         @$(MAKE) $(PRINT_DIR) -C $(@:-dist-clean=) dist-clean
398
399 clean: $(SUBDIRS_CLEAN)
400         rm -f defaults.h
401         rm -f include/asterisk/build.h
402         rm -f include/asterisk/version.h
403         @$(MAKE) -C menuselect clean
404         cp -f .cleancount .lastclean
405
406 dist-clean: distclean
407
408 distclean: $(SUBDIRS_DIST_CLEAN) clean
409         @$(MAKE) -C menuselect dist-clean
410         @$(MAKE) -C sounds dist-clean
411         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
412         rm -f makeopts.embed_rules
413         rm -f config.log config.status
414         rm -rf autom4te.cache
415         rm -f include/asterisk/autoconfig.h
416         rm -f include/asterisk/buildopts.h
417         rm -rf doc/api
418         rm -f build_tools/menuselect-deps
419
420 datafiles: _all
421         if [ x`$(ID) -un` = xroot ]; then CFLAGS="$(ASTCFLAGS)" sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
422 # Should static HTTP be installed during make samples or even with its own target ala
423 # webvoicemail?  There are portions here that *could* be customized but might also be
424 # improved a lot.  I'll put it here for now.
425         mkdir -p $(DESTDIR)$(ASTDATADIR)/static-http
426         for x in static-http/*; do \
427                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/static-http ; \
428         done
429         mkdir -p $(DESTDIR)$(ASTDATADIR)/images
430         for x in images/*.jpg; do \
431                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/images ; \
432         done
433         mkdir -p $(DESTDIR)$(AGI_DIR)
434         $(MAKE) -C sounds install
435
436 update: 
437         @if [ -d .svn ]; then \
438                 echo "Updating from Subversion..." ; \
439                 svn update | tee update.out; \
440                 rm -f .version; \
441                 if [ `grep -c ^C update.out` -gt 0 ]; then \
442                         echo ; echo "The following files have conflicts:" ; \
443                         grep ^C update.out | cut -b4- ; \
444                 fi ; \
445                 rm -f update.out; \
446         else \
447                 echo "Not under version control";  \
448         fi
449
450 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
451 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
452
453 bininstall: _all
454         mkdir -p $(DESTDIR)$(MODULES_DIR)
455         mkdir -p $(DESTDIR)$(ASTSBINDIR)
456         mkdir -p $(DESTDIR)$(ASTETCDIR)
457         mkdir -p $(DESTDIR)$(ASTBINDIR)
458         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
459         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
460         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
461         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
462         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
463         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
464         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
465         $(INSTALL) -m 755 main/asterisk $(DESTDIR)$(ASTSBINDIR)/
466         $(LN) -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
467         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
468         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
469         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
470                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
471                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
472         fi
473         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
474         $(INSTALL) -m 644 include/asterisk.h $(DESTDIR)$(includedir)
475         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
476         if [ -n "$(OLDHEADERS)" ]; then \
477                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
478         fi
479         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
480         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
481         mkdir -p $(DESTDIR)$(ASTDATADIR)/keys
482         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware
483         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware/iax
484         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
485         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys
486         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys
487         $(INSTALL) -m 644 doc/asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
488         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
489         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
490         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
491         if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
492                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
493         fi
494
495 $(SUBDIRS_INSTALL):
496         @DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" $(MAKE) -C $(@:-install=) install
497
498 NEWMODS=$(notdir $(wildcard */*.so))
499 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
500
501 oldmodcheck:
502         @if [ -n "$(OLDMODS)" ]; then \
503                 echo " WARNING WARNING WARNING" ;\
504                 echo "" ;\
505                 echo " Your Asterisk modules directory, located at" ;\
506                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
507                 echo " contains modules that were not installed by this " ;\
508                 echo " version of Asterisk. Please ensure that these" ;\
509                 echo " modules are compatible with this version before" ;\
510                 echo " attempting to run Asterisk." ;\
511                 echo "" ;\
512                 for f in $(OLDMODS); do \
513                         echo "    $$f" ;\
514                 done ;\
515                 echo "" ;\
516                 echo " WARNING WARNING WARNING" ;\
517         fi
518
519 install: datafiles bininstall $(SUBDIRS_INSTALL)
520         @if [ -x /usr/sbin/asterisk-post-install ]; then \
521                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
522         fi
523         @echo " +---- Asterisk Installation Complete -------+"  
524         @echo " +                                           +"
525         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
526         @echo " +                                           +"
527         @echo " + Asterisk has successfully been installed. +"  
528         @echo " + If you would like to install the sample   +"  
529         @echo " + configuration files (overwriting any      +"
530         @echo " + existing config files), run:              +"  
531         @echo " +                                           +"
532         @echo " +               $(mK) samples               +"
533         @echo " +                                           +"
534         @echo " +-----------------  or ---------------------+"
535         @echo " +                                           +"
536         @echo " + You can go ahead and install the asterisk +"
537         @echo " + program documentation now or later run:   +"
538         @echo " +                                           +"
539         @echo " +              $(mK) progdocs               +"
540         @echo " +                                           +"
541         @echo " + **Note** This requires that you have      +"
542         @echo " + doxygen installed on your local system    +"
543         @echo " +-------------------------------------------+"
544         @$(MAKE) -s oldmodcheck
545
546 upgrade: bininstall
547
548 # XXX why *.adsi is installed first ?
549 adsi:
550         @echo Installing adsi config files...
551         @mkdir -p $(DESTDIR)$(ASTETCDIR)
552         @for x in configs/*.adsi; do \
553                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
554                 if [ -f $${dst} ] ; then \
555                         echo "Overwriting $$x" ; \
556                 else \
557                         echo "Installing $$x" ; \
558                 fi ; \
559                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
560         done
561
562 samples: adsi
563         @echo Installing other config files...
564         @mkdir -p $(DESTDIR)$(ASTETCDIR)
565         @for x in configs/*.sample; do \
566                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`" ;        \
567                 if [ -f $${dst} ]; then \
568                         if [ "$(OVERWRITE)" = "y" ]; then \
569                                 if cmp -s $${dst} $$x ; then \
570                                         echo "Config file $$x is unchanged"; \
571                                         continue; \
572                                 fi ; \
573                                 mv -f $${dst} $${dst}.old ; \
574                         else \
575                                 echo "Skipping config file $$x"; \
576                                 continue; \
577                         fi ;\
578                 fi ; \
579                 echo "Installing file $$x"; \
580                 $(INSTALL) -m 644 $$x $${dst} ;\
581         done
582         @if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
583                 echo "Creating asterisk.conf"; \
584                 ( \
585                 echo "[directories]" ; \
586                 echo "astetcdir => $(ASTETCDIR)" ; \
587                 echo "astmoddir => $(MODULES_DIR)" ; \
588                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
589                 echo "astdbdir => $(ASTDBDIR)" ; \
590                 echo "astkeydir => $(ASTKEYDIR)" ; \
591                 echo "astdatadir => $(ASTDATADIR)" ; \
592                 echo "astagidir => $(AGI_DIR)" ; \
593                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
594                 echo "astrundir => $(ASTVARRUNDIR)" ; \
595                 echo "astlogdir => $(ASTLOGDIR)" ; \
596                 echo "" ; \
597                 echo ";[options]" ; \
598                 echo ";verbose = 3" ; \
599                 echo ";debug = 3" ; \
600                 echo ";alwaysfork = yes ; same as -F at startup" ; \
601                 echo ";nofork = yes ; same as -f at startup" ; \
602                 echo ";quiet = yes ; same as -q at startup" ; \
603                 echo ";timestamp = yes ; same as -T at startup" ; \
604                 echo ";execincludes = yes ; support #exec in config files" ; \
605                 echo ";console = yes ; Run as console (same as -c at startup)" ; \
606                 echo ";highpriority = yes ; Run realtime priority (same as -p at startup)" ; \
607                 echo ";initcrypto = yes ; Initialize crypto keys (same as -i at startup)" ; \
608                 echo ";nocolor = yes ; Disable console colors" ; \
609                 echo ";dontwarn = yes ; Disable some warnings" ; \
610                 echo ";dumpcore = yes ; Dump core on crash (same as -g at startup)" ; \
611                 echo ";languageprefix = yes ; Use the new sound prefix path syntax" ; \
612                 echo ";internal_timing = yes" ; \
613                 echo ";systemname = my_system_name ; prefix uniqueid with a system name for global uniqueness issues" ; \
614                 echo ";autosystemname = yes ; automatically set systemname to hostname - uses 'localhost' on failure, or systemname if set" ; \
615                 echo ";maxcalls = 10 ; Maximum amount of calls allowed" ; \
616                 echo ";maxload = 0.9 ; Asterisk stops accepting new calls if the load average exceed this limit" ; \
617                 echo ";maxfiles = 1000 ; Maximum amount of openfiles" ; \
618                 echo ";minmemfree = 1 ; in MBs, Asterisk stops accepting new calls if the amount of free memory falls below this watermark" ; \
619                 echo ";cache_record_files = yes ; Cache recorded sound files to another directory during recording" ; \
620                 echo ";record_cache_dir = /tmp ; Specify cache directory (used in cnjunction with cache_record_files)" ; \
621                 echo ";transmit_silence_during_record = yes ; Transmit SLINEAR silence while a channel is being recorded" ; \
622                 echo ";transcode_via_sln = yes ; Build transcode paths via SLINEAR, instead of directly" ; \
623                 echo ";runuser = asterisk ; The user to run as" ; \
624                 echo ";rungroup = asterisk ; The group to run as" ; \
625                 echo "" ; \
626                 echo "; Changing the following lines may compromise your security." ; \
627                 echo ";[files]" ; \
628                 echo ";astctlpermissions = 0660" ; \
629                 echo ";astctlowner = root" ; \
630                 echo ";astctlgroup = apache" ; \
631                 echo ";astctl = asterisk.ctl" ; \
632                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
633         else \
634                 echo "Skipping asterisk.conf creation"; \
635         fi
636         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
637         build_tools/make_sample_voicemail $(DESTDIR)/$(ASTDATADIR) $(DESTDIR)/$(ASTSPOOLDIR)
638
639 webvmail:
640         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
641         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
642         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
643         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
644         for x in images/*.gif; do \
645                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
646         done
647         @echo " +--------- Asterisk Web Voicemail ----------+"  
648         @echo " +                                           +"
649         @echo " + Asterisk Web Voicemail is installed in    +"
650         @echo " + your cgi-bin directory:                   +"
651         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
652         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
653         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
654         @echo " +                                           +"
655         @echo " + Other static items have been stored in:   +"
656         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
657         @echo " +                                           +"
658         @echo " + If these paths do not match your httpd    +"
659         @echo " + installation, correct the definitions     +"
660         @echo " + in your Makefile of HTTP_CGIDIR and       +"
661         @echo " + HTTP_DOCSDIR                              +"
662         @echo " +                                           +"
663         @echo " +-------------------------------------------+"  
664
665 spec: 
666         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
667
668 rpm: __rpm
669
670 __rpm: include/asterisk/version.h include/asterisk/buildopts.h spec
671         rm -rf /tmp/asterisk ; \
672         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
673         $(MAKE) DESTDIR=/tmp/asterisk install ; \
674         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
675         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
676         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
677         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
678
679 progdocs:
680         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
681         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
682
683 config:
684         @if [ "${OSARCH}" = "linux-gnu" ]; then \
685                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
686                         $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk $(DESTDIR)/etc/rc.d/init.d/asterisk; \
687                         if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
688                 elif [ -f /etc/debian_version ]; then \
689                         $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk $(DESTDIR)/etc/init.d/asterisk; \
690                         if [ -z "$(DESTDIR)" ]; then /usr/sbin/update-rc.d asterisk start 50 2 3 4 5 . stop 91 2 3 4 5 .; fi; \
691                 elif [ -f /etc/gentoo-release ]; then \
692                         $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk $(DESTDIR)/etc/init.d/asterisk; \
693                         if [ -z "$(DESTDIR)" ]; then /sbin/rc-update add asterisk default; fi; \
694                 elif [ -f /etc/mandrake-release -o -f /etc/mandriva-release ]; then \
695                         $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk $(DESTDIR)/etc/rc.d/init.d/asterisk; \
696                         if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
697                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
698                         $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk $(DESTDIR)/etc/init.d/asterisk; \
699                         if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
700                 elif [ -f /etc/slackware-version ]; then \
701                         echo "Slackware is not currently supported, although an init script does exist for it." \
702                 else \
703                         echo "We could not install init scripts for your distribution."; \
704                 fi \
705         else \
706                 echo "We could not install init scripts for your operating system."; \
707         fi
708
709 sounds:
710         $(MAKE) -C sounds all
711
712 # If the cleancount has been changed, force a make clean.
713 # .cleancount is the global clean count, and .lastclean is the 
714 # last clean count we had
715
716 cleantest:
717         @cmp -s .cleancount .lastclean || $(MAKE) clean
718
719 $(SUBDIRS_UNINSTALL):
720         @$(MAKE) $(PRINT_DIR) -C $(@:-uninstall=) uninstall
721
722 _uninstall: $(SUBDIRS_UNINSTALL)
723         rm -f $(DESTDIR)$(MODULES_DIR)/*
724         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
725         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
726         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
727         rm -rf $(DESTDIR)$(ASTHEADERDIR)
728         rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
729         rm -f $(DESTDIR)$(ASTMANDIR)/man8/asterisk.8
730         rm -f $(DESTDIR)$(ASTMANDIR)/man8/astgenkey.8
731         rm -f $(DESTDIR)$(ASTMANDIR)/man8/autosupport.8
732         rm -f $(DESTDIR)$(ASTMANDIR)/man8/safe_asterisk.8
733         $(MAKE) -C sounds uninstall
734
735 uninstall: _uninstall
736         @echo " +--------- Asterisk Uninstall Complete -----+"  
737         @echo " + Asterisk binaries, sounds, man pages,     +"  
738         @echo " + headers, modules, and firmware builds,    +"  
739         @echo " + have all been uninstalled.                +"  
740         @echo " +                                           +"
741         @echo " + To remove ALL traces of Asterisk,         +"
742         @echo " + including configuration, spool            +"
743         @echo " + directories, and logs, run the following  +"
744         @echo " + command:                                  +"
745         @echo " +                                           +"
746         @echo " +            $(mK) uninstall-all            +"  
747         @echo " +-------------------------------------------+"  
748
749 uninstall-all: _uninstall
750         rm -rf $(DESTDIR)$(ASTLIBDIR)
751         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
752         rm -rf $(DESTDIR)$(ASTDATADIR)
753         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
754         rm -rf $(DESTDIR)$(ASTETCDIR)
755         rm -rf $(DESTDIR)$(ASTLOGDIR)
756
757 menuconfig: menuselect
758
759 gmenuconfig: gmenuselect
760
761 menuselect: menuselect/menuselect menuselect-tree
762         -@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!"
763
764 gmenuselect: menuselect/gmenuselect menuselect-tree
765         -@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!"
766
767 menuselect/menuselect: menuselect/makeopts
768         echo "doing menuselect with $(HOST_CC)"
769         @CC="$(HOST_CC)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
770
771 menuselect/gmenuselect: menuselect/makeopts
772         @CC="$(HOST_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect gmenuselect CONFIGURE_SILENT="--silent"
773
774 menuselect/makeopts:
775         @CC="$(HOST_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect makeopts CONFIGURE_SILENT="--silent"
776
777 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
778         @echo "Generating input for menuselect ..."
779         @build_tools/prep_moduledeps > $@
780
781 asterisk.pdf:
782         $(MAKE) -C doc/tex asterisk.pdf
783
784 .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