Commit 93ebcbd0acec39ea697cd4c5af96710c990a66f6

Werner Lemberg 2014-03-03T07:13:45

Rewrite library option handling in `configure'; improve `freetype-config'. o Introduce `auto' value for `--with-XXX' library options; this is now the default. o First use `pkg-config' for library detection, then fall back to other tests. * builds/unix/configure.raw (--with-zlib, --with-bzip2, --with-png, --with-harfbuzz): Rewrite. Use new `xxx_reqpriv', `xxx_libpriv', and `xxx_libstaticconf' variables to collect data for `freetype2.pc' and `freetype-config'. (FT2_EXTRA_LIBS): Renamed to ... (ft2_extra_libs): This since it gets no longer substituted. (REQUIRES_PRIVATE, LIBS_PRIVATE, LIBS_CONFIG, LIBSSTATIC_CONFIG): New output variables, replacing `XXX_PKG' and `LIBXXX'. Add notice at the end of `configure' showing the library configuration. * builds/unix/freetype-config.in (--static): New command line option. (libs): Updated. (staticlibs): New variable, to be used if `--static' is given. * builds/doc/freetype-config.1: Document `--static'. * builds/unix/freetype2.in, builds/unix/unix-def.in: Updated.

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
diff --git a/ChangeLog b/ChangeLog
index a6554f4..bed2733 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2014-03-03  Werner Lemberg  <wl@gnu.org>
+
+	Rewrite library option handling in `configure'.
+
+	o Introduce `auto' value for `--with-XXX' library options; this is
+	  now the default.
+
+	o First use `pkg-config' for library detection, then fall back to
+	  other tests.
+
+	* builds/unix/configure.raw (--with-zlib, --with-bzip2, --with-png,
+	--with-harfbuzz): Rewrite.
+	Use new `xxx_reqpriv', `xxx_libpriv', and `xxx_libstaticconf'
+	variables to collect data for `freetype2.pc' and `freetype-config'.
+	(FT2_EXTRA_LIBS): Renamed to ...
+	(ft2_extra_libs): This since it gets no longer substituted.
+	(REQUIRES_PRIVATE, LIBS_PRIVATE, LIBS_CONFIG, LIBSSTATIC_CONFIG):
+	New output variables, replacing `XXX_PKG' and `LIBXXX'.
+	Add notice at the end of `configure' showing the library
+	configuration.
+
+	* builds/unix/freetype-config.in (--static): New command line
+	option.
+	(libs): Updated.
+	(staticlibs): New variable, to be used if `--static' is given.
+	* builds/doc/freetype-config.1: Document `--static'.
+
+	* builds/unix/freetype2.in, builds/unix/unix-def.in: Updated.
+
 2014-03-01  Werner Lemberg  <wl@gnu.org>
 
 	Avoid `long long' warnings with older gcc compilers.
diff --git a/builds/unix/configure.raw b/builds/unix/configure.raw
index b13f671..5a12520 100644
--- a/builds/unix/configure.raw
+++ b/builds/unix/configure.raw
@@ -36,6 +36,8 @@ AC_SUBST(EXEEXT)
 
 PKG_PROG_PKG_CONFIG([0.24])
 
+LT_INIT(win32-dll)
+
 
 # checks for native programs to generate building tool
 
@@ -287,96 +289,216 @@ AC_SUBST([XX_CFLAGS])
 AC_SUBST([XX_ANSIFLAGS])
 
 
+# All library tests below try `pkg-config' first.  If that fails, a function
+# from the library is tested in the traditional autoconf way (zlib, bzip2),
+# or a config script is called (libpng).
+#
+# The `xxx_reqpriv' variables are for the `Requires.private' field in
+# `freetype2.pc'.  The `xxx_libpriv' variables are for the `Libs.private'
+# field in `freetype2.pc' if pkg-config doesn't find a proper .pc file.
+#
+# The `xxx_libstaticconf' variables are for the `freetype-config' script.
+#
+# Note that a call to PKG_CHECK_MODULES(XXX, ...) sets and creates the
+# output variables `XXX_CFLAGS' and `XXX_LIBS'.  In case one or both are set
+# for a library by the user, no entry for this library is added to
+# `Requires.private'.  Instead, it gets added to `Libs.private'
+
+
 # check for system zlib
 
-# don't quote AS_HELP_STRING!
 AC_ARG_WITH([zlib],
-  AS_HELP_STRING([--without-zlib],
-                 [use internal zlib instead of system-wide]))
-if test x$with_zlib != xno && test -z "$LIBZ"; then
-  AC_CHECK_LIB([z],
-               [gzsetparams],
-               [AC_CHECK_HEADER([zlib.h], [LIBZ='-lz'])])
-fi
-if test x$with_zlib != xno && test -n "$LIBZ"; then
-  SYSTEM_ZLIB=yes
-fi
+  [AS_HELP_STRING([--with-zlib=@<:@yes|no|auto@:>@],
+                  [use system zlib instead of internal library @<:@default=auto@:>@])],
+  [], [with_zlib=auto])
 
+have_zlib=no
+if test x"$with_zlib" = xyes -o x"$with_zlib" = xauto; then
+  zlib_pkg="zlib"
+  have_zlib_pkg=no
 
-# All library tests below use `pkg-config'.  The `XXX_PKG' variables are for
-# the `Requires.private' field in `freetype2.pc'; we use the `HAVE_PKG' flag
-# to insert commas between the entries.
-HAVE_PKG=no
+  if test x"$ZLIB_CFLAGS" = x -a x"$ZLIB_LIBS" = x; then
+    PKG_CHECK_EXISTS([$zlib_pkg], [have_zlib_pkg=yes])
+  fi
+  PKG_CHECK_MODULES([ZLIB], [$zlib_pkg],
+                    [have_zlib="yes (pkg-config)"], [:])
+
+  if test $have_zlib_pkg = yes; then
+    # we have zlib.pc
+    zlib_reqpriv="$zlib_pkg"
+    zlib_libpriv=
+    zlib_libstaticconf=`$PKG_CONFIG --static --libs "$zlib_pkg"`
+  else
+    zlib_reqpriv=
+
+    if test "$have_zlib" != no; then
+      # ZLIB_CFLAGS and ZLIB_LIBS are set by the user
+      zlib_libpriv="$ZLIB_LIBS"
+      zlib_libstaticconf="$ZLIB_LIBS"
+      have_zlib="yes (ZLIB_CFLAGS and ZLIB_LIBS)"
+    else
+      # fall back to standard autoconf test
+      AC_CHECK_LIB([z],
+                   [gzsetparams],
+                   [AC_CHECK_HEADER([zlib.h],
+                                    [have_zlib="yes (autoconf test)"
+                                     zlib_libpriv="-lz"
+                                     zlib_libstaticconf="$zlib_libpriv"
+                                     ZLIB_LIBS="$zlib_libpriv"])])
+    fi
+  fi
+fi
+
+if test x"$with_zlib" = xyes -a "$have_zlib" = no; then
+  AC_MSG_ERROR([external zlib support requested but library not found])
+fi
 
 
 # check for system libbz2
 
-HAVE_LIBBZIP2=no
-# don't quote AS_HELP_STRING!
 AC_ARG_WITH([bzip2],
-  AS_HELP_STRING([--without-bzip2],
-                 [do not support bzip2 compressed fonts]))
-if test x$with_bzip2 != xno; then
-  BZIP2_PKG="bzip2"
-  # as a side effect, this call sets and creates output variables
-  # BZIP2_CFLAGS and BZIP2_LIBS
-  PKG_CHECK_MODULES([BZIP2], [$BZIP2_PKG])
-  LIBBZIP2=`$PKG_CONFIG --libs-only-l "$BZIP2_PKG"`
-  HAVE_LIBBZIP2=yes
-  AC_MSG_RESULT([$BZIP2_LIBS])
-  if test $HAVE_PKG = no; then
-    HAVE_PKG=yes
+  [AS_HELP_STRING([--with-bzip2=@<:@yes|no|auto@:>@],
+                  [support bzip2 compressed fonts @<:@default=auto@:>@])],
+  [], [with_bzip2=auto])
+
+have_bzip2=no
+if test x"$with_bzip2" = xyes -o x"$with_bzip2" = xauto; then
+  bzip2_pkg="bzip2"
+  have_bzip2_pkg=no
+
+  if test x"$BZIP2_CFLAGS" = x -a x"$BZIP2_LIBS" = x; then
+    PKG_CHECK_EXISTS([$bzip2_pkg], [have_bzip2_pkg=yes])
+  fi
+  PKG_CHECK_MODULES([BZIP2], [$bzip2_pkg],
+                    [have_bzip2="yes (pkg-config)"], [:])
+
+  if test $have_bzip2_pkg = yes; then
+    # we have bzip2.pc
+    bzip2_reqpriv="$bzip2_pkg"
+    bzip2_libpriv=
+    bzip2_libstaticconf=`$PKG_CONFIG --static --libs "$bzip2_pkg"`
   else
-    BZIP2_PKG=", $BZIP2_PKG"
+    bzip2_reqpriv=
+
+    if test "$have_bzip2" != no; then
+      # BZIP2_CFLAGS and BZIP2_LIBS are set by the user
+      bzip2_libpriv="$BZIP2_LIBS"
+      bzip2_libstaticconf="$BZIP2_LIBS"
+      have_bzip2="yes (BZIP2_CFLAGS and BZIP2_LIBS)"
+    else
+      # fall back to standard autoconf test
+      AC_CHECK_LIB([bz2],
+                   [BZ2_bzDecompress],
+                   [AC_CHECK_HEADER([bzlib.h],
+                                    [have_bzip2="yes (autoconf test)"
+                                     bzip2_libpriv="-lbz2"
+                                     bzip2_libstaticconf="$bzip2_libpriv"
+                                     BZIP2_LIBS="$bzip2_libpriv"])])
+    fi
   fi
 fi
 
+if test x"$with_bzip2" = xyes -a "$have_bzip2" = no; then
+  AC_MSG_ERROR([bzip2 support requested but library not found])
+fi
+
 
 # check for system libpng
 
-HAVE_LIBPNG=no
-# don't quote AS_HELP_STRING!
 AC_ARG_WITH([png],
-  AS_HELP_STRING([--without-png],
-                 [do not support png compressed OpenType embedded bitmaps]))
-if test x$with_png != xno; then
-  LIBPNG_PKG="libpng"
-  # as a side effect, this call sets and creates output variables
-  # LIBPNG_CFLAGS and LIBPNG_LIBS
-  PKG_CHECK_MODULES([LIBPNG], [$LIBPNG_PKG])
-  LIBPNG=`$PKG_CONFIG --libs-only-l "$LIBPNG_PKG"`
-  HAVE_LIBPNG=yes
-  AC_MSG_RESULT([$LIBPNG_LIBS])
-  if test $HAVE_PKG = no; then
-    HAVE_PKG=yes
+  [AS_HELP_STRING([--with-png=@<:@yes|no|auto@:>@],
+                  [support png compressed OpenType embedded bitmaps @<:@default=auto@:>@])],
+  [], [with_png=auto])
+
+have_libpng=no
+if test x"$with_png" = xyes -o x"$with_png" = xauto; then
+  libpng_pkg="libpng"
+  have_libpng_pkg=no
+
+  if test x"$LIBPNG_CFLAGS" = x -a x"$LIBPNG_LIBS" = x; then
+    PKG_CHECK_EXISTS([$libpng_pkg], [have_libpng_pkg=yes])
+  fi
+  PKG_CHECK_MODULES([LIBPNG], [$libpng_pkg],
+                    [have_libpng="yes (pkg-config)"], [:])
+
+  if test $have_libpng_pkg = yes; then
+    # we have libpng.pc
+    libpng_reqpriv="$libpng_pkg"
+    libpng_libpriv=
+    libpng_libstaticconf=`$PKG_CONFIG --static --libs "$libpng_pkg"`
   else
-    LIBPNG_PKG=", $LIBPNG_PKG"
+    libpng_reqpriv=
+
+    if test "$have_libpng" != no; then
+      # LIBPNG_CFLAGS and LIBPNG_LIBS are set by the user
+      libpng_libpriv="$LIBPNG_LIBS"
+      libpng_libstaticconf="$LIBPNG_LIBS"
+      have_libpng="yes (LIBPNG_CFLAGS and LIBPNG_LIBS)"
+    else
+      # fall back to config script.
+      AC_MSG_CHECKING([for libpng-config])
+      if which libpng-config > /dev/null; then
+        LIBPNG_CFLAGS=`libpng-config --cflags`
+        LIBPNG_LIBS=`libpng-config --ldflags`
+        libpng_libpriv=`libpng-config --static --ldflags`
+        libpng_libstaticconf="$libpng_libpriv"
+        have_libpng="yes (libpng-config)"
+        AC_MSG_RESULT([yes])
+      else
+        AC_MSG_RESULT([no])
+      fi
+    fi
   fi
 fi
 
+if test x"$with_png" = xyes -a "$have_libpng" = no; then
+  AC_MSG_ERROR([libpng support requested but library not found])
+fi
+
 
 # check for system libharfbuzz
 
-HAVE_HARFBUZZ=no
-# don't quote AS_HELP_STRING!
 AC_ARG_WITH([harfbuzz],
-  AS_HELP_STRING([--without-harfbuzz],
-                 [do not use improved auto-hinting of OpenType fonts]))
-if test x$with_harfbuzz != xno; then
-  HARFBUZZ_PKG="harfbuzz >= 0.9.19"
-  # as a side effect, this call sets and creates output variables
-  # HARFBUZZ_CFLAGS and HARFBUZZ_LIBS
-  PKG_CHECK_MODULES([HARFBUZZ], [$HARFBUZZ_PKG])
-  LIBHARFBUZZ=`$PKG_CONFIG --libs-only-l "$HARFBUZZ_PKG"`
-  HAVE_LIBHARFBUZZ=yes
-  AC_MSG_RESULT([$HARFBUZZ_LIBS])
-  if test $HAVE_PKG = no; then
-    HAVE_PKG=yes
+  [AS_HELP_STRING([--with-harfbuzz=@<:@yes|no|auto@:>@],
+                  [improve auto-hinting of OpenType fonts @<:@default=auto@:>@])],
+  [], [with_harfbuzz=auto])
+
+have_harfbuzz=no
+if test x"$with_harfbuzz" = xyes -o x"$with_harfbuzz" = xauto; then
+  harfbuzz_pkg="harfbuzz >= 0.9.19"
+  have_harfbuzz_pkg=no
+
+  if test x"$HARFBUZZ_CFLAGS" = x -a x"$HARFBUZZ_LIBS" = x; then
+    PKG_CHECK_EXISTS([$harfbuzz_pkg], [have_harfbuzz_pkg=yes])
+  fi
+  PKG_CHECK_MODULES([HARFBUZZ], [$harfbuzz_pkg],
+                    [have_harfbuzz="yes (pkg-config)"], [:])
+
+  if test $have_harfbuzz_pkg = yes; then
+    # we have harfbuzz.pc
+    harfbuzz_reqpriv="$harfbuzz_pkg"
+    harfbuzz_libpriv=
+    harfbuzz_libstaticconf=`$PKG_CONFIG --static --libs "$harfbuzz_pkg"`
   else
-    HARFBUZZ_PKG=", $HARFBUZZ_PKG"
+    harfbuzz_reqpriv=
+
+    if test "$have_harfbuzz" != no; then
+      # HARFBUZZ_CFLAGS and HARFBUZZ_LIBS are set by the user
+      harfbuzz_libpriv="$HARFBUZZ_LIBS"
+      harfbuzz_libstaticconf="$HARFBUZZ_LIBS"
+      have_harfbuzz="yes (HARFBUZZ_CFLAGS and HARFBUZZ_LIBS)"
+    else
+      # since HarfBuzz is quite a new library we don't fall back to a
+      # different test; additionally, it has too many dependencies
+      :
+    fi
   fi
 fi
 
+if test x"$with_harfbuzz" = xyes -a "$have_harfbuzz" = no; then
+  AC_MSG_ERROR([harfbuzz support requested but library not found])
+fi
+
 
 # Some options handling SDKs/archs in CFLAGS should be copied
 # to LDFLAGS. Apple TechNote 2137 recommends to include these
@@ -426,15 +548,14 @@ set ${save_config_args}
 
 ftmac_c="" # src/base/ftmac.c should not be included in makefiles by default
 
-# don't quote AS_HELP_STRING!
 AC_ARG_WITH([old-mac-fonts],
   AS_HELP_STRING([--with-old-mac-fonts],
                  [allow Mac resource-based fonts to be used]))
 if test x$with_old_mac_fonts = xyes; then
   orig_LDFLAGS="${LDFLAGS}"
   AC_MSG_CHECKING([CoreServices & ApplicationServices of Mac OS X])
-  FT2_EXTRA_LIBS="-Wl,-framework,CoreServices -Wl,-framework,ApplicationServices"
-  LDFLAGS="$LDFLAGS $FT2_EXTRA_LIBS"
+  ft2_extra_libs="-Wl,-framework,CoreServices -Wl,-framework,ApplicationServices"
+  LDFLAGS="$LDFLAGS $ft2_extra_libs"
   AC_LINK_IFELSE([
     AC_LANG_PROGRAM([
 
@@ -520,7 +641,7 @@ if test x$with_old_mac_fonts = xyes; then
         CFLAGS="$CFLAGS -DHAVE_TYPE_RESOURCE_INDEX=0"
        ])],
     [AC_MSG_RESULT([not found])
-     FT2_EXTRA_LIBS=""
+     ft2_extra_libs=""
      LDFLAGS="${orig_LDFLAGS}"
      CFLAGS="$CFLAGS -DDARWIN_NO_CARBON"])
 else
@@ -740,7 +861,6 @@ fi
 
 # Whether to use AppleTypeService since Mac OS X.
 
-# don't quote AS_HELP_STRING!
 AC_ARG_WITH([ats],
   AS_HELP_STRING([--with-ats],
                  [use AppleTypeService, if available (default=yes)]))
@@ -791,41 +911,91 @@ case "$CFLAGS" in
 esac
 
 
-AC_SUBST([ftmac_c])
-AC_SUBST([LIBZ])
-AC_SUBST([LIBBZIP2])
-AC_SUBST([LIBPNG])
-AC_SUBST([LIBHARFBUZZ])
-AC_SUBST([FT2_EXTRA_LIBS])
-AC_SUBST([SYSTEM_ZLIB])
+# entries in Requires.private are separated by commas;
+REQUIRES_PRIVATE="$zlib_reqpriv,     \
+                  $bzip2_reqpriv,    \
+                  $libpng_reqpriv,   \
+                  $harfbuzz_reqpriv"
+# beautify
+REQUIRES_PRIVATE=`echo "$REQUIRES_PRIVATE" \
+                  | sed -e 's/^  *//'      \
+                        -e 's/  *$//'      \
+                        -e 's/, */,/g'     \
+                        -e 's/,,*/,/g'     \
+                        -e 's/^,*//'       \
+                        -e 's/,*$//'       \
+                        -e 's/,/, /g'`
+
+LIBS_PRIVATE="$zlib_libpriv     \
+              $bzip2_libpriv    \
+              $libpng_libpriv   \
+              $harfbuzz_libpriv \
+              $ft2_extra_libs"
+# beautify
+LIBS_PRIVATE=`echo "$LIBS_PRIVATE"  \
+              | sed -e 's/^  *//'   \
+                    -e 's/  *$//'   \
+                    -e 's/  */ /g'`
+
+LIBS_CONFIG="-lfreetype      \
+             $ZLIB_LIBS      \
+             $BZIP2_LIBS     \
+             $LIBPNG_LIBS    \
+             $HARFBUZZ_LIBS  \
+             $ft2_extra_libs"
+# remove -L/usr/lib and -L/usr/lib64 since `freetype-config' adds them later
+# on if necessary; also beautify
+LIBS_CONFIG=`echo "$LIBS_CONFIG"                \
+             | sed -e 's|-L */usr/lib64/* | |g' \
+                   -e 's|-L */usr/lib/* | |g'   \
+                   -e 's/^  *//'                \
+                   -e 's/  *$//'                \
+                   -e 's/  */ /g'`
+
+LIBSSTATIC_CONFIG="-lfreetype              \
+                   $zlib_libstaticconf     \
+                   $bzip2_libstaticconf    \
+                   $libpng_libstaticconf   \
+                   $harfbuzz_libstaticconf \
+                   $ft2_extra_libs"
+# remove -L/usr/lib and -L/usr/lib64 since `freetype-config' adds them later
+# on if necessary; also beautify
+LIBSSTATIC_CONFIG=`echo "$LIBSSTATIC_CONFIG"          \
+                   | sed -e 's|-L */usr/lib64/* | |g' \
+                         -e 's|-L */usr/lib/* | |g'   \
+                         -e 's/^  *//'                \
+                         -e 's/  *$//'                \
+                         -e 's/  */ /g'`
 
-AC_SUBST([BZIP2_PKG])
-AC_SUBST([LIBPNG_PKG])
-AC_SUBST([HARFBUZZ_PKG])
 
-LT_INIT(win32-dll)
+AC_SUBST([ftmac_c])
+AC_SUBST([REQUIRES_PRIVATE])
+AC_SUBST([LIBS_PRIVATE])
+AC_SUBST([LIBS_CONFIG])
+AC_SUBST([LIBSSTATIC_CONFIG])
 
 AC_SUBST([hardcode_libdir_flag_spec])
 AC_SUBST([wl])
 AC_SUBST([build_libtool_libs])
 
+
 # changing LDFLAGS value should only be done after
 # lt_cv_prog_compiler_static_works test
 
-if test x$SYSTEM_ZLIB = xyes; then
-  CFLAGS="$CFLAGS -DFT_CONFIG_OPTION_SYSTEM_ZLIB"
-  LDFLAGS="$LDFLAGS $LIBZ"
+if test "$have_zlib" != no; then
+  CFLAGS="$CFLAGS $ZLIB_CFLAGS -DFT_CONFIG_OPTION_SYSTEM_ZLIB"
+  LDFLAGS="$LDFLAGS $ZLIB_LIBS"
 fi
 
-if test x$HAVE_LIBBZIP2 = xyes; then
-  CFLAGS="$CFLAGS $LIBBZIP2_CFLAGS -DFT_CONFIG_OPTION_USE_BZIP2"
-  LDFLAGS="$LDFLAGS $LIBBZIP2_LIBS"
+if test "$have_bzip2" != no; then
+  CFLAGS="$CFLAGS $BZIP2_CFLAGS -DFT_CONFIG_OPTION_USE_BZIP2"
+  LDFLAGS="$LDFLAGS $BZIP2_LIBS"
 fi
-if test x$HAVE_LIBPNG = xyes; then
+if test x"$have_libpng" != no; then
   CFLAGS="$CFLAGS $LIBPNG_CFLAGS -DFT_CONFIG_OPTION_USE_PNG"
   LDFLAGS="$LDFLAGS $LIBPNG_LIBS"
 fi
-if test x$HAVE_LIBHARFBUZZ = xyes; then
+if test x"$have_harfbuzz" != no; then
   CFLAGS="$CFLAGS $HARFBUZZ_CFLAGS -DFT_CONFIG_OPTION_USE_HARFBUZZ"
   LDFLAGS="$LDFLAGS $HARFBUZZ_LIBS"
 fi
@@ -855,4 +1025,13 @@ AC_CONFIG_FILES([unix-cc.mk:unix-cc.in
 
 AC_OUTPUT
 
+AC_MSG_NOTICE([
+
+Library configuration:
+  external zlib: $have_zlib
+  bzip2:         $have_bzip2
+  libpng:        $have_libpng
+  harfbuzz:      $have_harfbuzz
+])
+
 # end of configure.raw
diff --git a/builds/unix/freetype-config.in b/builds/unix/freetype-config.in
index 7221d83..41c3a88 100644
--- a/builds/unix/freetype-config.in
+++ b/builds/unix/freetype-config.in
@@ -38,6 +38,8 @@ Options:
   --libtool              display library name for linking with libtool
   --cflags               display flags for compiling with the FreeType
                          library
+  --static               make command line options display flags
+                         for static linking
 EOF
   exit $1
 }
@@ -88,6 +90,9 @@ while test $# -gt 0 ; do
   --libtool)
     echo_libtool=yes
     ;;
+  --static)
+    show_static=yes
+    ;;
   *)
     usage 1 1>&2
     ;;
@@ -137,7 +142,11 @@ if test "$echo_cflags" = "yes" ; then
 fi
 
 if test "$echo_libs" = "yes" ; then
-  libs="-lfreetype %LIBZ% %LIBBZIP2% %LIBPNG% %LIBHARFBUZZ% %FT2_EXTRA_LIBS%"
+  libs="%LIBS_CONFIG%"
+  staticlibs="%LIBSSTATIC_CONFIG%"
+  if test "$show_static" = "yes" ; then
+    libs="$staticlibs"
+  fi
   if test "${SYSROOT}$libdir" != "/usr/lib"  &&
      test "${SYSROOT}$libdir" != "/usr/lib64"; then
     echo -L${SYSROOT}$libdir $libs
diff --git a/builds/unix/freetype2.in b/builds/unix/freetype2.in
index 9747e09..6e7fb10 100644
--- a/builds/unix/freetype2.in
+++ b/builds/unix/freetype2.in
@@ -8,7 +8,7 @@ URL: http://freetype.org
 Description: A free, high-quality, and portable font engine.
 Version: %ft_version%
 Requires:
-Requires.private: %BZIP2_PKG%%LIBPNG_PKG%%HARFBUZZ_PKG%
+Requires.private: %REQUIRES_PRIVATE%
 Libs: -L${libdir} -lfreetype
-Libs.private: %LIBZ% %FT2_EXTRA_LIBS%
+Libs.private: %LIBS_PRIVATE%
 Cflags: -I${includedir}
diff --git a/builds/unix/unix-def.in b/builds/unix/unix-def.in
index 31d2441..35ea9c8 100644
--- a/builds/unix/unix-def.in
+++ b/builds/unix/unix-def.in
@@ -62,16 +62,12 @@ version_info := @version_info@
 
 # Variables needed for `freetype-config' and `freetype.pc'.
 #
-FT2_EXTRA_LIBS     := @FT2_EXTRA_LIBS@
-LIBZ               := @LIBZ@
-LIBBZIP2           := @LIBBZIP2@
-LIBPNG             := @LIBPNG@
-LIBHARFBUZZ        := @LIBHARFBUZZ@
+REQUIRES_PRIVATE   := @REQUIRES_PRIVATE@
+LIBS_PRIVATE       := @LIBS_PRIVATE@
+LIBS_CONFIG        := @LIBS_CONFIG@
+LIBSSTATIC_CONFIG  := @LIBSSTATIC_CONFIG@
 build_libtool_libs := @build_libtool_libs@
 ft_version         := @ft_version@
-BZIP2_PKG          := @BZIP2_PKG@
-LIBPNG_PKG         := @LIBPNG_PKG@
-HARFBUZZ_PKG       := @HARFBUZZ_PKG@
 
 # The directory where all library files are placed.
 #
@@ -106,18 +102,15 @@ NO_OUTPUT := 2> /dev/null
 
 $(OBJ_BUILD)/freetype-config: $(TOP_DIR)/builds/unix/freetype-config.in
 	rm -f $@ $@.tmp
-	sed -e 's|%FT2_EXTRA_LIBS%|$(FT2_EXTRA_LIBS)|' \
-	    -e 's|%LIBZ%|$(LIBZ)|' \
-	    -e 's|%LIBBZIP2%|$(LIBBZIP2)|' \
-	    -e 's|%LIBPNG%|$(LIBPNG)|' \
-	    -e 's|%LIBHARFBUZZ%|$(LIBHARFBUZZ)|' \
+	sed -e 's|%LIBS_CONFIG%|$(LIBS_CONFIG)|'               \
+	    -e 's|%LIBSSTATIC_CONFIG%|$(LIBSSTATIC_CONFIG)|'   \
 	    -e 's|%build_libtool_libs%|$(build_libtool_libs)|' \
-	    -e 's|%exec_prefix%|$(exec_prefix)|' \
-	    -e 's|%ft_version%|$(ft_version)|' \
-	    -e 's|%includedir%|$(includedir)|' \
-	    -e 's|%libdir%|$(libdir)|' \
-	    -e 's|%prefix%|$(prefix)|' \
-	    $< \
+	    -e 's|%exec_prefix%|$(exec_prefix)|'               \
+	    -e 's|%ft_version%|$(ft_version)|'                 \
+	    -e 's|%includedir%|$(includedir)|'                 \
+	    -e 's|%libdir%|$(libdir)|'                         \
+	    -e 's|%prefix%|$(prefix)|'                         \
+	    $<                                                 \
 	    > $@.tmp
 	chmod +x $@.tmp
 	chmod a-w $@.tmp
@@ -125,18 +118,15 @@ $(OBJ_BUILD)/freetype-config: $(TOP_DIR)/builds/unix/freetype-config.in
 
 $(OBJ_BUILD)/freetype2.pc: $(TOP_DIR)/builds/unix/freetype2.in
 	rm -f $@ $@.tmp
-	sed -e 's|%FT2_EXTRA_LIBS%|$(FT2_EXTRA_LIBS)|' \
-	    -e 's|%LIBZ%|$(LIBZ)|' \
-	    -e 's|%BZIP2_PKG%|$(BZIP2_PKG)|' \
-	    -e 's|%LIBPNG_PKG%|$(LIBPNG_PKG)|' \
-	    -e 's|%HARFBUZZ_PKG%|$(HARFBUZZ_PKG)|' \
+	sed -e 's|%REQUIRES_PRIVATE%|$(REQUIRES_PRIVATE)|'     \
+	    -e 's|%LIBS_PRIVATE%|$(LIBS_PRIVATE)|'             \
 	    -e 's|%build_libtool_libs%|$(build_libtool_libs)|' \
-	    -e 's|%exec_prefix%|$(exec_prefix)|' \
-	    -e 's|%ft_version%|$(ft_version)|' \
-	    -e 's|%includedir%|$(includedir)|' \
-	    -e 's|%libdir%|$(libdir)|' \
-	    -e 's|%prefix%|$(prefix)|' \
-	    $< \
+	    -e 's|%exec_prefix%|$(exec_prefix)|'               \
+	    -e 's|%ft_version%|$(ft_version)|'                 \
+	    -e 's|%includedir%|$(includedir)|'                 \
+	    -e 's|%libdir%|$(libdir)|'                         \
+	    -e 's|%prefix%|$(prefix)|'                         \
+	    $<                                                 \
 	    > $@.tmp
 	chmod a-w $@.tmp
 	mv $@.tmp $@
diff --git a/docs/freetype-config.1 b/docs/freetype-config.1
index e5d7251..f5e004b 100644
--- a/docs/freetype-config.1
+++ b/docs/freetype-config.1
@@ -68,6 +68,10 @@ Return compiler flags for linking with the installed FreeType library.
 .B \-\-cflags
 Return compiler flags for compiling against the installed FreeType library.
 .
+.TP
+.B \-\-static
+Make command line options display flags for static linking.
+.
 .
 .SS Path override options
 .