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