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