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