File: configure

package info (click to toggle)
mtpaint 3.40-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 5,092 kB
  • ctags: 4,451
  • sloc: ansic: 41,804; sh: 1,414; makefile: 77
file content (754 lines) | stat: -rwxr-xr-x 19,445 bytes parent folder | download | duplicates (3)
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
#!/bin/sh
# Mini configure script
# 26-01-2011

echo

MT_V="3.40"
MT_DATE="2011-12-30"

MT_VERSION="mtPaint $MT_V"
MT_LANG=YES
MT_MAN=YES
MT_POD=NO
MT_CPICK=mtpaint
MT_FPICK=mtpaint
MT_ANIM=Gifsicle
ICON_SET=icons1

GTK_FILE=_conf.txt
HELP=1

OS=
MARCH=
OPTS=YES
USE_THREADS=YES
AS_NEEDED=
DEFS=

# Path overrides
MT_BINDIR=
MT_DATAROOT=
MT_DOCDIR=
MT_LOCDIR=
MT_MANDIR=
MT_PO=
MT_HOST=

# Initialize library-tracking vars
STATICLIBS=
for A in PNG GIF JPEG JP2 TIFF FT CMS
do
	eval "N$A="
	eval "STATIC_$A="
	STATICLIBS="$STATICLIBS \$STATIC_$A"
done
GTK=
GTK2VERSION=

# Prevent nasty surprises from locale
unset LC_ALL
export LC_COLLATE=C # LC_CTYPE=C LC_NUMERIC=C

for A in "$@"
do
	case "$A" in
	"staticpng" )	STATIC_PNG=PNG;;
	"GIF" )		NGIF=GIF;;
	"gif" )		NGIF=YES;;
	"nogif" )	NGIF=NO;;
	"staticgif" )	STATIC_GIF=GIF;;
	"jpeg" )	NJPEG=YES;;
	"nojpeg" )	NJPEG=NO;;
	"staticjpeg" )	STATIC_JPEG=JPEG;;
	"jp2" )		NJP2=OpenJPEG;;
	"jasper" )	NJP2=JasPer;;
	"nojp2" )	NJP2=NO;;
	"staticjp2" )	STATIC_JP2=JPEG2000;;
	"tiff" )	NTIFF=YES;;
	"notiff" )	NTIFF=NO;;
	"statictiff" )	STATIC_TIFF=TIFF;;
	"noft" )	NFT=NO;;
	"staticft" )	STATIC_FT=FreeType;;
	"lcms" )	NCMS=LittleCMS;;
	"lcms2" )	NCMS=LittleCMS2;;
	"nolcms" )	NCMS=NO;;
	"staticlcms" )	STATIC_CMS=LittleCMS;;
	"gtk1" )	GTK=1;;
	"gtk2"* )	GTK=2
			# Override minor version of installed GTK+2
			GTK2VERSION="`echo "$A" | sed -e 's/gtk2\.\?\([0-9]*\).*/\1/'`";;
	"intl" )	MT_LANG=YES;;
	"man" )		MT_MAN=YES;;
	"pod" )		MT_POD=YES;;
	"gtkfilesel" )	MT_FPICK=gtkfilesel;;
	"gtkcolsel" )	MT_CPICK=gtkcolsel;;
	"imagick" )	MT_ANIM=ImageMagick;;
	"icons"* )	ICON_SET=$A;;
	"win" )		OS="MinGW/MSYS"
			GTK=2;;
	"cflags" )	OPTS=CFLAGS;;
	"386" )		MARCH='-march=i386';;
	"486" )		MARCH='-march=i486';;
	"586" )		MARCH='-march=i586';;
	"686" )		MARCH='-march=i686';;
	"--cpu="* )	MARCH="-march=${A#*=}";;
	"slow" )	OPTS=NO;;
	"debug" )	OPTS=DEBUG;;
	"release" )	OPTS=RELEASE;;
	"thread" )	USE_THREADS=YES;;
	"nothread" )	USE_THREADS=NO;;
	"asneeded" )	AS_NEEDED=-Wl,--as-needed;;
	"--help" )	HELP=0;;
	"--prefix="* )	MT_PREFIX="${A#*=}";;
	"--bindir="* )	MT_BINDIR="${A#*=}";;
	"--datarootdir="* )	MT_DATAROOT="${A#*=}";;
	"--docdir="* )	MT_DOCDIR="${A#*=}";;
	"--localedir="* )	MT_LOCDIR="${A#*=}";;
	"--mandir="* )	MT_MANDIR="${A#*=}";;
	"--host="* )	MT_HOST="${A#*=}";;
	"--fakeroot="* ) FAKE_ROOT="${A#*=}";;
	"flush" )	echo Clearing out directory to original state
			echo
			make clean
			echo
			rm $GTK_FILE
			rm po/mtpaint.pot
			rm -rf src/graphics
			exit;;
	"merge" )	xgettext src/*.c src/*.h --keyword=_ -o po/mtpaint.pot
			cd po
			NEW_DIR=trans_
			mkdir $NEW_DIR`date +%d-%m-%Y-%H-%M-%S`
			for file in *.po
			do
				echo New file = $file-a
				mv "$file" "$file-a"
				msgmerge -N "$file-a" mtpaint.pot > "$file"
				mv "$file-a" $NEW_DIR*
			done
			rm mtpaint.pot
			mv $NEW_DIR* ../../old_trans
			exit;;
	"newpo" )	xgettext src/*.c src/*.h --keyword=_ -o po/mtpaint.pot
			exit;;
	# Override variable
	[!=]*=* )	MT_VAR=${A%%=*}
			if [ "$MT_VAR" != "${MT_VAR#*[!A-Za-z0-9_]}" ]
			then
				echo "Invalid variable: '$MT_VAR'"
			else
				eval $MT_VAR=\${A#*=}
				export $MT_VAR
			fi;;
	esac
done

if [ "$HELP" = 0 ]
then

cat << 'EOF' ; exit
Usage: ./configure [OPTION] ... [VAR=VALUE] ...

Options:

win .............. Configure for Windows MinGW / MSYS
gtk1 ............. Configure for GTK+1
gtk2 ............. Configure for GTK+2
gtk2.VER ......... Configure for GTK+2, minor version VER
gtkfilesel ....... Use GtkFileSelection file picker
gtkcolsel ........ Use GtkColorSelection colour picker
imagick .......... Use ImageMagick for GIF animation tasks

thread ........... Use multithreading
nothread ......... Don't use multithreading

cflags ........... Use CFLAGS environment variable
--cpu= ........... Target a specific CPU, e.g. athlon-xp, x86-64
686 .............. Target 686 machines
586 .............. Target 586 machines
486 .............. Target 486 machines
386 .............. Target 386 machines
slow ............. Don't use compiler optimizations
asneeded ......... Use linker optimization --as-needed
release .......... Use the set of optimizations which work best for mtPaint code
debug ............ Include debugging info in binary
--host= .......... Cross-compile with a specific toolchain, e.g. i586-mingw32

staticpng ........ Statically link PNG library
GIF .............. Use libgif
gif .............. Use libungif
nogif ............ Don't use libgif and libungif
staticgif ........ Statically link GIF library
jpeg ............. Use libjpeg
nojpeg ........... Don't use libjpeg
staticjpeg ....... Statically link JPEG library
jp2 .............. Use libopenjpeg
jasper............ Use libjasper
nojp2 ............ Don't use libopenjpeg and libjasper
staticjp2 ........ Statically link JPEG 2000 library
tiff ............. Use libtiff
notiff ........... Don't use libtiff
statictiff ....... Statically link TIFF library
noft ............. Don't use FreeType
staticft ......... Statically link FreeType library
lcms ............. Use LittleCMS
lcms2............. Use LittleCMS2
nolcms ........... Don't use LittleCMS
staticlcms ....... Statically link LittleCMS library

intl ............. Use internationalized po files
man .............. Install the mtPaint man page

--fakeroot=DIR ... DIR = location of library and include files to use for cross-compilation
icons ............ Compile with alternative icon set - see ./src/icons1/README for details

--prefix=DIR ..... DIR = prefix location of all installs, e.g. /usr or /usr/local (default)
--bindir=DIR ..... DIR = location of bin file to install, ${prefix}/bin by default
--docdir=DIR ..... DIR = location of documentation to install, ${prefix}/share/doc/mtpaint by default
--localedir=DIR .. DIR = location of locale files to install, ${prefix}/share/locale by default
--mandir=DIR ..... DIR = location of man page to install, ${prefix}/share/man/man1 by default

flush ............ Flush directories to initial state
newpo ............ Create ./po/mtpaint.pot
merge ............ Update all po files with new strings - developers only

Environment variables:

CC ............... C compiler (defaults to gcc)
CFLAGS ........... C compiler flags (not recommended; for enabling better optimizations use 'release' option instead)
LDFLAGS .......... linker flags, e.g. -L<libdir>
CPPFLAGS ......... C preprocessor flags, e.g. -I<includedir>
CCLD ............. "test link" command (defaults to $CC -nostartfiles)


Default settings: GNU/Linux system, O2 optimizations, English only version,
mtpaint file picker, mtpaint colour picker.
pkg-config gtk+-2.0 is checked to determine GTK+2 availability in GNU/Linux

EOF

fi

### Detect the OS

if [ -n "$OS" ] ; then
	: # Do nothing
elif [ "$OSTYPE" = "msys" ] ; then
	OS="MinGW/MSYS"
elif [ -z "$MT_HOST" ] ; then
	OS="GNU/Linux"
elif [ "$MT_HOST" != "${MT_HOST%mingw32*}" ] ; then
	OS="MinGW/GNU/Linux"
else
	OS="Other/GNU/Linux"
fi

### Prepare to use selected icon set

mkdir -p src/graphics
cp src/$ICON_SET/*.xpm src/$ICON_SET/*.xbm src/graphics

### Choose which sub-makefiles to run

MAKE_DIRS=src
[ "$MT_LANG" = YES ] && MAKE_DIRS="$MAKE_DIRS po" # translations
[ "$MT_MAN" = YES ] && MAKE_DIRS="$MAKE_DIRS doc" # man page

### Setup directories

if [ "$OS" != "${OS#MinGW/}" ]
then
	EXEEXT=".exe"
	MT_PREFIX="${MT_PREFIX-/c/Program Files/mtPaint}"
else
	MT_PREFIX="${MT_PREFIX-/usr/local}"
fi
MT_BINDIR="${MT_BINDIR:-$MT_PREFIX/bin}"
MT_DATAROOT="${MT_DATAROOT:-$MT_PREFIX/share}"
MT_DOCDIR="${MT_DOCDIR:-$MT_DATAROOT/doc/mtpaint}"
MT_MANDIR="${MT_MANDIR:-$MT_DATAROOT/man}"
if [ "$OS" != "${OS#MinGW/}" ]
then
	MT_LOCDIR="${MT_LOCDIR:-$MT_BINDIR/locale}"
	# Want package-relative path on Windows
	MT_PKGDIR=${MT_BINDIR%/bin}
	[ "$MT_PKGDIR" = "$MT_BINDIR" ] && MT_PKGDIR=${MT_BINDIR%/lib}
	MT_PKGDIR="$MT_PKGDIR/"
	MT_PO="/"
	while [ "$MT_LOCDIR" = "${MT_LOCDIR#$MT_PKGDIR}" ]
	do
		MT_PO="/..$MT_PO"
		if [ "$MT_PKGDIR" = "${MT_PKGDIR%/[!/]*/}" ]
		then # Cannot relativize path - leave it be
			MT_PO=
			break
		fi
		MT_PKGDIR="${MT_PKGDIR%/[!/]*/}/"
	done
	MT_PO="$MT_PO${MT_LOCDIR#$MT_PKGDIR}"
else
	MT_LOCDIR="${MT_LOCDIR:-$MT_DATAROOT/locale}"
	MT_PO="$MT_LOCDIR"
fi

### Set feature flags

[ "$USE_THREADS" = "YES" ] && DEFS="$DEFS -DU_THREADS"
if [ "$MT_FPICK" = mtpaint ]
then
	DEFS="$DEFS -DU_FPICK_MTPAINT"
else # "$MT_FPICK" = gtkfilesel
	DEFS="$DEFS -DU_FPICK_GTKFILESEL"
fi
if [ "$MT_CPICK" = mtpaint ]
then
	DEFS="$DEFS -DU_CPICK_MTPAINT"
else #	"$MT_CPICK" = gtkcolsel
	DEFS="$DEFS -DU_CPICK_GTK"
fi
[ "$MT_ANIM" = ImageMagick ] && DEFS="$DEFS -DU_ANIM_IMAGICK"
# mtPaint version
DEFS="$DEFS -DMT_VERSION='\"$MT_VERSION\"'"

### Setup compiler (only GCC is really supported at this time)

INCLUDES=
LIBS=
if [ "$OS" != "${OS%GNU/Linux}" ]
then
	CC=${CC:-`which ${MT_HOST:+$MT_HOST-}gcc`}
	PKG_CONFIG=${PKG_CONFIG:-${MT_HOST:+$MT_HOST-}pkg-config}
fi
CC=${CC:-gcc}
# Use compiler as linker in tests - this way, both accept "-Wl," in LDFLAGS
CCLD=${CCLD:-$CC -nostartfiles}
# Get GCC version
GCCVER=`$CC -dumpversion`
# Get target architecture
GCCARCH=`$CC -dumpmachine`
# For eternally misconfigured, Windows-hosted MinGW
[ "$GCCARCH" != "${GCCARCH#mingw32}" ] && GCCARCH=i586-mingw32
# For any properly built toolchain
ARCH=${ARCH:-${GCCARCH%%-*}}

if [ -n "$FAKE_ROOT" ] # A way to replace just some libraries, leaving others be
then
	PKGCONFIG () # Check both locations in turn
	{
		PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR="$FAKE_ROOT/lib/pkgconfig" \
			pkg-config --define-variable=prefix="$FAKE_ROOT" "$@" \
			2> /dev/null || "$PKG_CONFIG" "$@"
	}
	MT_TESTLINK="$CCLD -L$FAKE_ROOT/lib -Wl,--unresolved-symbols=ignore-in-shared-libs $LDFLAGS"
	MT_TESTCOMP="$CC -fno-builtin -isystem $FAKE_ROOT/include $CPPFLAGS ${MT_TESTLINK#$CCLD}"
else
	PKGCONFIG ()
	{
		"$PKG_CONFIG" "$@"
	}
	MT_TESTLINK="$CCLD $LDFLAGS"
	MT_TESTCOMP="$CC -fno-builtin $CPPFLAGS $LDFLAGS"
fi

if [ "$OS" != "${OS%/MSYS}" ]
then
	MT_TESTLINK="redir -e /dev/null $MT_TESTLINK -L/lib"
	MT_TESTCOMP="redir -e /dev/null $MT_TESTCOMP -L/lib"
	INCLUDES="-I/include"
	LIBS="-L/lib"
fi
IS_LIB()
{
	$MT_TESTLINK -$1 -o _conf.tmp > /dev/null 2>&1
}
HAVE_FUNC()
{
	echo "main() { $1(); }" > _conf.c
	$MT_TESTCOMP _conf.c -o _conf.tmp > /dev/null 2>&1
}

HAVE_GCC_VER()
{
	# First 2 parts of GCC version
	MT_VN0=${GCCVER%%.*}
	MT_VN1=${GCCVER#$MT_VN0}
	MT_VN0=${MT_VN0%%[!0-9]*}
	MT_VN1=${MT_VN1#.}
	MT_VN1=${MT_VN1%%[!0-9]*}

	# Compare them to given version
	[ ${1%%.*} -eq "$MT_VN0" ] && [ ${1#*.} -le "$MT_VN1" ] || \
		[ ${1%%.*} -lt "$MT_VN0" ]
}

### Detect libraries and functions

if HAVE_FUNC "mkdtemp"
then
	DEFS="$DEFS -DHAVE_MKDTEMP"
fi

if IS_LIB "lgif"
then
	NGIF=${NGIF:-GIF}
fi
if IS_LIB "lungif"
then
	NGIF=${NGIF:-YES}
fi
NGIF=${NGIF:-NO}

if IS_LIB "ljpeg"
then
	NJPEG=${NJPEG:-YES}
fi
NJPEG=${NJPEG:-NO}

if IS_LIB "lopenjpeg"
then
	NJP2=${NJP2:-OpenJPEG}
fi
if IS_LIB "ljasper"
then
	NJP2=${NJP2:-JasPer}
fi
NJP2=${NJP2:-NO}

if IS_LIB "ltiff"
then
	NTIFF=${NTIFF:-YES}
fi
NTIFF=${NTIFF:-NO}

if IS_LIB "lfreetype"
then
	NFT=${NFT:-YES}
fi
NFT=${NFT:-NO}

if IS_LIB "llcms2"
then
	NCMS=${NCMS:-LittleCMS2}
fi
if IS_LIB "llcms"
then
	NCMS=${NCMS:-LittleCMS}
fi
NCMS=${NCMS:-NO}

### Setup optimizations

if [ "$OPTS" = RELEASE ]
then
	# Target i386 when compiling for any x86 CPU;
	# this produces smallest *AND* fastest binary
	case $ARCH in
		i?86) CFLAGS="-O2 ${MARCH:--march=i386}";;
		*) CFLAGS="-O2 $MARCH";;
	esac
	# Add optimizations which are proven to really make mtPaint code faster
	if HAVE_GCC_VER 4.0
	then # GCC 4.x
		CFLAGS="$CFLAGS -fweb -fomit-frame-pointer -fmodulo-sched"
	else # GCC 3.x
		CFLAGS="$CFLAGS -fweb"
	fi
	# Do not add unneeded dependencies
	AS_NEEDED="-Wl,--as-needed"
	# Disable GTK+ debug code
	DEFS="$DEFS -DGTK_NO_CHECK_CASTS -DG_DISABLE_CAST_CHECKS"
elif [ "$OPTS" = DEBUG ]
then
	CFLAGS="-ggdb"
elif [ "$OPTS" = YES ]
then
	CFLAGS="-O2 $MARCH"
elif [ "$OPTS" = NO ]
then
	CFLAGS="$MARCH"
else # $OPTS = CFLAGS
	MARCH=
	# And leave CFLAGS alone
fi
[ "$OPTS" != DEBUG ] && LDFLAGS="-s $LDFLAGS" # Strip debug info
# Set Windows-specific flags
if [ "$OS" != "${OS#MinGW/}" ]
then
	CFLAGS="-mms-bitfields $CFLAGS"
	LDFLAGS="-mwindows $LDFLAGS"
fi
# Enable warnings
if HAVE_GCC_VER 4.0
then # Tell gcc 4.x to shut up
	WARN="-Wall -Wno-pointer-sign"
else
	WARN="-Wall"
fi

### Setup libraries

MT_DLIBS=
MT_SLIBS=
LIB_NAME () # ( lib_ID , static_mode , libs )
{
	if [ "$2" ]
	then
		MT_SLIBS="$MT_SLIBS ${1:+-l$1}$3"
	else
		MT_DLIBS="$MT_DLIBS ${1:+-l$1}$3"
	fi
}

if [ "$NGIF" != NO ]
then
	if [ "$NGIF" = GIF ]
	then
		LIB_NAME gif "$STATIC_GIF"
	else
		LIB_NAME ungif "$STATIC_GIF"
	fi
	DEFS="$DEFS -DU_GIF"
fi
if [ "$NJP2" = OpenJPEG ]
then
	LIB_NAME openjpeg "$STATIC_JP2"
# !!! If <openjpeg.h> isn't found in include path, use CPPFLAGS or symlink;
# I'm not inclined to scan all the places where different packagers can put it
	DEFS="$DEFS -DU_JP2"
	if [ "$STATIC_JP2" ] || [ "$OS" != "GNU/Linux" ]
	then
		DEFS="$DEFS -DOPJ_STATIC"
	fi
fi
if [ "$NJP2" = JasPer ]
then
	LIB_NAME jasper "$STATIC_JP2"
	DEFS="$DEFS -DU_JASPER"
fi
if [ "$NTIFF" = YES ]
then
	LIB_NAME tiff "$STATIC_TIFF"
	DEFS="$DEFS -DU_TIFF"
fi
if [ "$NJPEG" = YES ]
then
	LIB_NAME jpeg "$STATIC_JPEG"
	DEFS="$DEFS -DU_JPEG"
fi
if [ "$NFT" = YES ]
then
	DEFS="$DEFS -DU_FREETYPE"
	if [ "$OS" = "GNU/Linux" ]
	then # Do it the old way, for native builds on *very* old distros
		INCLUDES="$INCLUDES `freetype-config --cflags`"
		LIB_NAME "" "$STATIC_FT" "`freetype-config --libs`"
	elif [ "$OS" != "${OS%/MSYS}" ]
	then # pkg-config may be missing on Windows - hardcode its results
		INCLUDES="$INCLUDES -I/include/freetype2"
		LIB_NAME "" "$STATIC_FT" "-lfreetype -lz"
	else # Use pkg-config
		INCLUDES="$INCLUDES `PKGCONFIG freetype2 --cflags`"
		LIB_NAME "" "$STATIC_FT" "`PKGCONFIG freetype2 --libs`"
	fi
	# libiconv may be separate, or part of libc
	HAVE_FUNC "iconv_open" || LIB_NAME iconv "$STATIC_FT"
fi
if [ "$NCMS" = LittleCMS2 ]
then
	LIB_NAME lcms2 "$STATIC_CMS"
	DEFS="$DEFS -DU_LCMS=2"
fi
if [ "$NCMS" = LittleCMS ]
then
	LIB_NAME lcms "$STATIC_CMS"
	DEFS="$DEFS -DU_LCMS"
fi
LIB_NAME png "$STATIC_PNG"
LIB_NAME z "$STATIC_PNG"
LIB_NAME m
if [ "$MT_LANG" = YES ]
then
	HAVE_FUNC "gettext" || LIB_NAME intl
	DEFS="$DEFS -DU_NLS -DMT_LANG_DEST='\"$MT_PO\"'"
fi

# !!! Would be nice to subtract MT_SLIBS from MT_DLIBS first
LIBS="$LIBS $MT_DLIBS${MT_SLIBS:+ -Wl,-dn $MT_SLIBS -Wl,-dy}"

rm -f _conf.c _conf.tmp

### Setup GTK+

FOUND_GTK=
[ "$OS" != "${OS#MinGW/}" ] && GTK=2
[ "$GTK" != 1 ] && PKGCONFIG gtk+-2.0 --cflags > /dev/null 2>&1 && FOUND_GTK=2 GTK=2
[ "$GTK" != 2 ] && PKGCONFIG gtk+ --cflags > /dev/null 2>&1 && FOUND_GTK=1 GTK=1
GTK=${GTK:-1}

if [ "$USE_THREADS" = NO ] ; then
	THREADS=
elif [ "$GTK" = 2 ] ; then
	THREADS="gthread-2.0"
else # "$GTK" = 1
	THREADS="gthread"
fi

# !!! It is assumed that the nondefault install prefix is the one GTK+ lives in
if [ "$FOUND_GTK" = 2 ]
then
	GTKPREFIX=`PKGCONFIG gtk+-2.0 --variable=prefix`
	INCLUDES="$INCLUDES `PKGCONFIG gtk+-2.0 $THREADS --cflags`"
	LIBS="$LIBS `PKGCONFIG gtk+-2.0 $THREADS --libs`"
elif [ "$FOUND_GTK" = 1 ]
then
# !!! Full equivalent to "gtk-config gtk" would be "pkg-config gtk+ gmodule",
# but for mtPaint, 'gmodule' is nothing but a nuisance anyway
	GTKPREFIX=`PKGCONFIG gtk+ --variable=prefix`
	INCLUDES="$INCLUDES `PKGCONFIG gtk+ $THREADS --cflags`"
	LIBS="$LIBS `PKGCONFIG gtk+ $THREADS --libs`"
elif [ "GTK" = 2 ] && [ "$OS" != "${OS%/MSYS}" ]
then # Windows system w/o working pkg-config
	GTKPREFIX=/
	INCLUDES="$INCLUDES -I/include/gtk-2.0 -I/lib/gtk-2.0/include -I/include/atk-1.0 -I/include/pango-1.0 -I/include/freetype2 -I/include/glib-2.0 -I/lib/glib-2.0/include"
	LIBS="$LIBS -lgtk-win32-2.0 -lgdk-win32-2.0 -lpango-1.0 -lglib-2.0 -lgobject-2.0 -lgdk_pixbuf-2.0 ${THREADS:+-lgthread-2.0}"
elif [ "GTK" = 1 ] && gtk-config --cflags > /dev/null
then # Very old GNU/Linux system
	GTKPREFIX=`gtk-config gtk --prefix`
	INCLUDES="$INCLUDES `gtk-config gtk $THREADS --cflags`"
	LIBS="$LIBS `gtk-config gtk $THREADS --libs | sed 's/-rdynamic//'`"
elif [ "GTK" = 1 ]
then # Even older GNU/Linux system
	GTKPREFIX=/opt/gnome
	GTK_INCLUDE="-I$GTKPREFIX/include/gtk-1.2 -I$GTKPREFIX/include/glib-1.2 -I$GTKPREFIX/lib/glib/include -I/usr/X11R6/include"
	GTK_LIB="-L/usr/lib -L/usr/X11R6/lib -L$GTKPREFIX/lib -lgtk -lgdk -lgmodule -lglib -ldl -lXext -lX11 -lm"
	echo
	echo I have not been able to find gtk-config so I am assuming the following:
	echo
	echo GTK_INCLUDE = $GTK_INCLUDE
	echo GTK_LIB = $GTK_LIB
	echo
	echo If these values are not right for your system, edit the configure script
	echo
	INCLUDES="$INCLUDES $GTK_INCLUDE"
	LIBS="$LIBS $GTK_LIB"
else
	echo "Failed to find required GTK+$GTK libraries" 1>&2
	exit 1
fi
# Also need to add "-lX11" on GTK+2/X systems
[ "$GTK" = 2 ] && [ "$LIBS" != "${LIBS#*gdk-x11}" ] && LIBS="$LIBS -lX11"
# GTK+2 version to use
DEFS="$DEFS${GTK2VERSION:+ -DGTK2VERSION=$GTK2VERSION}"

###

### Rebase the paths, for '--fakeroot' substitutions to work

FAKE_PATHS () # variable, key
{
	FAKE_KEYS=" "
	for A in $1
	do
		[ "$A" = "${A#$2/}" ] && continue
		for B in "$GTKPREFIX/include" "$GTKPREFIX/lib"\
			/usr/include /usr/lib /usr/local/include /usr/local/lib
		do
			[ "$A" != "${A#$2$B}" ] || continue
			C="$2$FAKE_ROOT${A#$2${B%/*}}"
			[ "$C" != "$A" ] && [ "$FAKE_KEYS" = "${FAKE_KEYS#* $C }" ] &&\
				FAKE_KEYS="$FAKE_KEYS$C "
			break
		done
	done
	echo "$FAKE_KEYS"
}
if [ "$FAKE_ROOT" ]
then
	# !!! Spaces in paths will NOT be well received here
	FAKE_PATHS "$LIBS" -L
	LIBS="-L$FAKE_ROOT/lib $FAKE_KEYS $LIBS"
	FAKE_PATHS "$INCLUDES" -I
	INCLUDES="-isystem $FAKE_ROOT/include $FAKE_KEYS $INCLUDES"
	AS_NEEDED="-Wl,--as-needed,--no-add-needed,--unresolved-symbols=ignore-in-shared-libs"
fi

### Write config

cat << CONFIG > "$GTK_FILE"
CC = $CC $WARN
EXEEXT = $EXEEXT
MT_VERSION=$MT_VERSION
MT_DATE=$MT_DATE
MT_PREFIX="$MT_PREFIX"
MT_DATAROOT="$MT_DATAROOT"
MT_LANG_DEST="$MT_LOCDIR"
MT_MAN_DEST="$MT_MANDIR"
LDFLAG = $AS_NEEDED $LIBS $LDFLAGS
CFLAG = $DEFS $INCLUDES $CPPFLAGS $CFLAGS
subdirs = $MAKE_DIRS
BIN_INSTALL="$MT_BINDIR"
CONFIG
HAVE_GCC_VER 3.3 && echo "HAVE_RANDSEED=1" >> $GTK_FILE

### Report config

eval STATICLIBS=\"$STATICLIBS\"
STATICLIBS=`echo -n "$STATICLIBS" | sed -e 's/  */ /g' -e 's/^ //'`
cat << CONFIG

---------------------
mtPaint Configuration
---------------------

-------
General
-------

    Version             $MT_V
    System              $OS
    Toolkit             GTK+$GTK${GTK2VERSION:+.$GTK2VERSION}
    File Picker         $MT_FPICK
    Colour Picker       $MT_CPICK
    Animation Package   $MT_ANIM
    Use FreeType        $NFT
    Use CMS             $NCMS
    Icon set            $ICON_SET
    Internationalized   $MT_LANG
    Multithreaded       $USE_THREADS

--------
Compiler
--------

    Optimizations       $OPTS
    CFLAGS              $CFLAGS
    LDFLAGS             ${AS_NEEDED:+$AS_NEEDED }$LDFLAGS
    Static libraries    ${STATICLIBS:-NONE}

----------
File Types
----------

    Use GIF             $NGIF
    Use JPEG            $NJPEG
    Use JPEG 2000       $NJP2
    Use TIFF            $NTIFF

------------
Installation
------------

    Binary install      $MT_BINDIR
CONFIG
[ "$MT_LANG" = YES ] && cat << CONFIG
    Locale install      $MT_LOCDIR
    Locale program      $MT_PO
CONFIG
cat << CONFIG
    Install man page    $MT_MAN
CONFIG
[ "$MT_MAN" = YES ] && cat << CONFIG
    Man page install    $MT_MANDIR
CONFIG
echo