summaryrefslogtreecommitdiff
path: root/config-scripts/cups-compiler.m4
blob: 51a5daa6f8c71b85f3600944c554c76eee82ebbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
dnl
dnl "$Id: cups-compiler.m4 6975 2007-09-18 20:37:09Z mike $"
dnl
dnl   Compiler stuff for the Common UNIX Printing System (CUPS).
dnl
dnl   Copyright 2007-2008 by Apple Inc.
dnl   Copyright 1997-2007 by Easy Software Products, all rights reserved.
dnl
dnl   These coded instructions, statements, and computer programs are the
dnl   property of Apple Inc. and are protected by Federal copyright
dnl   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
dnl   which should have been included with this file.  If this file is
dnl   file is missing or damaged, see the license at "http://www.cups.org/".
dnl

dnl Clear the debugging and non-shared library options unless the user asks
dnl for them...
INSTALL_STRIP=""
OPTIM=""
AC_SUBST(INSTALL_STRIP)
AC_SUBST(OPTIM)

AC_ARG_WITH(optim, [  --with-optim="flags"    set optimization flags ])
AC_ARG_ENABLE(debug, [  --enable-debug          turn on debugging, default=no])

dnl For debugging, keep symbols, otherwise strip them...
if test x$enable_debug = xyes; then
	OPTIM="-g"
	CFLAGS="$CFLAGS -DDEBUG"
else
	INSTALL_STRIP="-s"
fi

dnl Setup general architecture flags...
AC_ARG_WITH(archflags, [  --with-archflags="flags"
                          set default architecture flags ])
AC_ARG_WITH(ldarchflags, [  --with-ldarchflags="flags"
                          set default program architecture flags ])

if test -z "$with_archflags"; then
	ARCHFLAGS=""
else
	ARCHFLAGS="$with_archflags"
fi

if test -z "$with_ldarchflags"; then
	if test "$uname" = Darwin; then
		# Only create 32-bit programs by default
		LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch x86_64//' -e '1,$s/-arch ppc64//'`"
	else
		LDARCHFLAGS="$ARCHFLAGS"
	fi
else
	LDARCHFLAGS="$with_ldarchflags"
fi

AC_SUBST(ARCHFLAGS)
AC_SUBST(LDARCHFLAGS)

dnl Setup support for separate 32/64-bit library generation...
AC_ARG_WITH(arch32flags, [  --with-arch32flags="flags"
                          specifies 32-bit architecture flags])
ARCH32FLAGS=""
AC_SUBST(ARCH32FLAGS)

AC_ARG_WITH(arch64flags, [  --with-arch64flags="flags"
                          specifies 64-bit architecture flags])
ARCH64FLAGS=""
AC_SUBST(ARCH64FLAGS)

dnl Read-only data/program support on Linux...
AC_ARG_ENABLE(relro, [  --enable-relro          use GCC relro option, default=no])

dnl Update compiler options...
CXXLIBS="${CXXLIBS:=}"
AC_SUBST(CXXLIBS)

PIEFLAGS=""
AC_SUBST(PIEFLAGS)

RELROFLAGS=""
AC_SUBST(RELROFLAGS)

LIBCUPSORDER="libcups.order"
AC_ARG_WITH(libcupsorder, [  --with-libcupsorder     libcups secorder file, default=libcups.order],
	if test -f "$withval"; then
		LIBCUPSORDER="$withval"
	fi)
AC_SUBST(LIBCUPSORDER)

LIBCUPSIMAGEORDER="libcupsimage.order"
AC_ARG_WITH(libcupsimageorder, [  --with-libcupsimagesorder
                          libcupsimage secorder file, default=libcupsimage.order],
	if test -f "$withval"; then
		LIBCUPSIMAGEORDER="$withval"
	fi)
AC_SUBST(LIBCUPSIMAGEORDER)

PHPOPTIONS=""
AC_SUBST(PHPOPTIONS)

if test -n "$GCC"; then
	# Add GCC-specific compiler options...
	if test -z "$OPTIM"; then
		if test "x$with_optim" = x; then
			# Default to optimize-for-size and debug
       			OPTIM="-Os -g"
		else
			OPTIM="$with_optim $OPTIM"
		fi
	fi

	# Generate position-independent code as needed...
	if test $PICFLAG = 1 -a $uname != AIX; then
    		OPTIM="-fPIC $OPTIM"
	fi

	# The -fstack-protector option is available with some versions of
	# GCC and adds "stack canaries" which detect when the return address
	# has been overwritten, preventing many types of exploit attacks.
	AC_MSG_CHECKING(if GCC supports -fstack-protector)
	OLDCFLAGS="$CFLAGS"
	CFLAGS="$CFLAGS -fstack-protector"
	AC_TRY_COMPILE(,,
		OPTIM="$OPTIM -fstack-protector"
		AC_MSG_RESULT(yes),
		AC_MSG_RESULT(no))
	CFLAGS="$OLDCFLAGS"

	# The -pie option is available with some versions of GCC and adds
	# randomization of addresses, which avoids another class of exploits
	# that depend on a fixed address for common functions.
	AC_MSG_CHECKING(if GCC supports -pie)
	OLDCFLAGS="$CFLAGS"
	CFLAGS="$CFLAGS -pie -fPIE"
	AC_TRY_COMPILE(,,
		PIEFLAGS="-pie -fPIE"
		AC_MSG_RESULT(yes),
		AC_MSG_RESULT(no))
	CFLAGS="$OLDCFLAGS"

	if test "x$with_optim" = x; then
		# Add useful warning options for tracking down problems...
		OPTIM="-Wall -Wno-format-y2k $OPTIM"
		# Additional warning options for development testing...
		if test -d .svn; then
			OPTIM="-Wshadow -Wunused $OPTIM"
			PHPOPTIONS="-Wno-shadow"
		fi
	fi

	case "$uname" in
		Darwin*)
			# -D_FORTIFY_SOURCE=2 adds additional object size
			# checking, basically wrapping all string functions
			# with buffer-limited ones.  Not strictly needed for
			# CUPS since we already use buffer-limited calls, but
			# this will catch any additions that are broken.		
			CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"

			if test x$enable_pie = xyes; then
				# GCC 4 on Mac OS X needs -Wl,-pie as well
				LDFLAGS="$LDFLAGS -Wl,-pie"
			fi
			;;

		HP-UX*)
			if test "x$enable_32bit" = xyes; then
				# Build 32-bit libraries, 64-bit base...
				if test -z "$with_arch32flags"; then
					ARCH32FLAGS="-milp32"
				else
					ARCH32FLAGS="$with_arch32flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch64flags"; then
						ARCHFLAGS="-mlp64"
					else
						ARCHFLAGS="$with_arch64flags"
					fi
				fi
			fi

			if test "x$enable_64bit" = xyes; then
				# Build 64-bit libraries, 32-bit base...
				if test -z "$with_arch64flags"; then
					ARCH64FLAGS="-mlp64"
				else
					ARCH64FLAGS="$with_arch64flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch32flags"; then
						ARCHFLAGS="-milp32"
					else
						ARCHFLAGS="$with_arch32flags"
					fi
				fi
			fi
			;;

		IRIX)
			if test "x$enable_32bit" = xyes; then
				# Build 32-bit libraries, 64-bit base...
				if test -z "$with_arch32flags"; then
					ARCH32FLAGS="-n32 -mips3"
				else
					ARCH32FLAGS="$with_arch32flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch64flags"; then
						ARCHFLAGS="-64 -mips4"
					else
						ARCHFLAGS="$with_arch64flags"
					fi
				fi
			fi

			if test "x$enable_64bit" = xyes; then
				# Build 64-bit libraries, 32-bit base...
				if test -z "$with_arch64flags"; then
					ARCH64FLAGS="-64 -mips4"
				else
					ARCH64FLAGS="$with_arch64flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch32flags"; then
						ARCHFLAGS="-n32 -mips3"
					else
						ARCHFLAGS="$with_arch32flags"
					fi
				fi
			fi
			;;

		Linux*)
			# The -z relro option is provided by the Linux linker command to
			# make relocatable data read-only.
			if test x$enable_relro = xyes; then
				RELROFLAGS="-Wl,-z,relro"
			fi

			if test "x$enable_32bit" = xyes; then
				# Build 32-bit libraries, 64-bit base...
				if test -z "$with_arch32flags"; then
					ARCH32FLAGS="-m32"
				else
					ARCH32FLAGS="$with_arch32flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch64flags"; then
						ARCHFLAGS="-m64"
					else
						ARCHFLAGS="$with_arch64flags"
					fi
				fi
			fi

			if test "x$enable_64bit" = xyes; then
				# Build 64-bit libraries, 32-bit base...
				if test -z "$with_arch64flags"; then
					ARCH64FLAGS="-m64"
				else
					ARCH64FLAGS="$with_arch64flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch32flags"; then
						ARCHFLAGS="-m32"
					else
						ARCHFLAGS="$with_arch32flags"
					fi
				fi
			fi
			;;

		SunOS*)
			if test "x$enable_32bit" = xyes; then
				# Build 32-bit libraries, 64-bit base...
				if test -z "$with_arch32flags"; then
					ARCH32FLAGS="-m32"
				else
					ARCH32FLAGS="$with_arch32flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch64flags"; then
						ARCHFLAGS="-m64"
					else
						ARCHFLAGS="$with_arch64flags"
					fi
				fi
			fi

			if test "x$enable_64bit" = xyes; then
				# Build 64-bit libraries, 32-bit base...
				if test -z "$with_arch64flags"; then
					ARCH64FLAGS="-m64"
				else
					ARCH64FLAGS="$with_arch64flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch32flags"; then
						ARCHFLAGS="-m32"
					else
						ARCHFLAGS="$with_arch32flags"
					fi
				fi
			fi
			;;
	esac
else
	# Add vendor-specific compiler options...
	case $uname in
		AIX*)
			if test -z "$OPTIM"; then
				if test "x$with_optim" = x; then
					OPTIM="-O2 -qmaxmem=6000"
				else
					OPTIM="$with_optim $OPTIM"
				fi
			fi
			;;
		HP-UX*)
			if test -z "$OPTIM"; then
				if test "x$with_optim" = x; then
					OPTIM="+O2"
				else
					OPTIM="$with_optim $OPTIM"
				fi
			fi

			CFLAGS="-Ae $CFLAGS"

			if test $PICFLAG = 1; then
				OPTIM="+z $OPTIM"
			fi

			if test "x$enable_32bit" = xyes; then
				# Build 32-bit libraries, 64-bit base...
				if test -z "$with_arch32flags"; then
					ARCH32FLAGS="+DD32"
				else
					ARCH32FLAGS="$with_arch32flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch64flags"; then
						ARCHFLAGS="+DD64"
					else
						ARCHFLAGS="$with_arch64flags"
					fi
				fi
			fi

			if test "x$enable_64bit" = xyes; then
				# Build 64-bit libraries, 32-bit base...
				if test -z "$with_arch64flags"; then
					ARCH64FLAGS="+DD64"
				else
					ARCH64FLAGS="$with_arch64flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch32flags"; then
						ARCHFLAGS="+DD32"
					else
						ARCHFLAGS="$with_arch32flags"
					fi
				fi
			fi
			;;
        	IRIX)
			if test -z "$OPTIM"; then
				if test "x$with_optim" = x; then
					OPTIM="-O2"
				else
					OPTIM="$with_optim $OPTIM"
				fi
			fi

			if test "x$with_optim" = x; then
				OPTIM="-fullwarn -woff 1183,1209,1349,1506,3201 $OPTIM"
			fi

			if test "x$enable_32bit" = xyes; then
				# Build 32-bit libraries, 64-bit base...
				if test -z "$with_arch32flags"; then
					ARCH32FLAGS="-n32 -mips3"
				else
					ARCH32FLAGS="$with_arch32flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch64flags"; then
						ARCHFLAGS="-64 -mips4"
					else
						ARCHFLAGS="$with_arch64flags"
					fi
				fi
			fi

			if test "x$enable_64bit" = xyes; then
				# Build 64-bit libraries, 32-bit base...
				if test -z "$with_arch64flags"; then
					ARCH64FLAGS="-64 -mips4"
				else
					ARCH64FLAGS="$with_arch64flags"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch32flags"; then
						ARCHFLAGS="-n32 -mips3"
					else
						ARCHFLAGS="$with_arch32flags"
					fi
				fi
			fi
			;;
		OSF*)
			# Tru64 UNIX aka Digital UNIX aka OSF/1
			if test -z "$OPTIM"; then
				if test "x$with_optim" = x; then
					OPTIM="-O"
				else
					OPTIM="$with_optim"
				fi
			fi
			;;
		SunOS*)
			# Solaris
			if test -z "$OPTIM"; then
				if test "x$with_optim" = x; then
					OPTIM="-xO2"
				else
					OPTIM="$with_optim $OPTIM"
				fi
			fi

			if test $PICFLAG = 1; then
				OPTIM="-KPIC $OPTIM"
			fi

			if test "x$enable_32bit" = xyes; then
				# Compiling on a Solaris system, build 64-bit
				# binaries with separate 32-bit libraries...
				ARCH32FLAGS="-xarch=generic"

				if test "x$with_optim" = x; then
					# Suppress all of Sun's questionable
					# warning messages, and default to
					# 64-bit compiles of everything else...
					OPTIM="-w $OPTIM"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch64flags"; then
						ARCHFLAGS="-xarch=generic64"
					else
						ARCHFLAGS="$with_arch64flags"
					fi
				fi
			else
				if test "x$enable_64bit" = xyes; then
					# Build 64-bit libraries...
					ARCH64FLAGS="-xarch=generic64"
				fi

				if test "x$with_optim" = x; then
					# Suppress all of Sun's questionable
					# warning messages, and default to
					# 32-bit compiles of everything else...
					OPTIM="-w $OPTIM"
				fi

				if test -z "$with_archflags"; then
					if test -z "$with_arch32flags"; then
						ARCHFLAGS="-xarch=generic"
					else
						ARCHFLAGS="$with_arch32flags"
					fi
				fi
			fi
			;;
		UNIX_SVR*)
			# UnixWare
			if test -z "$OPTIM"; then
				if test "x$with_optim" = x; then
					OPTIM="-O"
				else
					OPTIM="$with_optim $OPTIM"
				fi
			fi

			if test $PICFLAG = 1; then
				OPTIM="-KPIC $OPTIM"
			fi
			;;
		*)
			# Running some other operating system; inform the user they
			# should contribute the necessary options to
			# cups-support@cups.org...
			echo "Building CUPS with default compiler optimizations; contact"
			echo "cups-bugs@cups.org with uname and compiler options needed"
			echo "for your platform, or set the CFLAGS and LDFLAGS environment"
			echo "variables before running configure."
			;;
	esac
fi

# Add general compiler options per platform...
case $uname in
	HP-UX*)
		# HP-UX 10.20 (at least) needs this definition to get the
		# h_errno global...
		OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED"

		# HP-UX 11.00 (at least) needs this definition to get the
		# u_short type used by the IP headers...
		OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE"

		# HP-UX 11.23 (at least) needs this definition to get the
		# IPv6 header to work...
		OPTIM="$OPTIM -D_HPUX_SOURCE"
		;;

	Linux*)
		# glibc 2.8 and higher breaks peer credentials unless you
		# define _GNU_SOURCE...
		OPTIM="$OPTIM -D_GNU_SOURCE"
		;;

	OSF*)
		# Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told
		# to be POSIX-compliant...
		OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE"
		;;
esac

dnl
dnl End of "$Id: cups-compiler.m4 6975 2007-09-18 20:37:09Z mike $".
dnl