1 # Kamailio build system
4 # makefile defs (CC, LD,a.s.o)
6 # Environment variables:
7 # PREFIX, LOCALBASE, BASEDIR
8 # INSTALL, TAR , CC, LEX, YACC,
9 # CPUTYPE, CC_EXTRA_OPTS, LD_EXTRA_OPTS
10 # exclude_modules, skip_modules, include_modules
14 # default silent, unless Q= 0|no|off|verbose|noisy
15 quiet?=$(if $(filter 0 no off verbose noisy,$(Q)),verbose,silent)
17 # check if already included/exported
19 # used for sanity checks for Makefile.defs inclusion (!= makefile_defs which
20 # specifies if we have a set of valid defs)
21 override makefile_defs_included:=1
22 ifeq ($(makefile_defs),1)
23 ifeq ($(quiet),verbose)
24 $(info Makefile.defs defs skipped)
29 ifeq (,$(main_makefile))
30 # hack to automatically use config.mak in all the modules, without
31 # changing the current module makefiles (which all include Makefile.defs):
32 # if not called from the main makefile (module, lib or ut):
33 # include config.mak, but if not present or incomplete (makefile_defs!=1)
34 # don't export the vars)
35 DEFCOREPATH = ../../src
36 ifneq ("$(wildcard $(DEFCOREPATH))","")
41 include $(COREPATH)/config.mak
42 ifeq ($(quiet),verbose)
43 $(info config.mak included)
45 # config.mak should set makefile_defs if complete
49 override makefile_defs=1
53 ifeq ($(quiet),verbose)
54 $(info normal Makefile.defs exec)
57 -include Makefile.vars
59 # usage: $(call set_if_empty,VAR,value)
60 set_if_empty=$(if $($(1)),,$(eval override $(1)=$(2)))
62 # flavour: sip-router, ser or kamailio
63 $(call set_if_empty,FLAVOUR,kamailio)
65 #prefix for various configs and scripts
66 #config name/name-prefix for distributed configs
68 #config name/name-prefix for distributed scripts
73 ifeq ($(FLAVOUR),sip-router)
76 else ifeq ($(FLAVOUR),ser)
79 else ifeq ($(FLAVOUR),kamailio)
84 # kamailio statistics on
86 # fast malloc statistics on
93 # application server support on
95 # enable core hooks for SCTP
104 INSTALL_FLAVOUR=$(FLAVOUR)
112 # memory manager switcher
113 # 0 - f_malloc (fast malloc)
114 # 1 - q_malloc (quick malloc)
115 # 2 - tlsf_malloc (O(1) malloc and free)
117 # memory debugger switcher
118 # 0 - off (no-debug mode)
119 # 1 - on (debug mode)
122 VERSIONVAL = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
124 RELEASE:=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
125 OS := $(shell uname -s | sed -e s/SunOS/solaris/ -e s/CYGWIN.*/cygwin/ \
126 | tr "[A-Z]" "[a-z]" | tr "/" "_")
137 HOST_ARCH := $(shell $(GETARCH) |sed -e s/i.86/i386/ -e s/sun4[uv]/sparc64/ \
138 -e s/armv[3-5].*/arm/ -e s/armv6.*/arm6/ \
139 -e "s/Power Macintosh/ppc/" \
140 -e "s/cobalt/mips2/" \
141 -e s/amd64/x86_64/ -e s/sparcv9/sparc64/ )
142 # fix sparc -> sparc64
143 ifeq ($(HOST_ARCH),sparc)
144 ifeq ($(shell uname -m),sun4u)
147 ifeq ($(shell uname -m),sun4v)
152 OSREL := $(shell uname -r)
153 # numerical version (good for comparisons: A.B.C => A*1000000+B*1000+C)
154 OSREL_N:= $(shell echo $(OSREL) | sed -e 's/^[^0-9]*//' \
155 -e 's/^\([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*$$/\1/g' | \
156 (IFS=. read A B C D; R=0; \
157 [ -n "$$A" ] && R=`expr $$R \* 1000 + $$A` && \
158 [ -n "$$B" ] && R=`expr $$R \* 1000 + $$B` && \
159 [ -n "$$C" ] && R=`expr $$R \* 1000 + $$C`; echo $$R ) )
164 # by default compile with tls hooks support (so that no ser recompile is
165 # needed before the tls module can be used)
167 ifeq ($(CORE_TLS), 1)
168 RELEASE:=$(RELEASE)-tls
171 ifeq ($(TLS_HOOKS), 1)
172 # RELEASE:=$(RELEASE)-tls
175 # extra CC command line options (e.g -march=athlon-mp)
178 # extra LD command line options
181 ifeq ($(OS), solaris)
190 INSTALL_TOUCH = touch # used to create the file first (good to
191 # make solaris install work)
192 INSTALL_CFG = $(INSTALL) -m 644
193 INSTALL_BIN = $(INSTALL) -m 755
194 INSTALL_SCRIPT = $(INSTALL) -m 755
195 INSTALL_MODULES = $(INSTALL) -m 755
196 INSTALL_LIB = $(INSTALL) -m 755
197 INSTALL_DOC = $(INSTALL) -m 644
198 INSTALL_MAN = $(INSTALL) -m 644
199 INSTALL_SHARE = $(INSTALL) -m 644
201 #set some vars from the environment (and not make builtins)
202 CC := $(shell echo "$${CC}")
203 LEX := $(shell echo "$${LEX}")
204 YACC := $(shell echo "$${YACC}")
209 # find compiler name & version
214 CC_LONGVER:=$(shell if $(CC) -v 2>/dev/null; then \
222 #find-out the compiler's name
224 ifneq (,$(findstring gcc, $(CC_LONGVER)))
227 CC_VER:=$(word 1,$(CC)) $(shell $(CC) - --version|head -n 1|\
228 sed -e 's/([^$(RPAREN)]*)//g' \
229 -e 's/^.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/'\
230 -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
231 # CC_VER:=$(word 1,$(CC)) $(shell $(CC) - --version|head -n 1|cut -d" " -f 3\
232 # |sed -e 's/^.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/'\
233 # -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
234 # sed with POSIX.1 regex doesn't support |, + or ?
235 # (darwin, solaris ...) => this complicated expression
237 #transform gcc version into 2.9x or 3.0
238 CC_SHORTVER:=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
239 sed -e 's/[^0-9]*-\(.*\)/\1/'| \
240 sed -e 's/2\.9.*/2.9x/' \
241 -e 's/3\.[0-3]\..*/3.0/' \
242 -e 's/3\.[0-3]/3.0/' \
243 -e 's/3\.[4-9]\..*/3.4/' \
244 -e 's/3\.[4-9]/3.4/' \
245 -e 's/4\.[0-1]\..*/4.x/' \
246 -e 's/4\.[0-1]/4.x/' \
247 -e 's/4\.[2-4]\..*/4.2+/' \
248 -e 's/4\.[2-4]$$/4.2+/' \
249 -e 's/4\.[5-9]\..*/4.5+/' \
250 -e 's/4\.[5-9]$$/4.5+/' \
251 -e 's/5\.[0-9]\..*/5.0+/' \
252 -e 's/5\.[0-9]$$/5.0+/' \
253 -e 's/6\.[0-9]\..*/6.0+/' \
254 -e 's/6\.[0-9]$$/6.0+/' \
255 -e 's/7\.[0-9]\..*/7.0+/' \
256 -e 's/7\.[0-9]$$/7.0+/')
257 ifeq (,$(strip $(filter-out 3.0 3.4 4.x 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
258 # dependencies can be generated on-the-fly while compiling *.c
259 CC_MKDEP_OPTS=-MMD -MP
260 endif # 3.0 <= $(CC_SHORTVER) <= 4.x
263 ifneq (, $(findstring Sun, $(CC_LONGVER)))
265 CC_SHORTVER:=$(shell echo "$(CC_LONGVER)"|head -n 1| \
266 sed -e 's/.*\([0-9]\.[0-9]\).*/\1/g' )
267 CC_VER=$(CC) $(CC_SHORTVER)
272 ifneq (, $(findstring Intel(R) C++ Compiler, $(CC_LONGVER)))
273 # very nice: gcc compatible
275 CC_FULLVER:=$(shell echo "$(CC_LONGVER)"|head -n 1| \
276 sed -e 's/.*Version \([0-9]\.[0-9]\.[0-9]*\).*/\1/g' )
277 CC_SHORTVER:=$(shell echo "$(CC_FULLVER)" | cut -d. -f1,2 )
278 CC_VER=$(CC) $(CC_FULLVER)
282 ifneq (, $(findstring clang, $(CC_LONGVER)))
283 #clang should be gcc compatible
285 CC_FULLVER:=$(shell echo "$(CC_LONGVER)" | head -n 1 | sed -e 's/.*version \([0-9]\.[0-9]\).*/\1/g' )
286 CC_SHORTVER:=$(shell echo "$(CC_FULLVER)" | cut -d. -f1,2 )
287 CC_VER=$(CC) $(CC_FULLVER)
298 $(warning Unknown compiler $(CC)\; supported compilers: \
299 gcc, sun cc, intel icc )
303 # predefined compiler macros for different architectures
304 # (see http://predef.sourceforge.net/prearch.html for a more complete list)
305 i386_macros= i386 __i386__ __i486__ __i586__ __i686__ \
306 __i386 _M_IX86 __X86__ _X86_
307 x86_64_macros= __amd64__ __amd64 __x86_64__ __x86_64 _M_X64
309 sparc_macros= __sparc__ __sparc __sparcv8
310 sparc64_macros= __sparcv9 __sparc_v9__
312 arm_macros= __arm__ __thumb__
313 arm6_macros= __ARM_ARCH_6__
315 aarch64_macros= __aarch64__
317 ppc_macros= __powerpc __powerpc__ __POWERPC__ __ppc__ _ARCH_PPC
318 ppc64_macros= __ppc64__ _ARCH_PPC64
320 mips_macros= __mips__ __mips _MIPS_ARCH_MIPS1
321 mips2_macros= _MIPS_ISA_MIPS2 _MIPS_ISA_MIPS3 _MIPS_ISA_MIPS4 \
322 _MIPS_ARCH_MIPS2 _MIPS_ARCH_MIPS3 _MIPS_ARCH_MIPS4
323 mips64_macros= _MIPS_ISA_MIPS64 _MIPS_ARCH_MIPS64
325 alpha_macros= __alpha__ __alpha _M_ALPHA_
327 ifeq ($(CC_NAME),gcc)
329 predef_macros:=$(shell $(CC) -dM -E -x c $(CC_EXTRA_OPTS) $(extra_defs) \
332 ifneq ($(strip $(filter $(i386_macros), $(predef_macros))),)
334 else ifneq ($(strip $(filter $(x86_64_macros), $(predef_macros))),)
336 else ifneq ($(strip $(filter $(sparc_macros), $(predef_macros))),)
338 ifneq ($(strip $(filter $(sparc64_macros), $(predef_macros))),)
340 else # sparc64_macros
342 endif # sparc64_macros
344 else ifneq ($(strip $(filter $(arm_macros), $(predef_macros))),)
346 ifneq ($(strip $(filter $(arm6_macros), $(predef_macros))),)
352 else ifneq ($(strip $(filter $(ppc64_macros), $(predef_macros))),)
354 else ifneq ($(strip $(filter $(ppc_macros), $(predef_macros))),)
356 else ifneq ($(strip $(filter $(mips_macros), $(predef_macros))),)
358 ifneq ($(strip $(filter $(mips64_macros), $(predef_macros))),)
360 else ifneq ($(strip $(filter $(mips2_macros), $(predef_macros))),)
364 endif # mips64_macros
366 else ifneq ($(strip $(filter $(alpha_macros), $(predef_macros))),)
370 $(warn "Unknown target compiler architecture")
372 endif # predefined macros tests (x86_macros, ...)
382 # retarget amd64 to x86_64
383 ifeq ($(ARCH), amd64)
387 $(info target architecture <$(ARCH)>, host architecture <$(HOST_ARCH)>)
391 ARCHBSZ= $(shell echo $(ARCH) | sed -e 's/.*64.*/64b/')
392 ifeq ($(ARCHBSZ),64b)
400 cfg_dir = etc/$(MAIN_NAME)/
402 share_dir = share/$(MAIN_NAME)/
403 # lib/$(MAIN_NAME)/modules , lib/$(MAIN_NAME)/modules-s, lib/$(MAIN_NAME)/modules-k
404 modules_dir = $(LIBDIR)/$(MAIN_NAME)/
405 lib_dir = $(LIBDIR)/$(MAIN_NAME)/
406 run_dir = var/run/$(MAIN_NAME)/
407 doc_dir = doc/$(MAIN_NAME)/
409 data_dir = $(MAIN_NAME)/
412 doc_dir = share/doc/$(MAIN_NAME)/
414 data_dir = share/$(MAIN_NAME)/
415 LOCALBASE ?= /usr/local
418 ifeq ($(OS), gnu_kfreebsd)
419 doc_dir = share/doc/$(MAIN_NAME)/
421 data_dir = share/$(MAIN_NAME)/
422 LOCALBASE ?= /usr/local
425 ifeq ($(OS), freebsd)
426 doc_dir = share/doc/$(MAIN_NAME)/
428 data_dir = share/$(MAIN_NAME)/
429 LOCALBASE ?= /usr/local
432 ifeq ($(OS), openbsd)
433 doc_dir = share/doc/$(MAIN_NAME)/
435 data_dir = share/$(MAIN_NAME)/
436 LOCALBASE ?= /usr/local
440 doc_dir = share/doc/$(MAIN_NAME)/
442 data_dir = share/$(MAIN_NAME)/
443 LOCALBASE ?= /usr/pkg
446 ifeq ($(OS), dragonfly)
447 doc_dir = share/doc/$(MAIN_NAME)/
449 data_dir = share/$(MAIN_NAME)/
450 LOCALBASE ?= /usr/pkg
454 doc_dir = share/doc/$(MAIN_NAME)/
456 data_dir = share/$(MAIN_NAME)/
457 LOCALBASE ?= /usr/local
460 LOCALBASE ?= /usr/local
463 doxygen_dir=doc/doxygen
465 BASEDIR ?= $(DESTDIR)
467 RUNBASEDIR ?= $(DESTDIR)
468 runbasedir = $(RUNBASEDIR)
471 PREFIX ?= $(LOCALBASE)
473 # install path is $(basedir) $(prefix)
475 # creating a bin. archive in /tmp, which unpacks in /usr/local
479 # install prefixes for various stuff
480 cfg_prefix = $(basedir)$(prefix)
481 bin_prefix = $(basedir)$(prefix)
482 modules_prefix = $(basedir)$(prefix)
483 lib_prefix = $(basedir)$(prefix)
484 run_prefix = $(runbasedir)
485 doc_prefix = $(basedir)$(prefix)
486 man_prefix = $(basedir)$(prefix)
487 ut_prefix = $(basedir)$(prefix)
488 share_prefix = $(basedir)$(prefix)
489 data_prefix = $(basedir)$(prefix)
492 # target dirs for various stuff
493 cfg_target = $(prefix)/$(cfg_dir)
494 bin_target = $(prefix)/$(bin_dir)
495 #modules_target = $(prefix)/$(modules_dir)
496 lib_target = $(prefix)/$(lib_dir)
497 run_target = $(run_prefix)/$(run_dir)
498 share_target = $(share_prefix)/$(share_dir)
499 doc_target = $(prefix)/$(doc_dir)
500 data_target = $(prefix)/$(data_dir)
503 # compile-time options
506 # allows to print out number of packets processed on CTRL-C;
507 # implementation still nasty and reports per-process
509 # turns off some of the debug messages (DBG(...)).
511 # completely turns of all the logging (and DBG(...))
513 # compiles in some extra debugging code
515 # faster ip address resolver for ip strings (e.g "127.0.0.1")
517 # compiles in shared mem. support, needed by some modules and
520 # use mmap instead of SYSV shared memory
522 # uses a faster malloc (exclusive w/ USE_SHM_MEM)
524 # all pkg_malloc => shm_malloc (most mallocs use a common sh.
525 # mem. segment); don't define PKG_MALLOC if you want this!
527 # qm_malloc debug code, will cause pkg_malloc and shm_malloc
528 # to keep and display lot of debuging information: file name,
529 # function, line number of malloc/free call for each block,
530 # extra error checking (trying to free the same pointer
531 # twice, trying to free a pointer alloc'ed with a different
534 # additional option to PKG_MALLOC which utilizes a fater then
536 # (not true anymore, q_malloc performs approx. the same)
538 # custom quick malloc, recommended for debugging
540 # an even faster malloc, not recommended for debugging
542 # an implemetation of the "two levels segregated fit" malloc algorithm
544 # a malloc implementation based on Doug Lea's dl_malloc
546 # an experimental multi-CPU, pool based, multi-process safe version of
547 # F_MALLOC. Should give better performance on machines with lots of CPUs
548 # after some tunning.
550 # an experimental multi-CPU, pool based, multi-process safe, mostly
551 # lockless version of SF_MALLOC/F_MALLOC. Not for production use for
554 # issues additional debugging information if lock/unlock is called
556 # enable the join of free memory chunks (see also mem_join cfg param)
558 # uses fast arhitecture specific locking (see the arh. specific section)
560 # uses sys v sems for locking (slower & limited number)
561 # -DUSE_PTHREAD_MUTEX
562 # uses pthread mutexes, faster than sys v or posix sems, but do not
563 # work on all systems inter-processes (e.g. linux)
565 # uses posix semaphores for locking (faster than sys v)
567 # uses futexes for locking (linux 2.6+)
569 # uses busy waiting on the lock (FAST_LOCK)
571 # try busy waiting for a while and if the lock is still held go to
572 # force reschedule (FAST_LOCK)
573 # -DADAPTIVE_WAIT_LOOPS=number
574 # number of loops we busy wait, after "number" loops have elapsed we
575 # force a reschedule (FAST_LOCK)
577 # don't use smp compliant locking (faster but won't work on SMP machines)
578 # (not yet enabled) (FAST_LOCK)
579 # -DNO_PINGTEL_TAG_HACK
580 # if enabled, To-header-field will be less liberal and will not accept
581 # 'tag=' (tag parameter with equal sign and without value); it is called
582 # this way because such message was sighted from a Pingtel phone
584 # compiles in tcp support
586 # disable the tcp Nagle algorithm (lower delay)
588 # compiles in tls support, requires -DUSE_TCP. Note: this is only
589 # generic support (parsing a.s.o.), it does not include the actual
590 # "tls engine". If you really want tls you need also either
591 # -DCORE_TLS and a tls/ subdir with the tls code or -DTLS_HOOKS and
592 # the tls module loaded.
594 # compiles tls in-core support. Requires -DUSE_TLS, conflicts
595 # -DTLS_HOOKS. Please use make CORE_TLS=1 instead (it will set all the
596 # needed defines automatically and extra libraries needed for linking).
598 # compile tls module support (support for having the "tls engine" in a
599 # module). Requires -DUSE_TLS, conflicts -DCORE_TLS.
600 # Please use make TLS_HOOKS=1 (or TLS_HOOKS=0 to for disabling) instead
601 # of setting -DTLS_HOOKS (it will set all the needed defines
604 # support for changing some of the resolver parameters present
605 # (_res structure in <resolv.h>)
607 # compiles in comp=[sergz|sigcomp] support (parsing uri & via,
608 # adding it to via, lumps a.s.o). WARNING: right now this option
609 # is useless since the compression code doesn't exist yet.
611 # compiles in checks and use for maddr parameter in uri.
612 # Required to support Windows Messenger 5.x over TCP connection
613 # which (mis)uses this parameter.
615 # use an internal dns cache instead of making dns requests each time
616 # -DUSE_DNS_CACHE_STATS
617 # turns on DNS cache measurements
619 # if the destination resolves to multiple ips, on send error fall back
621 # -DUSE_DST_BLACKLIST
622 # blacklist bad destination (timeout, failed to connect, error sending
624 # -DUSE_DST_BLACKLIST_STATS
625 # turns on blacklist bad destination measurements
627 # if enabled profiling will be enabled for child processes
628 # Don't forget to set PROFILE (see below)
630 # turns off debugging messages in signal handlers (which might be
633 # turns on naptr support (but must be also enabled from the config)
634 # -DDNS_WATCHDOG_SUPPORT
635 # turns on DNS watchdog support which can be used to inform the
636 # core that the DNS servers are down. No DNS query is performed
637 # when the servers are unreachable, and even expired resource
638 # records are used from the cache. (requires external watchdog)
640 # adds support for Application Server interface
641 # Sometimes is needes correct non-quoted $OS. HACK: gcc translates known OS to number ('linux'), so there is added underscore
643 ifeq ($(OS), dragonfly)
644 # Tell it that dragonflybsd is equivalent to compiling for freebsd, but
645 # define also __OS_dragonfly (for fine-tunning like kqueue support).
646 os_defs := -D__OS_freebsd -D__OS_dragonfly
649 os_defs := -D__OS_$(OS)
653 C_DEFS= $(extra_defs) \
654 -DNAME='"$(MAIN_NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
655 -DOS='$(OS)_' -DOS_QUOTED='"$(OS)"' -DCOMPILER='"$(CC_VER)"'\
656 -D__CPU_$(ARCH) $(os_defs) \
657 -DVERSIONVAL=$(VERSIONVAL) \
658 -DCFG_DIR='"$(cfg_target)"'\
659 -DSHARE_DIR='"$(share_target)"'\
660 -DRUN_DIR='"$(run_target)"'
662 ifneq ($(MEMPKG), sys)
663 C_DEFS+= -DPKG_MALLOC
666 C_DEFS+= -DSHM_MEM -DSHM_MMAP \
674 -DUSE_DST_BLACKLIST \
677 #-DUSE_DNS_CACHE_STATS \
678 #-DUSE_DST_BLACKLIST_STATS \
679 #-DDNS_WATCHDOG_SUPPORT \
695 #PROFILE= -pg # set this if you want profiling
696 # you may also want to set -DPROFILING
698 # WARNING: do not add mode=debug or mode=release anymore in the Makefile,
699 # use make mode=debug all instead. Anyway no by default ser is compiled w/
700 # debugging symbols in all cases (-g). --andrei
702 # memory managers and related debug mode
703 C_DEFS+= -DMEM_JOIN_FREE
709 C_DEFS+= -DTLSF_MALLOC
712 C_DEFS+= -DDBG_SR_MEMORY
714 ifeq ($(MEMPKG), sys)
715 ifeq ($(MEMDBGSYS), 1)
716 C_DEFS+= -DDBG_SYS_MEMORY
722 ifneq ($(PKG_MEM_SIZE),)
723 C_DEFS+= -DPKG_MEM_SIZE=$(PKG_MEM_SIZE)
725 ifeq ($(CORE_TLS), 1)
726 C_DEFS+= -DUSE_TLS -DCORE_TLS
728 ifeq ($(TLS_HOOKS), 1)
729 C_DEFS+= -DUSE_TLS -DTLS_HOOKS
732 C_DEFS+= -DUSE_CORE_STATS -DSTATISTICS
735 C_DEFS+= -DMALLOC_STATS
738 C_DEFS+= -DWITH_AS_SUPPORT
750 C_DEFS+= -DEXTRA_DEBUG
753 # platform dependent settings
755 # find ld & as name (gnu or solaris)
756 ifeq ($(OS), solaris)
757 ifeq ($(CC_NAME), gcc)
758 LDGCC:=$(shell $(CC) -v 2>&1 | grep with-ld| \
759 sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
760 ASGCC:=$(shell $(CC) -v 2>&1 | grep with-as| \
761 sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
762 LDPATH:=$(shell if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
764 if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
769 ASPATH:=$(shell if [ -z "$(ASGCC)" ] ; then echo "as" ;\
771 if $(ASGCC) -V 2>/dev/null 1>/dev/null </dev/null; \
778 LDTYPE:=$(shell if $(LDPATH) -V 1>/dev/null 2>/dev/null; then \
779 if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
782 if $(LDPATH) -V 2>&1|grep Solaris >/dev/null;\
789 ASTYPE:=$(shell if $(ASPATH) -V 1>/dev/null 2>/dev/null </dev/null; \
791 if $(ASPATH) -V 2>&1 </dev/null | \
792 grep GNU >/dev/null; then echo gnu; \
794 if $(ASPATH) -V 2>&1 </dev/null | \
795 grep Sun >/dev/null; then echo solaris; \
801 #$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
806 # arch. specific definitions
811 ifeq ($(ARCH), x86_64)
815 ifeq ($(ARCH), sparc64)
816 ifeq ($(CC_NAME), gcc)
821 ifeq ($(ARCH), sparc)
827 C_DEFS+=-DNOSMP # very unlikely to have an smp arm
832 C_DEFS+=-DNOSMP # very unlikely to have an smp arm
835 ifeq ($(ARCH), aarch64)
844 ifeq ($(ARCH), ppc64)
849 # mips1 arch. (e.g. R3000) - no hardware locking support
851 C_DEFS+=-DMIPS_HAS_LLSC # likely
852 C_DEFS+=-DNOSMP # very likely
855 ifeq ($(ARCH), mips2)
856 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
860 ifeq ($(ARCH), mips64)
861 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
865 ifeq ($(ARCH), alpha)
867 C_DEFS+=-DNOSMP # very likely
870 ifeq ($(use_fast_lock), yes)
871 C_DEFS+= -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024
872 found_lock_method=yes
879 ifeq ($(mode), release)
883 ifeq ($(CC_NAME), gcc)
884 C_DEFS+=-DCC_GCC_LIKE_ASM
886 CFLAGS=-g $(CC_OPT) -funroll-loops -Wcast-align $(PROFILE)
887 #if gcc 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
888 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
889 $(call set_if_empty,CPUTYPE,athlon64)
890 CFLAGS+=-m32 -minline-all-stringops \
893 -fno-strict-overflow \
898 ifeq ($(CC_SHORTVER), 4.x)
899 $(call set_if_empty,CPUTYPE,athlon64)
900 CFLAGS+=-m32 -minline-all-stringops \
907 ifeq ($(CC_SHORTVER), 3.4)
908 $(call set_if_empty,CPUTYPE,athlon)
909 CFLAGS+=-m32 -minline-all-stringops \
915 ifeq ($(CC_SHORTVER), 3.0)
916 $(call set_if_empty,CPUTYPE,athlon)
917 CFLAGS+=-minline-all-stringops \
920 # -m32 supported since gcc 3.2
922 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
923 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc >= 3.1 \
930 $(warning You are using an old and unsupported gcc \
931 version ($(CC_SHORTVER)), compile at your own risk!)
933 endif # CC_SHORTVER, 2.9x
934 endif # CC_SHORTVER, 3.0
935 endif # CC_SHORTVER, 3.4
936 endif # CC_SHORTVER, 4.x
937 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
940 ifeq ($(CC_NAME), clang)
941 $(call set_if_empty,CPUTYPE,athlon64)
942 C_DEFS+=-DCC_GCC_LIKE_ASM
943 CFLAGS+=-g -m32 $(CC_OPT) -mtune=$(CPUTYPE)
945 else # CC_NAME, clang
946 ifeq ($(CC_NAME), icc)
947 C_DEFS+=-DCC_GCC_LIKE_ASM
948 CFLAGS=-g -O3 -ipo -ipo_obj -unroll $(PROFILE) \
949 -tpp6 -xK #-openmp #optimize for PIII
950 # -prefetch doesn't seem to work
951 #( ty to inline acroos files, unroll loops,prefetch,
952 # optimize for PIII, use PIII instructions & vect.,
956 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
958 endif #CC_NAME, clang
963 ifeq ($(ARCH), x86_64)
965 ifeq ($(CC_NAME), gcc)
966 C_DEFS+=-DCC_GCC_LIKE_ASM
968 CFLAGS=-g $(CC_OPT) -funroll-loops -Wcast-align $(PROFILE)
970 # don't add '-mtune=$(CPUTYPE)' - gcc failure
971 ifeq ($(CC_SHORTVER),$(filter $(CC_SHORTVER),4.5+ 5.0+ 6.0+ 7.0+))
972 $(call set_if_empty,CPUTYPE,opteron)
973 CFLAGS+=-m64 -minline-all-stringops \
980 ifeq ($(CC_SHORTVER), 4.2+)
981 $(call set_if_empty,CPUTYPE,opteron)
982 CFLAGS+=-m64 -minline-all-stringops \
985 -fno-strict-overflow \
990 ifeq ($(CC_SHORTVER), 4.x)
991 $(call set_if_empty,CPUTYPE,opteron)
992 CFLAGS+=-m64 -minline-all-stringops \
999 ifeq ($(CC_SHORTVER), 3.4)
1000 $(call set_if_empty,CPUTYPE,athlon64)
1001 CFLAGS+=-m64 -minline-all-stringops \
1006 ifeq ($(CC_SHORTVER), 3.0)
1007 $(call set_if_empty,CPUTYPE,athlon64)
1008 CFLAGS+=-minline-all-stringops \
1010 #-mcpu=$(CPUTYPE) \ # not working on all x86_64 gccs
1012 #-m64 on x86_64/x86 works starting with gcc 3.2
1014 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1015 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc >= 3.1 \
1022 $(warning You are using an old and unsupported gcc \
1023 version ($(CC_SHORTVER)), compile at your own risk!)
1025 endif # CC_SHORTVER, 2.9x
1026 endif # CC_SHORTVER, 3.0
1027 endif # CC_SHORTVER, 3.4
1028 endif # CC_SHORTVER, 4.x
1029 endif # CC_SHORTVER, 4.2+
1030 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+
1033 ifeq ($(CC_NAME), clang)
1034 $(call set_if_empty,CPUTYPE,opteron)
1035 C_DEFS+=-DCC_GCC_LIKE_ASM
1039 else # CC_NAME, clang
1040 ifeq ($(CC_NAME), icc)
1041 C_DEFS+=-DCC_GCC_LIKE_ASM
1042 CFLAGS=-g -O3 -ipo -ipo_obj -unroll $(PROFILE) \
1043 -tpp6 -xK #-openmp #optimize for PIII
1044 # -prefetch doesn't seem to work
1045 #( ty to inline acroos files, unroll loops,prefetch,
1046 # optimize for PIII, use PIII instructions & vect.,
1047 # mutlithread loops)
1050 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1052 endif #CC_NAME, clang
1057 ifeq ($(ARCH), sparc64)
1059 ifeq ($(CC_NAME), gcc)
1060 C_DEFS+=-DCC_GCC_LIKE_ASM -DSPARC64_MODE
1062 CFLAGS=-g $(CC_OPT) -funroll-loops $(PROFILE) \
1064 #-Wmissing-prototypes
1065 #if gcc 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1066 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1067 $(call set_if_empty,CPUTYPE,ultrasparc)
1069 CFLAGS+=-m64 -mcpu=ultrasparc \
1071 -fno-strict-overflow \
1073 # use -m64 to force 64 bit (but add it also to LDFLAGS and
1074 # don't forget to define SPARC64_MODE)
1075 # -m32 for 32 bit (default on solaris),
1076 # nothing for arch. default
1080 ifeq ($(CC_SHORTVER), 4.x)
1081 $(call set_if_empty,CPUTYPE,ultrasparc)
1083 CFLAGS+=-m64 -mcpu=ultrasparc \
1089 ifeq ($(CC_SHORTVER), 3.4)
1090 $(call set_if_empty,CPUTYPE,ultrasparc)
1092 CFLAGS+=-m64 -mcpu=ultrasparc -mtune=$(CPUTYPE)
1096 ifeq ($(CC_SHORTVER), 3.0)
1097 $(call set_if_empty,CPUTYPE,ultrasparc)
1099 CFLAGS+=-m64 -mcpu=ultrasparc -mtune=$(CPUTYPE) \
1100 # -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
1101 #-mno-epilogue #try to inline function exit code
1102 #-mflat # omit save/restore
1103 #-,faster-structs #faster non Sparc ABI structure copy ops
1105 else # CC_SHORTVER, 3.0
1106 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1107 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc >= 3.1 \
1109 ifneq ($(OS), netbsd)
1110 # on netbsd/sparc64, gcc 2.95.3 does not compile
1113 # -m64/-m32 on sparc works starting with gcc 3.0
1115 ifeq ($(ASTYPE), solaris)
1116 CFLAGS+= -Wa,-xarch=v8plus
1118 else #CC_SHORTVER, 2.9x
1120 $(warning You are using an old and unsupported gcc \
1121 version ($(CC_SHORTVER)), compile at your own risk!)
1124 ifeq ($(ASTYPE), solaris)
1125 CFLAGS+= -Wa,-xarch=v8plus
1128 endif #CC_SHORTVER, 2.9x
1129 endif #CC_SHORTVER, 3.0
1130 endif #CC_SHORTVER, 3.4
1131 endif #CC_SHORTVER, 4.x
1132 endif #CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1135 ifeq ($(CC_NAME), suncc)
1136 C_DEFS+=-DCC_GCC_LIKE_ASM
1137 C_DEFS+=-DSPARC64_MODE
1138 CFLAGS+= -m64 -g -xO3 -xtarget=native -xmemalign=8i \
1139 -fma=fused -fns=yes \
1142 # -Dinline="" # add this if cc < 5.3 (define inline as null)
1145 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1146 endif #CC_NAME, suncc
1148 endif #ARCH, sparc64
1151 ifeq ($(ARCH), sparc)
1153 ifeq ($(CC_NAME), gcc)
1154 C_DEFS+=-DCC_GCC_LIKE_ASM
1156 CFLAGS=-g $(CC_OPT) -funroll-loops $(PROFILE) \
1158 #-Wmissing-prototypes
1159 #if gcc 5.0+, 4.5+ or 4.2+
1160 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1161 $(call set_if_empty,CPUTYPE,v8)
1163 CFLAGS+= -mtune=$(CPUTYPE) \
1164 -fno-strict-overflow \
1168 ifeq ($(CC_SHORTVER), 4.x)
1169 $(call set_if_empty,CPUTYPE,v8)
1171 CFLAGS+= -mtune=$(CPUTYPE) \
1175 ifeq ($(CC_SHORTVER), 3.4)
1176 $(call set_if_empty,CPUTYPE,v8)
1178 CFLAGS+= -mtune=$(CPUTYPE)
1181 ifeq ($(CC_SHORTVER), 3.0)
1182 $(call set_if_empty,CPUTYPE,v8)
1184 CFLAGS+= -mtune=$(CPUTYPE) \
1185 #-mno-epilogue #try to inline function exit code
1186 #-mflat # omit save/restore
1187 #-,faster-structs #faster non Sparc ABI structure copy ops
1188 else # CC_SHORTVER, 3.0
1189 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1190 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc >= 3.1 \
1192 else #CC_SHORTVER, 2.9x
1194 $(warning You are using an old and unsupported gcc \
1195 version ($(CC_SHORTVER)), compile at your own risk!)
1197 endif #CC_SHORTVER, 2.9x
1198 endif #CC_SHORTVER, 3.0
1199 endif #CC_SHORTVER, 3.4
1200 endif #CC_SHORTVER, 4.x
1201 endif #CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1204 ifeq ($(CC_NAME), suncc)
1205 C_DEFS+=-DCC_GCC_LIKE_ASM
1206 CFLAGS+= -g -xO3 -xtarget=native -xmemalign=4i \
1207 -fma=fused -fns=yes \
1209 # -Dinline="" # add this if cc < 5.3 (define inline as null)
1212 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1213 endif #CC_NAME, suncc
1220 ifeq ($(CC_NAME), gcc)
1221 C_DEFS+=-DCC_GCC_LIKE_ASM
1223 CFLAGS=-marm -march=armv5t $(CC_OPT) -funroll-loops -fsigned-char $(PROFILE)
1224 #if gcc 4.5+ or 4.2+
1225 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1226 CFLAGS+= -ftree-vectorize -fno-strict-overflow
1227 # not supported on arm: -minline-all-stringops
1230 ifeq ($(CC_SHORTVER), 4.x)
1231 CFLAGS+= -ftree-vectorize
1232 # not supported on arm: -minline-all-stringops
1235 ifeq ($(CC_SHORTVER), 3.4)
1239 ifeq ($(CC_SHORTVER), 3.0)
1243 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1244 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
1250 $(warning You are using an old and unsupported gcc \
1251 version ($(CC_SHORTVER)), compile at your own risk!)
1253 endif # CC_SHORTVER, 2.9x
1254 endif # CC_SHORTVER, 3.0
1255 endif # CC_SHORTVER, 3.4
1256 endif # CC_SHORTVER, 4.x
1257 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1261 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1266 ifeq ($(ARCH), arm6)
1268 ifeq ($(CC_NAME), gcc)
1269 C_DEFS+=-DCC_GCC_LIKE_ASM
1271 CFLAGS=-march=armv6 $(CC_OPT) -funroll-loops -fsigned-char \
1273 #if gcc 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1274 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1275 CFLAGS+= -ftree-vectorize -fno-strict-overflow
1278 ifeq ($(CC_SHORTVER), 4.x)
1279 CFLAGS+= -ftree-vectorize
1282 ifeq ($(CC_SHORTVER), 3.4)
1286 ifeq ($(CC_SHORTVER), 3.0)
1290 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1291 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
1297 $(warning You are using an old and unsupported gcc \
1298 version ($(CC_SHORTVER)), compile at your own risk!)
1300 endif # CC_SHORTVER, 2.9x
1301 endif # CC_SHORTVER, 3.0
1302 endif # CC_SHORTVER, 3.4
1303 endif # CC_SHORTVER, 4.x
1304 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1308 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1313 ifeq ($(ARCH), mips)
1315 ifeq ($(CC_NAME), gcc)
1316 C_DEFS+=-DCC_GCC_LIKE_ASM
1318 CFLAGS=$(CC_OPT) -funroll-loops $(PROFILE)
1319 #if gcc 7.0+, 6.0, 5.0+, 4.5+ or 4.2+
1320 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1321 CFLAGS+=-mfp32 -march=r3000 \
1322 -ftree-vectorize -fno-strict-overflow
1323 # not supported on mips: -minline-all-stringops
1326 ifeq ($(CC_SHORTVER), 4.x)
1327 CFLAGS+=-march=r3000 \
1329 # not supported on mips: -minline-all-stringops
1332 ifeq ($(CC_SHORTVER), 3.4)
1333 CFLAGS+= -march=r3000
1336 ifeq ($(CC_SHORTVER), 3.0)
1337 CFLAGS+= -march=r3000
1339 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1340 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
1343 CFLAGS+=-march=r3000
1346 $(warning You are using an old and unsupported gcc \
1347 version ($(CC_SHORTVER)), compile at your own risk!)
1349 endif # CC_SHORTVER, 2.9x
1350 endif # CC_SHORTVER, 3.0
1351 endif # CC_SHORTVER, 3.4
1352 endif # CC_SHORTVER, 4.x
1353 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1357 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1361 #if >=mips2 (R4000, R5000, R6000 ....)
1362 ifeq ($(ARCH), mips2)
1364 ifeq ($(CC_NAME), gcc)
1365 C_DEFS+=-DCC_GCC_LIKE_ASM
1367 CFLAGS= -mips2 $(CC_OPT) -funroll-loops $(PROFILE)
1368 #if gcc 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1369 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1370 CFLAGS+=-ftree-vectorize -fno-strict-overflow
1371 # not supported on mips: -minline-all-stringops
1374 ifeq ($(CC_SHORTVER), 4.x)
1375 CFLAGS+=-ftree-vectorize
1376 # not supported on mips: -minline-all-stringops
1379 ifeq ($(CC_SHORTVER), 3.4)
1383 ifeq ($(CC_SHORTVER), 3.0)
1386 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1387 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
1392 $(warning You are using an old and unsupported gcc \
1393 version ($(CC_SHORTVER)), compile at your own risk!)
1395 endif # CC_SHORTVER, 2.9x
1396 endif # CC_SHORTVER, 3.0
1397 endif # CC_SHORTVER, 3.4
1398 endif # CC_SHORTVER, 4.x
1399 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1403 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1408 ifeq ($(ARCH), mips64)
1410 ifeq ($(CC_NAME), gcc)
1411 C_DEFS+=-DCC_GCC_LIKE_ASM
1413 CFLAGS= -mips64 $(CC_OPT) -funroll-loops $(PROFILE)
1414 #if gcc 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1415 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1416 CFLAGS+=-ftree-vectorize -fno-strict-overflow
1417 # not supported on mips: -minline-all-stringops
1421 ifeq ($(CC_SHORTVER), 4.x)
1422 CFLAGS+=-ftree-vectorize
1423 # not supported on mips: -minline-all-stringops
1426 ifeq ($(CC_SHORTVER), 3.4)
1430 ifeq ($(CC_SHORTVER), 3.0)
1433 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1434 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
1439 $(warning You are using an old and unsupported gcc \
1440 version ($(CC_SHORTVER)), compile at your own risk!)
1442 endif # CC_SHORTVER, 2.9x
1443 endif # CC_SHORTVER, 3.0
1444 endif # CC_SHORTVER, 3.4
1445 endif # CC_SHORTVER, 4.x
1446 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1450 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1455 ifeq ($(ARCH), alpha)
1457 ifeq ($(CC_NAME), gcc)
1458 C_DEFS+=-DCC_GCC_LIKE_ASM
1460 CFLAGS= $(CC_OPT) -funroll-loops $(PROFILE)
1461 #if gcc 5.0+, 4.5 or 4.2+
1462 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1463 CFLAGS+= -fno-strict-overflow
1464 # not supported: -minline-all-stringops
1467 ifeq ($(CC_SHORTVER), 4.x)
1469 # not supported: -minline-all-stringops
1472 ifeq ($(CC_SHORTVER), 3.4)
1476 ifeq ($(CC_SHORTVER), 3.0)
1479 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1480 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
1485 $(warning You are using an old and unsupported gcc \
1486 version ($(CC_SHORTVER)), compile at your own risk!)
1488 endif # CC_SHORTVER, 2.9x
1489 endif # CC_SHORTVER, 3.0
1490 endif # CC_SHORTVER, 3.4
1491 endif # CC_SHORTVER, 4.x
1492 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1496 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1503 ifeq ($(CC_NAME), gcc)
1504 C_DEFS+=-DCC_GCC_LIKE_ASM
1507 #if gcc 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1508 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1509 $(call set_if_empty,CPUTYPE,powerpc)
1510 ifeq ($(NOALTIVEC),)
1511 CFLAGS += $(CC_OPT) -funroll-loops -fsigned-char $(PROFILE)
1512 CFLAGS += -ftree-vectorize
1514 CFLAGS += -fno-strict-overflow
1515 CFLAGS += -mtune=$(CPUTYPE)
1519 ifeq ($(CC_SHORTVER), 4.x)
1520 $(call set_if_empty,CPUTYPE,powerpc)
1521 ifeq ($(NOALTIVEC),)
1522 CFLAGS += $(CC_OPT) -funroll-loops -fsigned-char $(PROFILE)
1523 CFLAGS += -ftree-vectorize
1525 CFLAGS += -mtune=$(CPUTYPE)
1529 ifeq ($(CC_SHORTVER), 3.4)
1533 ifeq ($(CC_SHORTVER), 3.0)
1536 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1537 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
1542 $(warning You are using an old and unsupported gcc \
1543 version ($(CC_SHORTVER)), compile at your own risk!)
1545 endif # CC_SHORTVER, 2.9x
1546 endif # CC_SHORTVER, 3.0
1547 endif # CC_SHORTVER, 3.4
1548 endif # CC_SHORTVER, 4.x
1549 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1553 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1558 ifeq ($(ARCH), ppc64)
1560 ifeq ($(CC_NAME), gcc)
1561 C_DEFS+=-DCC_GCC_LIKE_ASM
1563 CFLAGS= $(CC_OPT) -funroll-loops -fsigned-char $(PROFILE)
1564 #if gcc 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1565 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+ 6.0+ 7.0+,$(CC_SHORTVER))))
1566 $(call set_if_empty,CPUTYPE,powerpc64)
1567 CFLAGS+=-ftree-vectorize \
1568 -fno-strict-overflow \
1569 -mtune=$(CPUTYPE) -maltivec
1572 ifeq ($(CC_SHORTVER), 4.x)
1573 $(call set_if_empty,CPUTYPE,powerpc64)
1574 CFLAGS+=-ftree-vectorize \
1575 -mtune=$(CPUTYPE) -maltivec
1578 ifeq ($(CC_SHORTVER), 3.4)
1582 ifeq ($(CC_SHORTVER), 3.0)
1585 ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1586 $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
1591 $(warning You are using an old and unsupported gcc \
1592 version ($(CC_SHORTVER)), compile at your own risk!)
1594 endif # CC_SHORTVER, 2.9x
1595 endif # CC_SHORTVER, 3.0
1596 endif # CC_SHORTVER, 3.4
1597 endif # CC_SHORTVER, 4.x
1598 endif # CC_SHORTVER, 7.0+, 6.0+, 5.0+, 4.5+ or 4.2+
1602 $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1606 CFLAGS+= $(CC_EXTRA_OPTS)
1610 ifeq ($(CC_NAME), gcc)
1611 ifeq ($(LDTYPE), solaris)
1613 LDFLAGS+=-O2 $(PROFILE)
1614 MOD_LDFLAGS:=-G $(LDFLAGS)
1615 LIB_LDFLAGS:=-G $(LDFLAGS)
1619 #gcc and maybe others, => gnu ld
1620 LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE)
1621 MOD_LDFLAGS:=-shared $(LDFLAGS)
1622 LIB_LDFLAGS:=-shared $(LDFLAGS)
1623 LIB_SONAME=-Wl,-soname,
1624 LD_RPATH=-Wl,-rpath,
1627 ifeq ($(CC_NAME), icc)
1628 #gcc and maybe others
1629 LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE)
1630 MOD_LDFLAGS:=-shared $(LDFLAGS)
1631 LIB_LDFLAGS:=-shared $(LDFLAGS)
1632 LIB_SONAME=-Wl,-soname,
1633 LD_RPATH=-Wl,-rpath,
1635 ifeq ($(CC_NAME), suncc)
1637 LDFLAGS+=-xO3 $(PROFILE)
1638 MOD_LDFLAGS:=-G $(LDFLAGS)
1639 LIB_LDFLAGS:=-G $(LDFLAGS)
1643 # we need -fPIC -DPIC only for shared objects, we don't need them for
1644 # the executable file, because it's always loaded at a fixed address
1647 ifeq ($(CC_NAME), clang)
1648 LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE)
1649 MOD_LDFLAGS:=-shared $(LDFLAGS)
1650 LIB_LDFLAGS:=-shared $(LDFLAGS)
1651 LIB_SONAME=-Wl,-soname,
1652 LD_RPATH=-Wl,-rpath,
1655 LDFLAGS+= $(LD_EXTRA_OPTS)
1656 MOD_LDFLAGS+= $(LD_EXTRA_OPTS)
1657 LIB_LDFLAGS+= $(LD_EXTRA_OPTS)
1660 ifeq ($(CC_NAME), gcc)
1661 CFLAGS=-g -Wcast-align $(PROFILE)
1662 C_DEFS+=-DCC_GCC_LIKE_ASM
1663 ifeq ($(ARCH), sparc64)
1664 C_DEFS+=SPARC64_MODE
1665 CFLAGS+= -mcpu=ultrasparc -m64
1668 ifeq ($(LDTYPE), solaris)
1670 LDFLAGS+=-g $(PROFILE)
1671 MOD_LDFLAGS:=-G $(LDFLAGS)
1672 LIB_LDFLAGS:=-G $(LDFLAGS)
1676 #gnu or other ld type
1677 LDFLAGS+=-g -Wl,-E $(PROFILE)
1678 MOD_LDFLAGS:=-shared $(LDFLAGS)
1679 LIB_LDFLAGS:=-shared $(LDFLAGS)
1680 LIB_SONAME=-Wl,-soname,
1681 LD_RPATH=-Wl,-rpath,
1684 ifeq ($(CC_NAME), icc)
1685 C_DEFS+=-DCC_GCC_LIKE_ASM
1686 CFLAGS=-g $(PROFILE)
1687 LDFLAGS+=-g -Wl,-E $(PROFILE)
1688 MOD_LDFLAGS:=-shared $(LDFLAGS)
1689 LIB_LDFLAGS:=-shared $(LDFLAGS)
1690 LIB_SONAME=-Wl,-soname,
1691 LD_RPATH=-Wl,-rpath,
1693 ifeq ($(CC_NAME), suncc)
1694 CFLAGS= -g $(PROFILE)
1695 LDFLAGS+=-g $(PROFILE)
1696 MOD_LDFLAGS:=-G $(LDFLAGS)
1697 LIB_LDFLAGS:=-G $(LDFLAGS)
1705 # set pedantic compiler options
1706 ifeq ($(CC_NAME), gcc)
1709 ifeq ($(CC_NAME), icc)
1712 ifeq ($(CC_NAME), suncc)
1713 # FIXME: is the default (-Xa ?) enough?
1714 endif # CC_NAME=suncc
1718 #CFLAGS used for compiling the modules, libraries and utils
1719 ifeq ($(CC_NAME), gcc)
1720 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
1721 LIB_CFLAGS=-fPIC -DPIC $(CFLAGS)
1723 ifeq ($(CC_NAME), icc)
1724 MOD_CFLAGS=-Kpic $(CFLAGS)
1725 LIB_CFLAGS=-Kpic $(CFLAGS)
1727 ifeq ($(CC_NAME), suncc)
1728 MOD_CFLAGS=-xcode=pic32 $(CFLAGS)
1729 LIB_CFLAGS=-xcode=pic32 $(CFLAGS)
1731 ifeq ($(CC_NAME), clang)
1732 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
1733 LIB_CFLAGS=-fPIC -DPIC $(CFLAGS)
1736 UTILS_CFLAGS=$(CFLAGS)
1737 # LDFLAGS uses for compiling the utils
1738 UTILS_LDFLAGS=$(LDFLAGS)
1746 YACC_FLAGS=-d -b core/cfg
1747 # on solaris add -lxnet (e.g. LIBS= -lxnet)
1755 # by default use futexes if available
1757 C_DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1758 -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1759 -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DHAVE_IP_MREQN
1760 ifeq ($(RAW_SOCKS), yes)
1761 C_DEFS+= -DUSE_RAW_SOCKS
1763 ifneq ($(found_lock_method), yes)
1764 #C_DEFS+= -DUSE_POSIX_SEM
1765 C_DEFS+=-DUSE_PTHREAD_MUTEX
1767 #C_DEFS+= -DUSE_SYSV_SEM # try posix sems
1768 found_lock_method=yes
1770 ifneq (,$(findstring -DUSE_POSIX_SEM, $(C_DEFS)))
1773 ifneq (,$(findstring -DUSE_PTHREAD_MUTEX, $(C_DEFS)))
1778 # check for >= 2.5.44
1779 ifeq ($(shell [ $(OSREL_N) -ge 2005044 ] && echo has_epoll), has_epoll)
1781 C_DEFS+=-DHAVE_EPOLL
1782 # linux + gcc >= 3.0 + -malign-double + epoll => problems
1783 CFLAGS_RM+=-malign-double
1784 #CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1787 # check for >= 2.2.0
1788 ifeq ($(shell [ $(OSREL_N) -ge 2002000 ] && echo has_sigio), has_sigio)
1790 C_DEFS+=-DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND
1793 # check for >= 2.5.70
1794 ifeq ($(shell [ $(OSREL_N) -ge 2005070 ] && echo has_futex), has_futex)
1795 ifeq ($(use_futex), yes)
1799 ifeq ($(NO_SELECT),)
1800 C_DEFS+=-DHAVE_SELECT
1804 ifeq ($(OS), gnu_kfreebsd)
1805 # by default use futexes if available
1807 C_DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1808 -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1809 -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER
1810 ifeq ($(RAW_SOCKS), yes)
1811 C_DEFS+= -DUSE_RAW_SOCKS
1813 ifneq ($(found_lock_method), yes)
1814 #C_DEFS+= -DUSE_POSIX_SEM
1815 C_DEFS+=-DUSE_PTHREAD_MUTEX
1817 #C_DEFS+= -DUSE_SYSV_SEM # try posix sems
1818 found_lock_method=yes
1820 ifneq (,$(findstring -DUSE_POSIX_SEM, $(C_DEFS)))
1823 ifneq (,$(findstring -DUSE_PTHREAD_MUTEX, $(C_DEFS)))
1828 # check for ver >= 4.1
1829 ifeq ($(shell [ $(OSREL_N) -gt 4001 ] && echo has_kqueue), has_kqueue)
1830 ifeq ($(NO_KQUEUE),)
1831 C_DEFS+=-DHAVE_KQUEUE
1834 ifeq ($(NO_SELECT),)
1835 C_DEFS+=-DHAVE_SELECT
1839 ifeq ($(OS), solaris)
1840 C_DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
1841 -DHAVE_ALLOCA_H -DUSE_SIGACTION
1842 ifneq ($(found_lock_method), yes)
1843 C_DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
1844 found_lock_method=yes
1846 # check for ver >= 5.7
1847 ifeq ($(shell [ $(OSREL_N) -gt 5007 ] && echo has_devpoll), has_devpoll)
1848 ifeq ($(NO_DEVPOLL),)
1849 C_DEFS+=-DHAVE_DEVPOLL
1852 ifeq ($(NO_SELECT),)
1853 C_DEFS+=-DHAVE_SELECT
1856 filio_h_locations= /usr/include/sys/filio.h \
1857 $(LOCALBASE)/include/sys/filio.h
1858 has_filio_h=$(shell for r in $(filio_h_locations); do \
1859 if [ -r "$$r" ] ; then echo yes; exit; fi \
1862 ifeq ($(has_filio_h), yes)
1863 C_DEFS+=-DHAVE_FILIO_H
1865 ifeq ($(mode), release)
1866 #use these only if you're using gcc with Solaris ld
1867 #LDFLAGS=-O2 $(PROFILE)
1870 #LDFLAGS=-g $(PROFILE)
1875 ifeq ($(CC_NAME), suncc)
1878 OLD_SOLARIS= $(shell echo "$(OSREL)" | \
1879 sed -e 's/^5\.[0-6][^0-9]*$$/yes/' )
1880 LIBS+= -L$(LOCALBASE)/lib -lxnet -lsocket -lnsl -lmd5
1881 ifeq ($(OLD_SOLARIS), yes)
1886 # -lrt needed for sched_yield
1889 ifeq ($(OS), freebsd)
1890 C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1891 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1892 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1893 -DHAVE_NETINET_IN_SYSTM -DHAVE_IP_MREQN
1894 ifeq ($(RAW_SOCKS), yes)
1895 C_DEFS+= -DUSE_RAW_SOCKS
1897 ifneq ($(found_lock_method), yes)
1898 C_DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
1899 found_lock_method=yes
1900 LIBS+= -pthread #dlopen is in libc
1902 LIBS= #dlopen is in libc
1904 # check for ver >= 4.1
1905 ifeq ($(shell [ $(OSREL_N) -gt 4001 ] && echo has_kqueue), has_kqueue)
1906 ifeq ($(NO_KQUEUE),)
1907 C_DEFS+=-DHAVE_KQUEUE
1910 ifeq ($(NO_SELECT),)
1911 C_DEFS+=-DHAVE_SELECT
1916 ifeq ($(OS), dragonfly)
1917 C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1918 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1919 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1920 -DHAVE_NETINET_IN_SYSTM
1921 ifneq ($(found_lock_method), yes)
1922 C_DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
1923 found_lock_method=yes
1924 LIBS+= -pthread #dlopen is in libc
1926 LIBS= #dlopen is in libc
1928 # dragonfly was forked from freebsd 4.8 => all version have kqueue
1929 ifeq ($(NO_KQUEUE),)
1930 C_DEFS+=-DHAVE_KQUEUE
1932 ifeq ($(NO_SELECT),)
1933 C_DEFS+=-DHAVE_SELECT
1938 ifeq ($(OS), openbsd)
1939 C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
1940 -DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL \
1941 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1942 -DHAVE_NETINET_IN_SYSTM -DUSE_SIGWAIT \
1944 ifneq ($(found_lock_method), yes)
1945 C_DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
1946 found_lock_method=yes
1948 # check for ver >=2 9
1949 ifeq ($(shell [ $(OSREL_N) -ge 2009 ] && echo has_kqueue), has_kqueue)
1950 ifeq ($(NO_KQUEUE),)
1951 C_DEFS+=-DHAVE_KQUEUE
1954 ifeq ($(NO_SELECT),)
1955 C_DEFS+=-DHAVE_SELECT
1957 # (symbols on openbsd are prefixed by "_")
1959 # unfortunately pthread is needed for sigwait
1963 ifeq ($(OS), netbsd)
1964 C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
1965 -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1966 ifneq ($(found_lock_method), yes)
1967 C_DEFS+= -DUSE_SYSV_SEM # try pthread sems
1968 found_lock_method=yes
1970 # check for ver >= 2.0.0
1971 ifeq ($(shell [ $(OSREL_N) -ge 2000000 ] && echo has_kqueue), has_kqueue)
1972 ifeq ($(NO_KQUEUE),)
1973 C_DEFS+=-DHAVE_KQUEUE
1974 # netbsd + kqueue and -malign-double don't work
1975 CFLAGS_RM+=-malign-double
1976 #CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1979 ifeq ($(NO_SELECT),)
1980 C_DEFS+=-DHAVE_SELECT
1986 # OS X support, same as freebsd
1987 ifeq ($(OS), darwin)
1988 C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1989 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1991 -DNDEBUG -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1992 -DUSE_SIGWAIT -DHAVE_IP_MREQN
1993 # -DNDEBUG used to turn off assert (assert wants to call
1994 # eprintf which doesn't seem to be defined in any shared lib
1995 ifneq ($(found_lock_method), yes)
1996 C_DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
1997 found_lock_method=yes
1998 C_DEFS+= -DUSE_SYSV_SEM # try sys v sems (pthread don't work for
1999 # processes and unnamed posix sems are not
2002 LIBS= -lresolv #dlopen is in libc
2003 ifeq ($(NO_KQUEUE),)
2004 C_DEFS+=-DHAVE_KQUEUE
2006 ifeq ($(NO_SELECT),)
2007 C_DEFS+=-DHAVE_SELECT
2009 LDFLAGS= # darwin doesn't like -O2 or -E
2010 # the modules uses symbols from ser => either
2011 # -flat_namespace -undefined_suppress or -bundle_loader ../../$(MAIN_NAME)
2012 MOD_LDFLAGS:= -bundle -flat_namespace -undefined suppress
2013 # for libs using symbols from ser (e.g srdb2, a.s.o) we
2014 # need -flat_namespace -undefined suppress
2015 LIB_LDFLAGS:= -dynamiclib -flat_namespace -undefined suppress
2017 # on darwin soname should include the full path
2018 # (it kind of combines rpath & soname)
2020 # no equiv. for rpath on darwin
2025 ifneq (,$(findstring cygwin, $(OS)))
2026 # cygwin does support IPV6 starting from version 1.7, but (still?) doesn't support fd passing so no TCP
2027 #C_DEFS:=$(filter-out -DUSE_TCP, $(C_DEFS))
2029 C_DEFS+=-DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
2030 -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
2031 -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER
2032 ifneq ($(found_lock_method), yes)
2033 C_DEFS+= -DUSE_POSIX_SEM
2034 #C_DEFS+= -DUSE_SYSV_SEM # try posix sems
2035 # PTHREAD_MUTEX do not work for processes (try test/pthread_test.c)
2037 found_lock_method=yes
2039 ifneq (,$(findstring -DUSE_POSIX_SEM, $(C_DEFS)))
2042 ifneq (,$(findstring -DUSE_PTHREAD_MUTEX, $(C_DEFS)))
2043 $(error PTHREAD_MUTEX do not work for processes on Windows/CYGWIN)
2046 # check for >= 2.5.70
2047 ifeq ($(NO_SELECT),)
2048 C_DEFS+=-DHAVE_SELECT
2052 #add libssl if needed
2053 ifeq ($(CORE_TLS), 1)
2054 C_INCLUDES+= -I$(LOCALBASE)/ssl/include
2055 LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lssl -lcrypto \
2057 # NOTE: depending on the way in which libssl was compiled you might
2058 # have to add -lz -lkrb5 (zlib and kerberos5).
2059 # E.g.: make CORE_TLS=1 EXTRA_TLS_LIBS="-lz -lkrb5"
2062 ifneq ($(found_lock_method), yes)
2063 $(warning No locking method found so far, trying SYS V sems)
2064 C_DEFS+= -DUSE_SYSV_SEM # try sys v sems
2065 found_lock_method=yes
2069 endif # ifeq (,$(main_makefile))
2070 endif # ifeq ($(makefile_defs), 1)
2072 # if incomplete or missing config.mak, or already exported vars, don't
2073 # try to export/re-export
2074 ifeq ($(makefile_defs),1)
2075 ifneq ($(exported_vars),1)
2078 override exported_vars:=1
2079 export exported_vars
2081 # variable changeable only at configure time (once saved in config.mak they
2082 # cannot be overwritten from environment or command line, unless make cfg
2084 saved_fixed_vars:= MAIN_NAME CFG_NAME SCR_NAME FLAVOUR INSTALL_FLAVOUR \
2085 SRC_NAME RELEASE OS ARCH \
2086 C_DEFS DEFS_RM PROFILE CC LD MKDEP MKTAGS LDFLAGS C_INCLUDES \
2088 MOD_LDFLAGS LIB_LDFLAGS UTILS_LDFLAGS LIB_SONAME LD_RPATH \
2089 LIB_SUFFIX LIB_PREFIX \
2091 LEX YACC YACC_FLAGS \
2094 INSTALL INSTALL_CFG INSTALL_BIN INSTALL_MODULES INSTALL_DOC \
2095 INSTALL_MAN INSTALL_LIB INSTALL_TOUCH INSTALL_SHARE \
2098 # variable changeable at compile time
2099 # extra: prefix DESTDIR BASEDIR basedirt
2101 CC_EXTRA_OPTS CPUTYPE CFLAGS_RM CFLAGS MOD_CFLAGS LIB_CFLAGS UTILS_CFLAGS \
2102 BASEDIR basedir DESTDIR LIBDIR RUNBASEDIR runbasedir \
2104 cfg_prefix cfg_dir bin_prefix bin_dir modules_prefix modules_dir \
2105 doc_prefix doc_dir man_prefix man_dir ut_prefix ut_dir \
2106 share_prefix share_dir lib_prefix lib_dir data_prefix data_dir \
2107 cfg_target lib_target data_target run_prefix run_dir run_target
2110 #export relevant variables to the sub-makes
2111 export $(saved_fixed_vars)
2112 export $(saved_chg_vars)
2115 endif # ifneq ($(exported_vars),1)
2116 endif # ifeq ($(makefile_defs),1)