diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-03-30 17:06:25 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-04-09 17:15:47 +0200 |
| commit | 877126e572c2d473cd80de7abaae6d0fadc5c142 (patch) | |
| tree | 018c1aaf0ddead5ac70f2da3cc8c714767de75ff | |
| parent | 00b82b287ca91a270f1c462c9b0d948dfb8838e1 (diff) | |
Allow more input files and compiler flags in fltk-config (#647, #656)
Also refactor, reformat, and simplify code:
- move all variable substitutions to the beginning of the file
- simplify Cairo support and nesting of 'if' clauses
- unify indenting: 4 spaces, no tabs
| -rw-r--r-- | fltk-config.in | 448 |
1 files changed, 240 insertions, 208 deletions
diff --git a/fltk-config.in b/fltk-config.in index c82d8067c..17c91a270 100644 --- a/fltk-config.in +++ b/fltk-config.in @@ -2,7 +2,7 @@ # # FLTK configuration utility. # -# Copyright 2000-2016 by Bill Spitzak and others. +# Copyright 2000-2023 by Bill Spitzak and others. # Original version Copyright 2000 by James Dean Palmer # Adapted by Vincent Penne and Michael Sweet # @@ -17,25 +17,16 @@ # https://www.fltk.org/bugs.php # +# Variables and constants generated by configure or CMake: + +# version numbers MAJOR_VERSION=@FLTK_VERSION_MAJOR@ MINOR_VERSION=@FLTK_VERSION_MINOR@ PATCH_VERSION=@FLTK_VERSION_PATCH@ + VERSION="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION" APIVERSION="$MAJOR_VERSION.$MINOR_VERSION" -### BEGIN fltk-config -selfdir=`dirname "$0"` - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -exec_prefix_set=no -includedir=@includedir@ -libdir=@libdir@ -srcdir=@srcdir@ - -# BINARY_DIR - used only for CMake builds in local (binary) directory -BINARY_DIR=@BINARY_DIR@ - # compiler names CC="@CC@" CXX="@CXX@" @@ -49,89 +40,101 @@ LDLIBS="@LIBS@" OPTIM="@OPTIM@" CAIROFLAGS="@CAIROFLAGS@" -# Config -if ( ( test -f "$includedir/FL/fl_config.h" && \ - grep -q '^#define FLTK_HAVE_CAIRO 1' "$includedir/FL/fl_config.h" ) \ - || \ - ( test -f "$selfdir/FL/fl_config.h" && \ - grep -q '^#define FLTK_HAVE_CAIRO 1' "$selfdir/FL/fl_config.h" ) ) ; then - FLTK_HAVE_CAIRO=1 -else - FLTK_HAVE_CAIRO=0 -fi - -# Check for local invocation, and update paths accordingly... -if test -f "$selfdir/FL/Fl_Window.H"; then - includedir="$selfdir" - libdir="$selfdir/lib" - - if test -f "$libdir/libfltk_jpeg.a"; then - CFLAGS="-I$includedir/jpeg $CFLAGS" - CXXFLAGS="-I$includedir/jpeg $CXXFLAGS" - fi - - if test -f "$libdir/libfltk_z.a"; then - CFLAGS="-I$includedir/zlib $CFLAGS" - CXXFLAGS="-I$includedir/zlib $CXXFLAGS" - fi - - if test -f "$libdir/libfltk_png.a"; then - CFLAGS="-I$includedir/png $CFLAGS" - CXXFLAGS="-I$includedir/png $CXXFLAGS" - fi -fi - -if test -d $includedir/FL/images; then - CFLAGS="-I$includedir/FL/images $CFLAGS" - CXXFLAGS="-I$includedir/FL/images $CXXFLAGS" -fi +# BINARY_DIR: this is only set for CMake builds in the CMake build directory, +# otherwise it is an empty string +BINARY_DIR=@BINARY_DIR@ -if [ $FLTK_HAVE_CAIRO = 1 ]; then - CFLAGS="$CAIROFLAGS $CFLAGS" - CXXFLAGS="$CAIROFLAGS $CXXFLAGS" -fi +prefix=@prefix@ +exec_prefix=@exec_prefix@ +exec_prefix_set=no +includedir=@includedir@ +libdir=@libdir@ +srcdir=@srcdir@ -# libraries to link with: +# libraries to link with (must be after 'prefix' stuff) LIBNAME="@LIBNAME@" DSONAME="@DSONAME@" DSOLINK="@DSOLINK@" IMAGELIBS="@IMAGELIBS@" STATICIMAGELIBS="@STATICIMAGELIBS@" -CAIROLIBS="@CAIROLIBS@" SHAREDSUFFIX="@SHAREDSUFFIX@" +CAIROLIBS="@CAIROLIBS@" +GLLIBS="@GLLIBS@" + +# BEGIN fltk-config code + +selfdir=`dirname "$0"` + +# Check for local invocation (in FLTK source folder), and update paths accordingly... +if test -f "$selfdir/FL/Fl_Window.H"; then + includedir="$selfdir" + libdir="$selfdir/lib" +fi + +# Check bundled image libraries in source tree +if test -f "$libdir/libfltk_jpeg.a"; then + CFLAGS="-I$includedir/jpeg $CFLAGS" + CXXFLAGS="-I$includedir/jpeg $CXXFLAGS" +fi + +if test -f "$libdir/libfltk_z.a"; then + CFLAGS="-I$includedir/zlib $CFLAGS" + CXXFLAGS="-I$includedir/zlib $CXXFLAGS" +fi + +if test -f "$libdir/libfltk_png.a"; then + CFLAGS="-I$includedir/png $CFLAGS" + CXXFLAGS="-I$includedir/png $CXXFLAGS" +fi + +# Check bundled image libraries in installation folder. +# Note: jpeg, png, and zlib headers are installed in FL/images +if test -d $includedir/FL/images; then + CFLAGS="-I$includedir/FL/images $CFLAGS" + CXXFLAGS="-I$includedir/FL/images $CXXFLAGS" +fi + +# Cairo support +if test -n $CAIROFLAGS; then + CFLAGS="$CAIROFLAGS $CFLAGS" + CXXFLAGS="$CAIROFLAGS $CXXFLAGS" +fi usage () { echo "Usage: fltk-config [OPTIONS] Options: - [--version] - [--api-version] + [--version] + [--api-version] Options telling what we are doing: - [--use-gl] use GL - [--use-images] use extra image formats (PNG, JPEG) - [--use-glut] use glut compatibility layer - [--use-forms] use forms compatibility layer - [--use-cairo] use cairo graphics lib + [--use-gl] use GL + [--use-images] use extra image formats (PNG, JPEG) + [--use-glut] use glut compatibility layer + [--use-forms] use forms compatibility layer + [--use-cairo] use cairo graphics lib Options telling what information we request: - [--cc] return C compiler used to compile FLTK - [--cxx] return C++ compiler used to compile FLTK - [--optim] return compiler optimization used to compile FLTK - [--cflags] return flags to compile C using FLTK - [--cxxflags] return flags to compile C++ using FLTK - [--ldflags] return flags to link against FLTK - [--ldstaticflags] return flags to link against static FLTK library + [--cc] return C compiler used to compile FLTK + [--cxx] return C++ compiler used to compile FLTK + [--optim] return compiler optimization used to compile FLTK + [--cflags] return flags to compile C using FLTK + [--cxxflags] return flags to compile C++ using FLTK + [--ldflags] return flags to link against FLTK + [--ldstaticflags] return flags to link against static FLTK library even if there are DSOs installed - [--libs] return FLTK libraries full path for dependencies - [--prefix] return FLTK install time --prefix directory - [--includedir] return FLTK install time include directory + [--libs] return FLTK libraries full path for dependencies + [--prefix] return FLTK install time --prefix directory + [--includedir] return FLTK install time include directory Options to compile and link an application: - [-g] compile the program with debugging information - [-Dname[=value]] compile the program with the given define - [--compile program.cxx] - [--post program] prepare the program for desktop use + [-g] compile the program with debugging information + [-Dname[=value]] compile the program with the given define + [--compile program.cxx ..] compile and link the program with optional + .. compiler flags, source files, and libraries + [--link flags and libs] additional linker flags and libraries + .. for --compile, added after all other libs + [--post program] prepare the program for desktop use (macOS) " exit $1 } @@ -140,89 +143,113 @@ if test $# -eq 0; then usage 1 fi -no_plugins=no +# variables for parsing and generation of the commandline compile= post= debug= +flags= +files= +use_link= +link= # Parse command line options while test $# -gt 0 do - case "$1" in - -*=*) - optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` - ;; - *) - optarg= - ;; - esac - case $1 in - --version) - echo $VERSION - ;; - --api-version) - echo $APIVERSION - ;; - --cc) - echo $CC - ;; - --cxx) - echo $CXX - ;; - --optim) - echo_optim=yes - ;; - --use-gl | --use-glut) - use_gl=yes - ;; - --use-forms) - use_forms=yes - ;; - --use-images) - use_images=yes - ;; - --use-cairo) - use_cairo=yes - ;; - --cflags) - echo_cflags=yes - ;; - --cxxflags) - echo_cxxflags=yes - ;; - --ldflags) - echo_ldflags=yes - ;; - --ldstaticflags) - echo_ldstaticflags=yes - ;; - --libs) - echo_libs=yes - ;; - --prefix) - echo_prefix=yes - ;; - --includedir) - echo_includedir=yes - ;; - -g) - debug=-g - ;; - -D*) - CXXFLAGS="$CXXFLAGS $1" - ;; - --compile) - compile="$2" - shift - ;; - --post) - post="$2" - shift - ;; - *) - echo_help=yes - ;; + --version) + echo $VERSION + ;; + --api-version) + echo $APIVERSION + ;; + --cc) + echo $CC + ;; + --cxx) + echo $CXX + ;; + --optim) + echo_optim=yes + ;; + --use-gl | --use-glut) + use_gl=yes + ;; + --use-forms) + use_forms=yes + ;; + --use-images) + use_images=yes + ;; + --use-cairo) + use_cairo=yes + ;; + --cflags) + echo_cflags=yes + ;; + --cxxflags) + echo_cxxflags=yes + ;; + --ldflags) + echo_ldflags=yes + ;; + --ldstaticflags) + echo_ldstaticflags=yes + ;; + --libs) + echo_libs=yes + ;; + --prefix) + echo_prefix=yes + ;; + --includedir) + echo_includedir=yes + ;; + -g) + debug=-g + ;; + -D*) + CXXFLAGS="$CXXFLAGS $1" + ;; + --compile) + compile="$2" + shift + ;; + --post) + post="$2" + shift + ;; + --link) + # linker flags and libs, allowed only after "--compile" + if test -n "$compile"; then + use_link=yes + else + echo_help=yes + fi + ;; + -*) + # additional compiler flags, allowed only after "--compile" + if test -n "$compile"; then + if test -n "$use_link"; then + link="$link $1" # flags and libs after "--link" + else + flags="$flags $1" # compiler flags like "-I..." + fi + else + echo_help=yes + fi + ;; + *) + # additional source files or libs, allowed only after "--compile" + if test -n "$compile"; then + if test -n "$use_link"; then + link="$link $1" # linker flag or library + else + files="$files $1" # other (source) files + fi + else + echo_help=yes + fi + ;; esac shift done @@ -233,7 +260,8 @@ else includes= fi -if test "$BINARY_DIR" != ""; then +# prepend build directory for fltk-config in CMake build folder +if test -n "$BINARY_DIR"; then includes="-I$BINARY_DIR $includes" fi @@ -251,16 +279,18 @@ if test x$use_forms = xyes; then LDLIBS="-lfltk_forms$SHAREDSUFFIX $LDLIBS" LDSTATIC="$libdir/libfltk_forms.a $LDSTATIC" fi + if test x$use_gl = xyes; then - LDLIBS="-lfltk_gl$SHAREDSUFFIX @GLLIBS@ $LDLIBS" - LDSTATIC="$libdir/libfltk_gl.a @GLLIBS@ $LDSTATIC" + LDLIBS="-lfltk_gl$SHAREDSUFFIX $GLLIBS $LDLIBS" + LDSTATIC="$libdir/libfltk_gl.a $GLLIBS $LDSTATIC" fi + if test x$use_images = xyes; then LDLIBS="-lfltk_images$SHAREDSUFFIX $IMAGELIBS $LDLIBS" LDSTATIC="$libdir/libfltk_images.a $STATICIMAGELIBS $LDSTATIC" fi -if test x$use_cairo = xyes -a $FLTK_HAVE_CAIRO = 1; then +if test x$use_cairo = xyes -a -n $CAIROLIBS; then LDLIBS="$CAIROLIBS $LDLIBS" LDSTATIC="$CAIROLIBS $LDSTATIC" fi @@ -277,73 +307,75 @@ if test -n "$compile"; then case "$compile" in *.cxx) prog="`basename \"$compile\" .cxx`" - ;; + ;; *.cpp) prog="`basename \"$compile\" .cpp`" - ;; + ;; *.cc) prog="`basename \"$compile\" .cc`" - ;; + ;; *.C) prog="`basename \"$compile\" .C`" - ;; - *) - echo "ERROR: Unknown/bad C++ source file extension on \"$compile\"!" - exit 1 - ;; + ;; + *) + echo "ERROR: Unknown/bad C++ source file extension on \"$compile\"!" + exit 1 + ;; esac post="$prog" - echo $CXX $ARCHFLAGS $includes $CXXFLAGS $debug -o "'$prog'" "'$compile'" $LDSTATIC - $CXX $ARCHFLAGS $includes $CXXFLAGS $debug -o "$prog" "$compile" $LDSTATIC || exit 1 + command="$CXX $ARCHFLAGS $includes $CXXFLAGS $debug -o $prog $flags $compile $files $LDSTATIC $link" + + echo $command + $command || exit 1 fi if test -n "$post"; then running=`uname` if test "$running" = "Darwin"; then - # if FLTK targets MacOS+X11, apps need not be bundled - if test `echo $LDLIBS | fgrep -c -e " -lX11"` = 1; then - running="" - fi + # if FLTK targets macOS + X11, apps need not be bundled + if test `echo $LDLIBS | fgrep -c -e " -lX11"` = 1; then + running="" + fi fi case $running in - Darwin) - echo Creating "'$post.app'" bundle for desktop... - id=`echo $post | tr ' ' '_'` - - # Make the bundle directory and move the executable there - rm -rf "$post.app/Contents/MacOS" - mkdir -p "$post.app/Contents/MacOS" - mv "$post" "$post.app/Contents/MacOS" - - # Make a shell script that runs the bundled executable - echo "#!/bin/sh" >"$post" - echo 'dir="`dirname \"$0\"`"' >>"$post" - echo 'exec "$dir/'"$post.app/Contents/MacOS/$post"'" "$@"' >>"$post" - chmod +x "$post" - - # Make the simplest Info.plist needed for an application - cat >"$post.app/Contents/Info.plist" <<EOF + Darwin) + echo Creating "'$post.app'" bundle for desktop... + id=`echo $post | tr ' ' '_'` + + # Make the bundle directory and move the executable there + rm -rf "$post.app/Contents/MacOS" + mkdir -p "$post.app/Contents/MacOS" + mv "$post" "$post.app/Contents/MacOS" + + # Make a shell script that runs the bundled executable + echo "#!/bin/sh" >"$post" + echo 'dir="`dirname \"$0\"`"' >>"$post" + echo 'exec "$dir/'"$post.app/Contents/MacOS/$post"'" "$@"' >>"$post" + chmod +x "$post" + + # Make the simplest Info.plist needed for an application + cat >"$post.app/Contents/Info.plist" <<EOF <?xml version="1.0" encoding="UTF-8"?> <plist version="0.9"> <dict> - <key>CFBundleInfoDictionaryVersion</key> - <string>6.0</string> - <key>CFBundleExecutable</key> - <string>$post</string> - <key>CFBundleIdentifier</key> - <string>org.fltk.$id</string> - <key>CFBundleName</key> - <string>$post</string> - <key>CFBundlePackageType</key> - <string>APPL</string> - <key>NSHighResolutionCapable</key> - <true/> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleExecutable</key> + <string>$post</string> + <key>CFBundleIdentifier</key> + <string>org.fltk.$id</string> + <key>CFBundleName</key> + <string>$post</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>NSHighResolutionCapable</key> + <true/> </dict> </plist> EOF - ;; + ;; esac fi @@ -364,13 +396,13 @@ if test "$echo_ldflags" = "yes"; then libdirs=$libs for i in $LDLIBS ; do - if test $i != -L$libdir ; then - if test -z "$my_libs" ; then - my_libs="$i" - else - my_libs="$my_libs $i" - fi - fi + if test $i != -L$libdir ; then + if test -z "$my_libs" ; then + my_libs="$i" + else + my_libs="$my_libs $i" + fi + fi done echo $libdirs $my_libs fi @@ -397,7 +429,7 @@ if test "$echo_libs" = "yes"; then if test -f $libdir/lib$lib.a; then USELIBS="$libdir/lib$lib.a $USELIBS" fi - done + done fi echo $USELIBS |
