Makefile.defs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. # $Id$
  2. #
  3. # makefile defs (CC, LD,a.s.o)
  4. #
  5. # Environment variables:
  6. # PREFIX, LOCALBASE, BASEDIR
  7. # INSTALL, TAR , CC, LEX, YACC,
  8. # CPU, CC_EXTRA_OPTS,
  9. # exclude_modules, skip_modules, include_modules
  10. # extra_defs
  11. #
  12. # History:
  13. # --------
  14. # created by andrei
  15. # 2003-02-24 added LOCALBASE, fixed doc-dir for freebsd - patch provided
  16. # by Maxim Sobolev <[email protected]>
  17. # 2003-02-25 added -DDISABLE_NAGLE (andrei)
  18. # 2003-03-02 added -DDIGEST_DOMAIN (janakj)
  19. # 2003-03-10 added -xcode=pic32 for module compilation w/ sun cc
  20. # (too many symbols for pic13) (andrei)
  21. # 2003-04-16 added CC_EXTRA_OPTS, s/march/mcpu, added CPU (cpu to optimize
  22. # for, used only with gcc-3.x) (andrei)
  23. # 2003-05-23 check if this makefile was already included (andrei)
  24. # removed -DDIGEST_DOMAIN (andrei)
  25. # 2003-05-30 added extra_defs (andrei)
  26. # 2003-06-06 moved compiler detection before DEFS (andrei)
  27. # 2003-06-10 removed -m32 for gcc 3.x/sparc64 -- it will use
  28. # arch. default: -m32 on solaris, -m64 on *bsd (andrei)
  29. # 2003-09-25 added -pthread into LIBS when compiling on FreeBSD/alpha
  30. # and other FreeBSD arches for which no fast locking assembly
  31. # code exists (sobomax)
  32. # 2003-11-08 mips1 support introduced (andrei)
  33. # 2003-11-24 openbsd 3.4 (elf) fixes (andrei)
  34. # 2004-07-27 darwin (mac os x) port (andrei)
  35. # 2004-09-12 mips2 & cobalt support introduced (andrei)
  36. # 2004-09-28 x86_64 support introduced (andrei)
  37. # check if already included/exported
  38. ifeq ($(makefile_defs), 1)
  39. else
  40. makefile_defs=1
  41. export makefile_defs
  42. # main binary name
  43. MAIN_NAME=ser
  44. #version number
  45. VERSION = 0
  46. PATCHLEVEL = 8
  47. SUBLEVEL = 99
  48. EXTRAVERSION = -dev15
  49. RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
  50. OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
  51. ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
  52. -e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" -e "s/cobalt/mips2/" )
  53. OSREL = $(shell uname -r)
  54. # TLS support
  55. TLS ?=
  56. ifneq ($(TLS),)
  57. RELEASE:=$(RELEASE)-tls
  58. endif
  59. # extra CC command line options (e.g -march=athlon-mp)
  60. CC_EXTRA_OPTS ?=
  61. # install location
  62. DESTDIR ?= /usr/local
  63. PREFIX ?= $(DESTDIR)
  64. LOCALBASE ?= /usr/local
  65. prefix = $(PREFIX)
  66. # install path is $(basedir) $(prefix)
  67. # example:
  68. # creating a bin. archive in /tmp, which unpacks in /usr/local
  69. # basedir=/tmp
  70. # prefix=/usr/local
  71. BASEDIR ?=
  72. basedir = $(BASEDIR)
  73. # install prefixes for various stuff
  74. cfg-prefix = $(basedir)$(prefix)
  75. bin-prefix = $(basedir)$(prefix)
  76. modules-prefix = $(basedir)$(prefix)
  77. doc-prefix = $(basedir)$(prefix)
  78. man-prefix = $(basedir)$(prefix)
  79. ut-prefix = $(basedir)$(prefix)
  80. # dirs
  81. cfg-dir = etc/ser/
  82. bin-dir = sbin/
  83. modules-dir = lib/ser/modules/
  84. ifeq ($(OS), linux)
  85. doc-dir = share/doc/ser/
  86. man-dir = share/man/
  87. else
  88. ifeq ($(OS), freebsd)
  89. doc-dir = share/doc/ser/
  90. man-dir = man/
  91. else
  92. ifeq ($(OS), openbsd)
  93. doc-dir = share/doc/ser/
  94. man-dir = man/
  95. else
  96. ifeq ($(OS), netbsd)
  97. doc-dir = share/doc/ser
  98. man-dir = man/
  99. else
  100. ifeq ($(OS), darwin)
  101. doc-dir = share/doc/ser/
  102. man-dir = man/
  103. else
  104. doc-dir = doc/ser/
  105. man-dir = man/
  106. endif
  107. endif
  108. endif
  109. endif
  110. endif
  111. ut-prefix = bin/
  112. # target dirs for various stuff
  113. cfg-target = $(prefix)/$(cfg-dir)
  114. bin-target = $(prefix)/$(bin-dir)
  115. modules-target = $(prefix)/$(modules-dir)
  116. doc-target = $(prefix)/$(doc-dir)
  117. ifeq ($(OS), solaris)
  118. #use GNU versions
  119. INSTALL ?= ginstall
  120. TAR ?= gtar
  121. else
  122. INSTALL ?= install
  123. TAR ?= tar
  124. endif
  125. INSTALL-TOUCH = touch # used to create the file first (good to
  126. # make solaris install work)
  127. # INSTALL-CFG = $(INSTALL) -m 644
  128. INSTALL-BIN = $(INSTALL) -m 755
  129. INSTALL-MODULES = $(INSTALL) -m 755
  130. INSTALL-DOC = $(INSTALL) -m 644
  131. INSTALL-MAN = $(INSTALL) -m 644
  132. #set some vars from the environment (and not make builtins)
  133. CC := $(shell echo "$${CC}")
  134. LEX := $(shell echo "$${LEX}")
  135. YACC := $(shell echo "$${YACC}")
  136. # find compiler name & version
  137. ifeq ($(CC),)
  138. CC=gcc
  139. endif
  140. LD= $(CC)
  141. CC_LONGVER=$(shell if $(CC) -v 2>/dev/null; then \
  142. $(CC) -v 2>&1 ;\
  143. else \
  144. $(CC) -V 2>&1 ; \
  145. fi )
  146. MKTAGS=ctags -R .
  147. #find-out the compiler's name
  148. ifneq (,$(findstring gcc, $(CC_LONGVER)))
  149. CC_NAME=gcc
  150. CC_VER=$(CC) $(shell $(CC) --version|head -n 1| \
  151. sed -e 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/' -e 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
  152. # sun sed is a little brain damaged => this complicated expression
  153. MKDEP=$(CC) -MM
  154. #transform gcc version into 2.9x or 3.0
  155. CC_SHORTVER=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
  156. sed -e 's/[^0-9]*-\(.*\)/\1/'| \
  157. sed -e 's/2\.9.*/2.9x/' -e 's/3\..\..*/3.0/' -e \
  158. 's/3\../3.0/')
  159. endif
  160. ifneq (, $(findstring Sun, $(CC_LONGVER)))
  161. CC_NAME=suncc
  162. CC_SHORTVER=$(shell echo "$(CC_LONGVER)"|head -n 1| \
  163. sed -e 's/.*\([0-9]\.[0-9]\).*/\1/g' )
  164. CC_VER=$(CC) $(CC_SHORTVER)
  165. MKDEP=$(CC) -xM1
  166. endif
  167. ifneq (, $(findstring Intel(R) C++ Compiler, $(CC_LONGVER)))
  168. # very nice: gcc compatible
  169. CC_NAME=icc
  170. CC_FULLVER=$(shell echo "$(CC_LONGVER)"|head -n 1| \
  171. sed -e 's/.*Version \([0-9]\.[0-9]\.[0-9]*\).*/\1/g' )
  172. CC_SHORTVER=$(shell echo "$(CC_FULLVER)" | cut -d. -f1,2 )
  173. CC_VER=$(CC) $(CC_FULLVER)
  174. MKDEP=$(CC) -MM
  175. endif
  176. ifeq (,$(CC_NAME))
  177. #not found
  178. CC_NAME=$(CC)
  179. CC_SHORTVER=unknown
  180. CC_VER=unknown
  181. MKDEP=gcc -MM
  182. $(warning Unknown compiler $(CC)\; supported compilers: \
  183. gcc, sun cc, intel icc )
  184. endif
  185. # compile-time options
  186. #
  187. # -DSTATS
  188. # allows to print out number of packets processed on CTRL-C;
  189. # implementation still nasty and reports per-process
  190. # -DNO_DEBUG
  191. # turns off some of the debug messages (DBG(...)).
  192. # -DNO_LOG
  193. # completely turns of all the logging (and DBG(...))
  194. # -DEXTRA_DEBUG
  195. # compiles in some extra debugging code
  196. # -DDNS_IP_HACK
  197. # faster ip address resolver for ip strings (e.g "127.0.0.1")
  198. # -DSHM_MEM
  199. # compiles in shared mem. support, needed by some modules and
  200. # by USE_SHM_MEM
  201. # -DSHM_MMAP
  202. # use mmap instead of SYSV shared memory
  203. # -DPKG_MALLOC
  204. # uses a faster malloc (exclusive w/ USE_SHM_MEM)
  205. # -DUSE_SHM_MEM
  206. # all pkg_malloc => shm_malloc (most mallocs use a common sh.
  207. # mem. segment); don't define PKG_MALLOC if you want this!
  208. # -DDBG_QM_MALLOC
  209. # qm_malloc debug code, will cause pkg_malloc and shm_malloc
  210. # to keep and display lot of debuging information: file name,
  211. # function, line number of malloc/free call for each block,
  212. # extra error checking (trying to free the same pointer
  213. # twice, trying to free a pointer alloc'ed with a different
  214. # malloc etc.)
  215. # -DVQ_MALLOC
  216. # additional option to PKG_MALLOC which utilizes a fater then
  217. # qm version
  218. # (not true anymore, q_malloc performs approx. the same)
  219. # -DF_MALLOC
  220. # an even faster malloc, not recommended for debugging
  221. # -DDBG_MALLOC
  222. # issues additional debugging information if lock/unlock is called
  223. # -DFAST_LOCK
  224. # uses fast arhitecture specific locking (see the arh. specific section)
  225. # -DUSE_SYSV_SEM
  226. # uses sys v sems for locking (slower & limited number)
  227. # -DUSE_PTHREAD_MUTEX
  228. # uses pthread mutexes, faster than sys v or posix sems, but do not
  229. # work on all systems inter-processes (e.g. linux)
  230. # -DUSE_POSIX_SEM
  231. # uses posix semaphores for locking (faster than sys v)
  232. # -DBUSY_WAIT
  233. # uses busy waiting on the lock (FAST_LOCK)
  234. # -DADAPTIVE_WAIT
  235. # try busy waiting for a while and if the lock is still held go to
  236. # force reschedule (FAST_LOCK)
  237. # -DADAPTIVE_WAIT_LOOPS=number
  238. # number of loops we busy wait, after "number" loops have elapsed we
  239. # force a reschedule (FAST_LOCK)
  240. # -DNOSMP
  241. # don't use smp compliant locking (faster but won't work on SMP machines)
  242. # (not yet enabled) (FAST_LOCK)
  243. # -DNO_PINGTEL_TAG_HACK
  244. # if enabled, To-header-field will be less liberal and will not accept
  245. # 'tag=' (tag parameter with equal sign and without value); it is called
  246. # this way because such message was sighted from a Pingtel phone
  247. # -DWITH_SNMP_MOD
  248. # if enabled, allows forking of the snmp agent just before child
  249. # forking (done at the top of main_loop). Needed if you want
  250. # to use the snmp module.
  251. # -DUSE_TCP
  252. # compiles in tcp support
  253. # -DDISABLE_NAGLE
  254. # disable the tcp Nagle algorithm (lower delay)
  255. # -DUSE_TLS
  256. # compiles in tls support, requires -DUSE_TCP. Please use
  257. # make TLS=1 instead. (tls support is highly experimental for now)
  258. DEFS+= $(extra_defs) \
  259. -DNAME='"$(MAIN_NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
  260. -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"' -D__CPU_$(ARCH) -D__OS_$(OS) \
  261. -DCFG_DIR='"$(cfg-target)"'\
  262. -DPKG_MALLOC \
  263. -DSHM_MEM -DSHM_MMAP \
  264. -DDNS_IP_HACK \
  265. -DUSE_IPV6 \
  266. -DUSE_MCAST \
  267. -DUSE_TCP \
  268. -DDISABLE_NAGLE \
  269. -DF_MALLOC \
  270. # -DDBG_QM_MALLOC \
  271. # -DDBG_F_MALLOC \
  272. #-DF_MALLOC \
  273. #-DNO_DEBUG \
  274. #-DNO_LOG
  275. #-DEXTRA_DEBUG \
  276. #-DDBG_QM_MALLOC \
  277. #-DVQ_MALLOC
  278. #-DCONTACT_BUG
  279. #-DDBG_LOCK
  280. #-DNOSMP \
  281. #-DEXTRA_DEBUG \
  282. #-DUSE_SHM_MEM \
  283. #-DSTATS \
  284. #-DWITH_SNMP_MOD \
  285. #-DNO_LOG
  286. #PROFILE= -pg #set this if you want profiling
  287. # WARNING: do not add mode=debug or mode=release anymore in the Makefile,
  288. # use make mode=debug all instead. Anyway no by default ser is compiled w/
  289. # debugging symbols in all cases (-g). --andrei
  290. ifneq ($(TLS),)
  291. DEFS+= -DUSE_TLS
  292. endif
  293. ifeq ($(mode),)
  294. mode = release
  295. endif
  296. ifeq ($(mode),debug)
  297. DEFS+= -DEXTRA_DEBUG
  298. endif
  299. # platform dependent settings
  300. # find ld & as name (gnu or solaris)
  301. ifeq ($(ARCH), sparc64)
  302. ifeq ($(CC_NAME), gcc)
  303. LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
  304. sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
  305. ASGCC=$(shell $(CC) -v 2>&1 | grep with-as| \
  306. sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
  307. LDPATH=$(shell if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
  308. else \
  309. if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
  310. echo $(LDGCC); \
  311. else echo "ld" ; \
  312. fi\
  313. fi)
  314. ASPATH=$(shell if [ -z "$(ASGCC)" ] ; then echo "as" ;\
  315. else \
  316. if $(ASGCC) -V 2>/dev/null 1>/dev/null; then \
  317. echo $(ASGCC); \
  318. else echo "as" ; \
  319. fi\
  320. fi)
  321. LDTYPE=$(shell if $(LDPATH) -V 1>/dev/null 2>/dev/null; then \
  322. if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
  323. then echo gnu; \
  324. else \
  325. if $(LDPATH) -V 2>&1|grep Solaris >/dev/null;\
  326. then echo solaris; \
  327. else \
  328. echo unknown ; \
  329. fi \
  330. fi \
  331. fi)
  332. ASTYPE=$(shell if $(ASPATH) -V 1>/dev/null 2>/dev/null </dev/null; \
  333. then \
  334. if $(ASPATH) -V 2>&1 </dev/null |grep GNU >/dev/null; \
  335. then echo gnu; \
  336. else \
  337. if $(ASPATH) -V 2>&1 </dev/null |grep Sun >/dev/null;\
  338. then echo solaris; \
  339. else \
  340. echo unknown ; \
  341. fi \
  342. fi \
  343. fi)
  344. #$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
  345. endif
  346. endif
  347. # arh. specific definitions
  348. ifeq ($(ARCH), i386)
  349. use_fast_lock=yes
  350. endif
  351. ifeq ($(ARCH), x86_64)
  352. use_fast_lock=yes
  353. endif
  354. ifeq ($(ARCH), sparc64)
  355. ifeq ($(CC_NAME), gcc)
  356. use_fast_lock=yes
  357. endif
  358. endif
  359. ifeq ($(ARCH), arm)
  360. use_fast_lock=yes
  361. endif
  362. ifeq ($(ARCH), ppc)
  363. use_fast_lock=yes
  364. endif
  365. ifeq ($(ARCH), mips)
  366. # mips1 arch. (e.g. R3000) - no hardware locking support
  367. use_fast_lock=no
  368. endif
  369. ifeq ($(ARCH), mips2)
  370. # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
  371. use_fast_lock=yes
  372. endif
  373. ifeq ($(use_fast_lock), yes)
  374. DEFS+= -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024
  375. found_lock_method=yes
  376. endif
  377. CFLAGS=
  378. LDFLAGS=
  379. # setting CFLAGS
  380. ifeq ($(mode), release)
  381. #if i386
  382. ifeq ($(ARCH), i386)
  383. # if gcc
  384. ifeq ($(CC_NAME), gcc)
  385. #common stuff
  386. CFLAGS=-g -O9 -funroll-loops -Wcast-align $(PROFILE) \
  387. -Wall \
  388. #if gcc 3.0
  389. ifeq ($(CC_SHORTVER), 3.0)
  390. CPU ?= athlon
  391. CFLAGS+=-minline-all-stringops -malign-double \
  392. -falign-loops \
  393. -mcpu=$(CPU) \
  394. #-mcpu=athlon
  395. else
  396. ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
  397. $(warning Old gcc detected ($(CC_SHORTVER)), use gcc >= 3.1 \
  398. for better results)
  399. CFLAGS+=-m486 \
  400. -malign-loops=4
  401. else
  402. #really old version
  403. $(warning You are using an old and unsupported gcc \
  404. version ($(CC_SHORTVER)), compile at your own risk!)
  405. endif # CC_SHORTVER, 2.9x
  406. endif # CC_SHORTVER, 3.0
  407. else # CC_NAME, gcc
  408. ifeq ($(CC_NAME), icc)
  409. CFLAGS=-g -O3 -ipo -ipo_obj -unroll $(PROFILE) \
  410. -tpp6 -xK #-openmp #optimize for PIII
  411. # -prefetch doesn't seem to work
  412. #( ty to inline acroos files, unroll loops,prefetch,
  413. # optimize for PIII, use PIII instructions & vect.,
  414. # mutlithread loops)
  415. else
  416. #other compilers
  417. $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
  418. endif #CC_NAME, icc
  419. endif #CC_NAME, gcc
  420. endif #ARCH, i386
  421. #x86_64
  422. ifeq ($(ARCH), x86_64)
  423. # if gcc
  424. ifeq ($(CC_NAME), gcc)
  425. #common stuff
  426. CFLAGS=-g -O9 -funroll-loops -Wcast-align $(PROFILE) \
  427. -Wall \
  428. #if gcc 3.0
  429. ifeq ($(CC_SHORTVER), 3.0)
  430. CPU ?= athlon64
  431. CFLAGS+=-minline-all-stringops \
  432. -falign-loops \
  433. #-mcpu=$(CPU) \ # not working on all x86_64 gccs
  434. #-mcpu=athlon
  435. else
  436. ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
  437. $(warning Old gcc detected ($(CC_SHORTVER)), use gcc >= 3.1 \
  438. for better results)
  439. CFLAGS+=-m486 \
  440. -malign-loops=4
  441. else
  442. #really old version
  443. $(warning You are using an old and unsupported gcc \
  444. version ($(CC_SHORTVER)), compile at your own risk!)
  445. endif # CC_SHORTVER, 2.9x
  446. endif # CC_SHORTVER, 3.0
  447. else # CC_NAME, gcc
  448. ifeq ($(CC_NAME), icc)
  449. CFLAGS=-g -O3 -ipo -ipo_obj -unroll $(PROFILE) \
  450. -tpp6 -xK #-openmp #optimize for PIII
  451. # -prefetch doesn't seem to work
  452. #( ty to inline acroos files, unroll loops,prefetch,
  453. # optimize for PIII, use PIII instructions & vect.,
  454. # mutlithread loops)
  455. else
  456. #other compilers
  457. $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
  458. endif #CC_NAME, icc
  459. endif #CC_NAME, gcc
  460. endif #ARCH, x86_64
  461. #if sparc
  462. ifeq ($(ARCH), sparc64)
  463. #if gcc
  464. ifeq ($(CC_NAME), gcc)
  465. #common stuff
  466. CFLAGS=-g -O9 -funroll-loops $(PROFILE) \
  467. -Wall\
  468. #-Wcast-align \
  469. #-Wmissing-prototypes
  470. #if gcc 3.0
  471. ifeq ($(CC_SHORTVER), 3.0)
  472. CPU ?= ultrasparc
  473. #use 32bit for now
  474. CFLAGS+= -mcpu=ultrasparc -mtune=$(CPU) \
  475. # use -m64 to force 64 bit (but add it also to LDFLAGS),
  476. # -m32 for 32 bit (default on solaris),
  477. # nothing for arch. default
  478. # -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
  479. #-mno-epilogue #try to inline function exit code
  480. #-mflat # omit save/restore
  481. #-,faster-structs #faster non Sparc ABI structure copy ops
  482. else # CC_SHORTVER, 3.0
  483. ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
  484. $(warning Old gcc detected ($(CC_SHORTVER)), use gcc >= 3.1 \
  485. for better results)
  486. ifneq ($(OS), netbsd)
  487. # on netbsd/sparc64, gcc 2.95.3 does not compile
  488. # ser with -mv8
  489. CFLAGS+= -mv8
  490. endif
  491. ifeq ($(ASTYPE), solaris)
  492. CFLAGS+= -Wa,-xarch=v8plus
  493. endif
  494. else #CC_SHORTVER, 2.9x
  495. #really old version
  496. $(warning You are using an old and unsupported gcc \
  497. version ($(CC_SHORTVER)), compile at your own risk!)
  498. CFLAGS+= -mv8
  499. ifeq ($(ASTYPE), solaris)
  500. CFLAGS+= -Wa,-xarch=v8plus
  501. endif
  502. endif #CC_SHORTVER, 2.9x
  503. endif #CC_SHORTVER, 3.0
  504. else #CC_NAME, gcc
  505. ifeq ($(CC_NAME), suncc)
  506. CFLAGS+=-g -xO5 -fast -native -xarch=v8plusa -xCC \
  507. -xc99 # C99 support
  508. # -Dinline="" # add this if cc < 5.3 (define inline as null)
  509. else
  510. #other compilers
  511. $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
  512. endif #CC_NAME, suncc
  513. endif #CC_NAME, gcc
  514. endif #ARCH, sparc
  515. #if ipaq/netwinder
  516. ifeq ($(ARCH), arm)
  517. # if gcc
  518. ifeq ($(CC_NAME), gcc)
  519. #common stuff
  520. CFLAGS=-O9 -funroll-loops -Wcast-align $(PROFILE) \
  521. -Wall \
  522. #if gcc 3.0
  523. ifeq ($(CC_SHORTVER), 3.0)
  524. CFLAGS+= -mcpu=strongarm1100
  525. #-mcpu=athlon
  526. else
  527. ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
  528. $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
  529. for better results)
  530. CFLAGS+=
  531. else
  532. #really old version
  533. $(warning You are using an old and unsupported gcc \
  534. version ($(CC_SHORTVER)), compile at your own risk!)
  535. endif # CC_SHORTVER, 2.9x
  536. endif # CC_SHORTVER, 3.0
  537. else # CC_NAME, gcc
  538. #other compilers
  539. $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
  540. endif #CC_NAME, gcc
  541. endif #ARCH, arm
  542. #if mips (R3000)
  543. ifeq ($(ARCH), mips)
  544. # if gcc
  545. ifeq ($(CC_NAME), gcc)
  546. #common stuff
  547. CFLAGS=-O9 -funroll-loops -Wcast-align $(PROFILE) \
  548. -Wall \
  549. #if gcc 3.0
  550. ifeq ($(CC_SHORTVER), 3.0)
  551. CFLAGS+= -mcpu=r3000
  552. #-mcpu=athlon
  553. else
  554. ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
  555. $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
  556. for better results)
  557. CFLAGS+=-mcpu=r3000
  558. else
  559. #really old version
  560. $(warning You are using an old and unsupported gcc \
  561. version ($(CC_SHORTVER)), compile at your own risk!)
  562. endif # CC_SHORTVER, 2.9x
  563. endif # CC_SHORTVER, 3.0
  564. else # CC_NAME, gcc
  565. #other compilers
  566. $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
  567. endif #CC_NAME, gcc
  568. endif #ARCH, mips
  569. #if >=mips2 (R4000, R5000, R6000 ....)
  570. ifeq ($(ARCH), mips2)
  571. # if gcc
  572. ifeq ($(CC_NAME), gcc)
  573. #common stuff
  574. CFLAGS= -mips2 -O9 -funroll-loops $(PROFILE) \
  575. -Wall \
  576. #if gcc 3.0
  577. ifeq ($(CC_SHORTVER), 3.0)
  578. CFLAGS+=
  579. else
  580. ifeq ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
  581. $(warning Old gcc detected ($(CC_SHORTVER)), use gcc 3.0.x \
  582. for better results)
  583. CFLAGS+=
  584. else
  585. #really old version
  586. $(warning You are using an old and unsupported gcc \
  587. version ($(CC_SHORTVER)), compile at your own risk!)
  588. endif # CC_SHORTVER, 2.9x
  589. endif # CC_SHORTVER, 3.0
  590. else # CC_NAME, gcc
  591. #other compilers
  592. $(error Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
  593. endif #CC_NAME, gcc
  594. endif #ARCH, mips2
  595. CFLAGS+= $(CC_EXTRA_OPTS)
  596. # setting LDFLAGS
  597. ifeq ($(CC_NAME), gcc)
  598. ifeq ($(ARCH), sparc64)
  599. ifeq ($(LDTYPE), solaris)
  600. # solaris ld
  601. LDFLAGS+=-O2 $(PROFILE)
  602. MOD_LDFLAGS=-G $(LDFLAGS)
  603. else
  604. #gcc and maybe others, on solaris, with gnu ld
  605. LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE)
  606. MOD_LDFLAGS=-shared $(LDFLAGS)
  607. endif
  608. else
  609. #gcc and maybe others
  610. LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE)
  611. MOD_LDFLAGS=-shared $(LDFLAGS)
  612. endif
  613. endif
  614. ifeq ($(CC_NAME), icc)
  615. #gcc and maybe others
  616. LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE)
  617. MOD_LDFLAGS=-shared $(LDFLAGS)
  618. endif
  619. ifeq ($(CC_NAME), suncc)
  620. LDFLAGS+=-xO5 $(PROFILE)
  621. MOD_LDFLAGS=-G $(LDFLAGS)
  622. endif
  623. # we need -fPIC -DPIC only for shared objects, we don't need them for
  624. # the executable file, because it's always loaded at a fixed address
  625. # -andrei
  626. else #mode,release
  627. ifeq ($(CC_NAME), gcc)
  628. CFLAGS=-g -Wcast-align $(PROFILE)
  629. ifeq ($(ARCH), sparc64)
  630. CFLAGS+= -mcpu=ultrasparc
  631. endif
  632. ifeq ($(LDTYPE), solaris)
  633. #solaris ld
  634. LDFLAGS+=-g $(PROFILE)
  635. MOD_LDFLAGS=-G $(LDFLAGS)
  636. else
  637. #gnu or other ld type
  638. LDFLAGS+=-g -Wl,-E $(PROFILE)
  639. MOD_LDFLAGS=-shared $(LDFLAGS)
  640. endif
  641. endif
  642. ifeq ($(CC_NAME), icc)
  643. CFLAGS=-g $(PROFILE)
  644. LDFLAGS+=-g -Wl,-E $(PROFILE)
  645. MOD_LDFLAGS=-shared $(LDFLAGS)
  646. endif
  647. ifeq ($(CC_NAME), suncc)
  648. CFLAGS= -g $(PROFILE)
  649. LDFLAGS+=-g $(PROFILE)
  650. MOD_LDFLAGS=-G $(LDFLAGS)
  651. endif
  652. endif #mode=release
  653. #*FLAGS used for compiling the modules
  654. ifeq ($(CC_NAME), gcc)
  655. MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
  656. endif
  657. ifeq ($(CC_NAME), icc)
  658. MOD_CFLAGS=-Kpic $(CFLAGS)
  659. endif
  660. ifeq ($(CC_NAME), suncc)
  661. MOD_CFLAGS=-xcode=pic32 $(CFLAGS)
  662. endif
  663. ifeq ($(LEX),)
  664. LEX=flex
  665. endif
  666. ifeq ($(YACC),)
  667. YACC=bison
  668. endif
  669. YACC_FLAGS=-d -b cfg
  670. # on solaris add -lxnet (e.g. LIBS= -lxnet)
  671. LIBS= -lfl -ldl -lresolv
  672. #os specific stuff
  673. ifeq ($(OS), linux)
  674. DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
  675. -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL
  676. ifneq ($(found_lock_method), yes)
  677. DEFS+= -DUSE_SYSV_SEM # try posix sems
  678. found_lock_method=yes
  679. endif
  680. endif
  681. ifeq ($(OS), solaris)
  682. DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD
  683. ifneq ($(found_lock_method), yes)
  684. DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
  685. found_lock_method=yes
  686. endif
  687. ifeq ($(mode), release)
  688. #use these only if you're using gcc with Solaris ld
  689. #LDFLAGS=-O2 $(PROFILE)
  690. #MOD_LDFLAGS=-O2 -G
  691. else
  692. #LDFLAGS=-g $(PROFILE)
  693. #MOD_LDFLAGS=-g -G
  694. endif
  695. ifneq ($(TLS),)
  696. DEFS+= -I/usr/local/ssl/include
  697. endif
  698. YACC=yacc
  699. ifeq ($(CC_NAME), suncc)
  700. LIBS= -lfast -ldl -lresolv
  701. endif
  702. LIBS+= -L/usr/local/lib -lfl -lxnet -lrt -lnsl
  703. # -lrt needed for sched_yield
  704. endif
  705. ifeq ($(OS), freebsd)
  706. DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
  707. -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL
  708. ifneq ($(found_lock_method), yes)
  709. DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
  710. found_lock_method=yes
  711. LIBS= -pthread -lfl #dlopen is in libc
  712. else
  713. LIBS= -lfl #dlopen is in libc
  714. endif
  715. YACC=yacc
  716. endif
  717. ifeq ($(OS), openbsd)
  718. DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
  719. -DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL
  720. ifneq ($(found_lock_method), yes)
  721. DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
  722. found_lock_method=yes
  723. endif
  724. # (symbols on openbsd are prefixed by "_")
  725. YACC=yacc
  726. # no sched_yield on openbsd unless linking with c_r (not recommended)
  727. LIBS= -lfl
  728. OPENBSD_IS_AOUT= $(shell echo "$(OSREL)" | \
  729. sed -e 's/^3\.[0-3][^0-9]*$$/yes/' |sed -e 's/^[0-2]\..*/yes/')
  730. ifeq ($(OPENBSD_IS_AOUT), yes)
  731. DEFS+=-DDLSYM_PREFIX='"_"'
  732. LDFLAGS= # openbsd ld doesn't like -O2 or -E
  733. endif
  734. endif # if opensd
  735. ifeq ($(OS), netbsd)
  736. DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
  737. -DHAVE_MSGHDR_MSG_CONTROL
  738. ifneq ($(found_lock_method), yes)
  739. DEFS+= -DUSE_SYSV_SEM # try pthread sems
  740. found_lock_method=yes
  741. endif
  742. YACC=yacc
  743. LIBS= -lfl
  744. endif
  745. # OS X support, same as freebsd
  746. ifeq ($(OS), darwin)
  747. DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
  748. -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
  749. -DUSE_ANON_MMAP \
  750. -DNDEBUG
  751. # -DNDEBUG used to turn off assert (assert wants to call
  752. # eprintf which doesn't seem to be defined in any shared lib
  753. ifneq ($(found_lock_method), yes)
  754. DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
  755. found_lock_method=yes
  756. LIBS= -pthread -lfl -lresolv #dlopen is in libc
  757. else
  758. LIBS= -lfl -lresolv #dlopen is in libc
  759. endif
  760. LDFLAGS= # darwin doesn't like -O2 or -E
  761. MOD_LDFLAGS= -bundle -bundle_loader ../../$(MAIN_NAME)
  762. YACC=yacc
  763. endif
  764. ifneq (,$(findstring CYGWIN, $(OS)))
  765. #cygwin is the same as common
  766. ifneq ($(found_lock_method), yes)
  767. DEFS+= -DUSE_SYSV_SEM # try sys v sems
  768. found_lock_method=yes
  769. endif
  770. endif
  771. #add libssl if needed
  772. ifneq ($(TLS),)
  773. LIBS+= -L/usr/local/lib -L/usr/local/ssl/lib -lssl -lcrypto
  774. endif
  775. ifneq ($(found_lock_method), yes)
  776. $(warning No locking method found so far, trying SYS V sems)
  777. DEFS+= -DUSE_SYSV_SEM # try sys v sems
  778. found_lock_method=yes
  779. endif
  780. endif # ifeq ($(makefile_defs, 1)