File: Preflight

package info (click to toggle)
gr-framework 0.73.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,600 kB
  • sloc: ansic: 87,413; cpp: 45,348; objc: 3,057; javascript: 2,647; makefile: 1,129; python: 1,000; sh: 991; yacc: 855; pascal: 554; fortran: 228
file content (768 lines) | stat: -rwxr-xr-x 21,014 bytes parent folder | download
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
755
756
757
758
759
760
761
762
763
764
765
766
767
768
#!/usr/bin/env bash

if [ -f /usr/local/bin/python ]
then
  export PATH="/usr/local/bin:$PATH"
fi

target=all
if [ -z "${CC}" ]; then
  CC="cc"
fi
if [ -z "${CXX}" ]; then
  CXX="c++"
fi
while [ $# -gt 0 ]
do
  eval $1
  shift
done
wxdefs=""
qt4defs=""
qt5defs=""
qt6defs=""
if [ -n "${QT_ARCH}" ]; then
  qt_arch="${QT_ARCH}"
  qt_lib_suffix=""
elif [ "`uname -m`" = "x86_64" ]; then
  qt_lib_suffix="64"
  qt_arch="x86_64"
else
  qt_lib_suffix=""
  qt_arch="i386"   # using 'uname -p' does not work in that case; for ubuntu it returns i686, but i386 is set as path prefix
fi
qt4_qmake_names=("qmake-qt4" "qmake")
qt4_qmake_dirs=("/usr/lib/${qt_arch}-linux-gnu/qt4/bin" "/usr/bin" "/usr/lib${qt_lib_suffix}/qt4/bin")
qt5_qmake_names=("qmake-qt5" "qmake")
qt5_qmake_dirs=("/usr/lib/${qt_arch}-linux-gnu/qt5/bin" "/usr/bin" "/usr/lib${qt_lib_suffix}/qt5/bin")
if [ -d /usr/lib/arm-linux-gnueabihf/qt5 ]; then
  qt5_qmake_names=("qmake")
  qt5_qmake_dirs=("/usr/lib/arm-linux-gnueabihf/qt5/bin" "/usr/bin")
fi
qt6_qmake_names=("qmake-qt6" "qmake6" "qmake")
qt6_qmake_dirs=("/usr/lib/${qt_arch}-linux-gnu/qt6/bin" "/usr/bin" "/usr/lib${qt_lib_suffix}/qt6/bin")
gtkdefs=""
x11defs=""
xftdefs=""
gsdefs=""
glfwdefs=""
zmqdefs=""
avdefs=""
cairodefs=""
extradefs=""
if [ `uname` = "Darwin" ]; then
  if [ `arch` = "arm64" ]; then
    extra_root="/opt"
  else
    extra_root="/usr/local"
  fi
  if [ -z "${EXTRA_CFLAGS}" ]; then
    EXTRA_CFLAGS="-I${extra_root}/include"
  fi
  if [ -z "${EXTRA_CXXFLAGS}" ]; then
    EXTRA_CXXFLAGS="-I${extra_root}/include"
  fi
  if [ -z "${EXTRA_LDFLAGS}" ]; then
    EXTRA_LDFLAGS="-L${extra_root}/lib"
  fi
fi

create_extradef () {
    local var_name value extradef

    var_name="$1"
    shift
    extradef=""
    for value in "$@"; do
        if [ -z "${extradef}" ]; then
            extradef="${var_name}=${value}"
        else
            extradef="${extradef} ${var_name}+=${value}"
        fi
    done
    echo "${extradef}"
}

if [ ! -z "${EXTRA_CFLAGS}" ]; then
  extradefs="$(create_extradef EXTRA_CFLAGS $EXTRA_CFLAGS)"
fi
if [ ! -z "${EXTRA_CXXFLAGS}" ]; then
  extradefs="$extradefs $(create_extradef EXTRA_CXXFLAGS $EXTRA_CXXFLAGS)"
fi
if [ ! -z "${EXTRA_LDFLAGS}" ]; then
  extradefs="$extradefs $(create_extradef EXTRA_LDFLAGS $EXTRA_LDFLAGS)"
fi
ret=0

red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
normal=$(tput sgr0)

printf "\nBuilding GR Framework\n---------------------\n" >&2

if [ "`which ${CC} 2>/dev/null`" = "" ]
then
  info="${red} no${normal} [not found]"
else
  info="${green}yes${normal} [`${CC} --version | sed 's/) (/ /' | head -1`]"
fi
printf "%12s: %s\n" "C" "$info" >&2

if [ "`which ${CXX} 2>/dev/null`" = "" ]
then
  info="${red} no${normal} [not found]"
else
  info="${green}yes${normal} [`${CXX} --version | sed 's/) (/ /' | head -1`]"
fi
printf "%12s: %s\n" "C++" "$info" >&2

if [ "`which python 2>/dev/null`" = "" ]
then
  info="${red} no${normal} [not found]"
else
  info="${green}yes${normal} [version `python -c 'import sys;print(sys.version)' | head -1`]"
fi
printf "%12s: %s\n" "Python" "$info" >&2

if [ "`which latex 2>/dev/null`" = "" ]
then
  info="${red} no${normal} [not found]"
else
  info="${green}yes${normal} [version `latex --version|grep ^pdfTeX|awk '{print $2}'`]"
fi
printf "%12s: %s\n" "LaTeX" "$info" >&2

if [ "`which dvipng 2>/dev/null`" = "" ]
then
  info="${red} no${normal} [not found]"
else
  info="${green}yes${normal} [version `dvipng --version|grep ^dvipng|awk '{print $NF}'`]"
fi
printf "%12s: %s\n" "dvipng" "$info" >&2

function version {
  echo "$@" | awk -F. '{ printf("%d\n", $1); }';
}

if [ "$qt" != "no" ]
then
  qt_versions="4 5 6"
  if [ `uname` == "Darwin" ]; then
    if [ $(version "`sw_vers --productVersion`") -ge "14" ]; then
      qt_versions="5 6"
      qt4defs="QT4DEFS=-DNO_QT4 QT4_QMAKE=false"
    fi
  fi
  for qt_major_version in ${qt_versions}
  do
    eval current_qt="$qt${qt_major_version}"
    if [ "${current_qt}" != "no" ]
    then
      found_qmake=false
      eval qmake_path="\${QT${qt_major_version}_QMAKE}"
      if [ "${qmake_path}" != "" ]
      then
        if [ -x "${qmake_path}" ] || [ "`which ${qmake_path} 2>/dev/null`" != "" ]
        then
          qmake_qt_version="`${qmake_path} -query QT_VERSION 2>/dev/null`"
          if [ "${qmake_qt_version%%.*}" = "${qt_major_version}" ]
          then
            found_qmake=true
          fi
        fi
      else
        eval current_qmake_names=( "\${qt${qt_major_version}_qmake_names[@]}" )
        eval current_qmake_dirs=( "\${qt${qt_major_version}_qmake_dirs[@]}" )
        for qmake_name in "${current_qmake_names[@]}"
        do
          if [ "`which ${qmake_name} 2>/dev/null`" != "" ]
          then
            qmake_qt_version="`${qmake_name} -query QT_VERSION 2>/dev/null`"
            if [ "${qmake_qt_version%%.*}" = "${qt_major_version}" ]
            then
              found_qmake=true
              qmake_path="${qmake_name}"
              break
            fi
          fi
        done
        if [ "${found_qmake}" = "false" ]
        then
          for qmake_dir in "${current_qmake_dirs[@]}"
          do
            for qmake_name in "${current_qmake_names[@]}"
            do
              qmake_path="${qmake_dir}/${qmake_name}"
              if [ -x "${qmake_path}" ]
              then
                qmake_qt_version="`${qmake_path} -query QT_VERSION 2>/dev/null`"
                if [ "${qmake_qt_version%%.*}" = "${qt_major_version}" ]
                then
                  found_qmake=true
                  break
                fi
              fi
            done
            if [ "${found_qmake}" = "true" ]
            then
              break
            fi
          done
        fi
      fi
      if [ "${found_qmake}" = "false" ]
      then
        info="${red} no${normal} [Qt${qt_major_version} API not found]"
        eval qt${qt_major_version}defs="QT${qt_major_version}_QMAKE=false\ QT${qt_major_version}DEFS=-DNO_QT${qt_major_version}"
        ret=1
      else
        info="${green}yes${normal} [version ${qmake_qt_version}]"
        eval qt${qt_major_version}defs="QT${qt_major_version}_QMAKE=${qmake_path}"
      fi
    else
      eval qt${qt_major_version}defs="QT${qt_major_version}_QMAKE=false\ QT${qt_major_version}DEFS=-DNO_QT${qt_major_version}"
      info="${yellow} no${normal} [disabled]"
      ret=1
    fi
    printf "%12s: %s\n" "Qt${qt_major_version}" "$info" >&2
  done
fi

if [ "$wx" != "no" ]
then
  wxconfig=wx-config
  if [ "$WX_CONFIG" != "" ]
  then
    wxconfig=$WX_CONFIG
  fi
  if [ "`which $wxconfig 2>/dev/null`" = "" ]
  then
    wxdefs="WX_CONFIG=false WXDEFS=-DNO_WX WXINC= WXLIBS="
    info="${red} no${normal} [wx-config not found]"
    ret=1
  else
    wxdefs="WX_CONFIG=$wxconfig"
    info="${green}yes${normal} [version `wx-config --version`]"
  fi
else
  wxdefs="WX_CONFIG=false WXDEFS=-DNO_WX WXINC= WXLIBS="
  info="${yellow} no${normal} [disabled]"
  ret=1
fi
printf "%12s: %s\n" "wxWidgets" "$info" >&2

if [ "$gtk" != "no" ]
then
  if [ "`pkg-config gtk+-2.0 --cflags 2>/dev/null`" = "" ]
  then
    gtkdefs="GTK_CONFIG=false GTKDEFS=-DNO_GTK GTKINC= GTKLIBS="
    info="${red} no${normal} [gtk+-2.0 not found]"
    ret=1
  else
    gtkdefs="GTK_CONFIG=pkg-config"
    info="${green}yes${normal} [version `pkg-config gtk+-2.0 --modversion`]"
  fi
else
  gtkdefs="GTK_CONFIG=false GTKDEFS=-DNO_GTK GTKINC= GTKLIBS="
  info="${yellow} no${normal} [disabled]"
  ret=1
fi
printf "%12s: %s\n" "GTK+" "$info" >&2

if [ "$x11" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  cat >$tmpsrc << eof
#include <X11/Intrinsic.h>

int main(int argc, char **argv)
{
    Widget toplevel;
    toplevel = XtInitialize(argv[0], "simple", NULL, 0, &argc, argv);
    XtMainLoop();
    return 0;
}
eof
  if [ `uname` = "Darwin" ]; then
    x11path="/opt/X11"
  elif [ -d /usr/X11R6 ]; then
    x11path="/usr/X11R6"
  else
    x11path="/usr/X11"
  fi
  cmd="${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -I$x11path/include -L$x11path/lib -lXt -lX11"
  $cmd >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    x11defs="X11DEFS=-DNO_X11 X11INC= X11LIBS="
    info="${red} no${normal} [X11 API not found]"
    ret=1
  else
    x11defs="X11PATH=-L$x11path/lib"
    info="${green}yes${normal} [$x11path]"
  fi
else
  x11defs="X11DEFS=-DNO_X11 X11INC= X11LIBS="
  info="${yellow} no${normal} [disabled]"
  xft="no"
  gs="no"
  ret=1
fi
printf "%12s: %s\n" "X11" "$info" >&2
rm -f $tmpout $tmpsrc
if [ `uname` = "Darwin" ]; then
  dir=`dirname $0`
  if [ $ret -eq 0 ]; then
    cp -p $dir/gks/quartz/project.pbxproj.X11 lib/gks/quartz/GKSTerm.xcodeproj/project.pbxproj
  else
    cp -p $dir/gks/quartz/project.pbxproj lib/gks/quartz/GKSTerm.xcodeproj/project.pbxproj
  fi
fi

if [ "$xft" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmpver=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#include <stdio.h>
#include <X11/Xft/Xft.h>
int main(void)
{
    printf("%d.%d.%d\n", XFT_MAJOR, XFT_MINOR, XFT_REVISION);
    return 0;
}
eof
  if [ "`which freetype-config 2>/dev/null`" = "" ]; then
    freetype_cflags="`pkg-config freetype2 --cflags 2>/dev/null`"
  else
    freetype_cflags="`freetype-config --cflags 2>/dev/null`"
  fi
  cmd="${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -I$x11path/include $freetype_cflags"
  $cmd >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    xftdefs="XFTDEFS=-DNO_XFT XFTLIBS="
    info="${red} no${normal} [Xft API not found]"
    ret=1
  else
    $tmpout >$tmpver 2>&1
    info="${green}yes${normal} [version `cat $tmpver`]"
  fi
else
  xftdefs="XFTDEFS=-DNO_XFT XFTLIBS="
  info="${yellow} no${normal} [disabled]"
  ret=1
fi
printf "%12s: %s\n" "Xft" "$info" >&2
rm -f $tmpout $tmpsrc $tmpver

if [ "$gs" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmprev=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#include <stdio.h>
#include <stdlib.h>
#include <ghostscript/iapi.h>

int main()
{
    gsapi_revision_t r;
    if (gsapi_revision(&r, sizeof(gsapi_revision_t)) == 0)
        fprintf(stderr, "%ld\n", r.revision);
    exit(0);
}
eof
  cmd="${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -lgs"
  if [ `uname` = "Darwin" ]; then
    cmd="$cmd -L/usr/X11/lib -lXt -lX11 -liconv"
  fi
  $cmd >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    gsdefs="GSDEFS=-DNO_GS GSINC= GSLIBS="
    info="${red} no${normal} [GS API not found]"
    ret=1
  else
    $tmpout >$tmprev 2>&1
    info="${green}yes${normal} [revision `cat $tmprev`]"
  fi
else
  gsdefs="GSDEFS=-DNO_GS GSINC= GSLIBS="
  info="${yellow} no${normal} [disabled]"
  ret=1
fi
printf "%12s: %s\n" "Ghostscript" "$info" >&2
rm -f $tmpout $tmpsrc $tmprev

if [ "$glfw" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmpver=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#include <stdio.h>
#include <GLFW/glfw3.h>

int main(void)
{
    if (!glfwInit())
        return -1;
    fprintf(stderr, "%d.%d.%d\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR,
        GLFW_VERSION_REVISION);
    return 0;
}
eof
  cmd="${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc"
  if [ `uname` = "Darwin" ]; then
    libs="-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo"
    ret=1
  else
    libs="-lGL -lXrandr -lXxf86vm -lXinerama -lXcursor -lXi -lX11 -lrt -lpthread -lm"
  fi
  glfwlib="glfw3"
  $cmd -l$glfwlib $libs >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    glfwlib="glfw"
    $cmd -l$glfwlib $libs >/dev/null 2>&1
  fi
  if [ $? -ne 0 ]; then
    glfwdefs="GLFWDEFS=-DNO_GLFW GLFWLIBS="
    info="${red} no${normal} [GLFW 3.x API not found]"
    ret=1
  else
    glfwdefs="GLFWLIB=$glfwlib"
    $tmpout >$tmpver 2>&1
    info="${green}yes${normal} [version `cat $tmpver`]"
  fi
else
  glfwdefs="GLFWDEFS=-DNO_GLFW GLFWLIBS="
  info="${yellow} no${normal} [disabled]"
  ret=1
fi
printf "%12s: %s\n" "GLFW" "$info" >&2
rm -f $tmpout $tmpsrc $tmpver

if [ "$gl" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  if [ `uname` = "Darwin" ]; then
    cat >$tmpsrc << eof
#include <OpenGL/OpenGL.h>
int main(){
  return 0;
}
eof
    libs="-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo"
    ret=1
  else
    cat >$tmpsrc << eof
#include <GL/gl.h>
int main(){
  return 0;
}
eof
    libs="-lGL -lX11"
  fi
  cmd="${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc"
  $cmd $libs >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    gldefs="GLDEFS=-DNO_GL PLATFORMLIBS="
    info="${red} no${normal} [OpenGL API not found]"
    ret=1
  else
    $tmpout >$tmpver 2>&1
    info="${green}yes${normal}"
  fi
else
  gldefs="GLDEFS=-DNO_GL PLATFORMLIBS="
  info="${yellow} no${normal} [disabled]"
  ret=1
fi
printf "%12s: %s\n" "OpenGL" "$info" >&2
rm -f $tmpout $tmpsrc $tmpver

if [ "$zmq" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmpver=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#include <stdio.h>
#include <zmq.h>

int main(void)
{
    void *context = zmq_ctx_new();
    void *publisher = zmq_socket(context, ZMQ_PUSH);
    if (0) {
        zmq_bind(publisher, "tcp://*:5556");
        zmq_send(publisher, "Hello", 5, 0);
    }
    zmq_close(publisher);
    zmq_ctx_destroy(context);
    fprintf(stderr, "%d.%d.%d\n", ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR,
        ZMQ_VERSION_PATCH);
    return 0;
}
eof
  cmd="${CXX} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -lzmq -lpthread"
  if [ `uname` != "Darwin" ]; then
    cmd="${cmd} -lrt"
  fi
  $cmd >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    zmqdefs="ZMQDEFS=-DNO_ZMQ ZMQLIBS="
    info="${red} no${normal} [0MQ 3.x API not found]"
    ret=1
  else
    $tmpout >$tmpver 2>&1
    info="${green}yes${normal} [version `cat $tmpver`]"
  fi
else
  info="${yellow} no${normal} [disabled]"
  zmqdefs="ZMQDEFS=-DNO_ZMQ ZMQLIBS="
  ret=1
fi
printf "%12s: %s\n" "0MQ" "$info" >&2
rm -f $tmpout $tmpsrc $tmpver

if [ "$av" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmpver=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/mathematics.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
#ifdef __cplusplus
}
#endif
int main(void)
{
  int minimum_version = (57 << 16) + (48 << 8) + 100;
  if (avcodec_version() < minimum_version) {
    /* ffmpeg version is lower than 3.1 */
    return 1;
  }

  const AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_VP8);
  AVCodecContext *ctx = avcodec_alloc_context3(codec);
  avcodec_free_context(&ctx);

  /* av_version_info() is the 'informative version string' but should not be parsed */
  fprintf(stderr, "%s\n", av_version_info());
  return 0;
}
eof
  cmd="${CXX} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -lavformat -lavcodec -lswscale -lavutil -lz"
  cmd_link_encoder="${CXX} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -lavformat -lavcodec -lswscale -lavutil -lz -lvpx -ltheora -logg -lopenh264"
  if [ `uname` = "Linux" ]
  then
    cmd="$cmd -lpthread -lm"
    cmd_link_encoder="$cmd_link_encoder -lpthread -lm"
  elif [ `uname` = "Darwin" ]
  then
    cmd="$cmd -liconv -framework VideoToolbox -framework CoreVideo -framework CoreFoundation -framework CoreServices -framework CoreMedia"
    cmd_link_encoder="$cmd_link_encoder -liconv -framework VideoToolbox -framework CoreVideo -framework CoreFoundation -framework CoreServices -framework CoreMedia"
  fi
  if $cmd >/dev/null 2>&1 && $tmpout >$tmpver 2>&1; then
    info="${green}yes${normal} [version `cat $tmpver | head -1`]"
    avdefs="AVDEFS= AVLIBS=-lavformat AVLIBS+=-lavcodec AVLIBS+=-lswscale AVLIBS+=-lavutil"
  elif $cmd_link_encoder >/dev/null 2>&1 && $tmpout >$tmpver 2>&1; then
    info="${green}yes${normal} [version `cat $tmpver | head -1`, linking encoders]"
    avdefs="AVDEFS= AVLIBS=-lavformat AVLIBS+=-lavcodec AVLIBS+=-lswscale AVLIBS+=-lavutil AVLIBS+=-lvpx AVLIBS+=-ltheora AVLIBS+=-logg AVLIBS+=-lopenh264"
  else
    avdefs="AVDEFS=-DNO_AV AVLIBS="
    info="${red} no${normal} [required APIs not found]"
    ret=1
  fi
else
  avdefs="AVDEFS=-DNO_AV AVLIBS="
  info="${yellow} no${normal} [disabled]"
  ret=1
fi
printf "%12s: %s\n" "ffmpeg" "$info" >&2
rm -f $tmpsrc $tmpout $tmpver

if [ "$cairo" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmpver=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#include <stdio.h>
#include <cairo/cairo.h>

int main(int argc, char **argv) {
    cairo_t *cr;
    cairo_surface_t *surface;

    surface = (cairo_surface_t *) cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 500, 500);
    cr = cairo_create(surface);

    cairo_move_to(cr, 0, 0);
    cairo_line_to(cr, 500, 500);
    cairo_stroke(cr);

    cairo_destroy(cr);
    cairo_surface_destroy(surface);

    puts(CAIRO_VERSION_STRING);

    return 0;
}
eof
  libs="-lm"
  cmd="${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -lcairo -lpixman-1 -lpthread -lfreetype -lz"
  $cmd $libs >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    cairodefs="CAIRODEFS=-DNO_CAIRO CAIROLIBS="
    info="${red} no${normal} [Cairo not found]"
    ret=1
  else
    $tmpout >$tmpver 2>&1
    info="${green}yes${normal} [version `cat $tmpver | head -1`]"
  fi
else
  info="${yellow} no${normal} [disabled]"
  cairodefs="CAIRODEFS=-DNO_CAIRO CAIROLIBS="
  ret=1
fi
printf "%12s: %s\n" "Cairo" "$info" >&2
rm -f $tmpsrc $tmpout $tmpver


if [ "$tiff" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmpver=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#include <stdio.h>
#include <tiffio.h>

int main() {
    puts(TIFFGetVersion());
    return 0;
}
eof
  libs="-lm"
  cmd="${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -ltiff"
  $cmd $libs >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    tiffdefs="TIFFDEFS=-DNO_TIFF TIFFLIBS="
    info="${red} no${normal} [libtiff not found]"
    ret=1
  else
    $tmpout >$tmpver 2>&1
    info="${green}yes${normal} [`cat $tmpver | head -1 | sed s/LIBTIFF,\ Version/version/`]"
  fi
else
  info="${yellow} no${normal} [disabled]"
  tiffdefs="TIFFDEFS=-DNO_TIFF TIFFLIBS="
  ret=1
fi
printf "%12s: %s\n" "libtiff" "$info" >&2
rm -f $tmpsrc $tmpout $tmpver

if [ "$agg" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmpver=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#include <stdio.h>
#include <agg_pixfmt_rgba.h>
#include <agg_renderer_base.h>

typedef agg::pixfmt_alpha_blend_rgba<agg::blender_rgba<agg::rgba8, agg::order_bgra>, agg::rendering_buffer> pix_fmt;
typedef agg::renderer_base<pix_fmt> renderer_base;

int main() {
    renderer_base renderer;
    return 0;
}
eof
  libs="-lm"
  cmd="${CXX} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -lagg"
  $cmd $libs >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    aggdefs="AGGDEFS=-DNO_AGG AGGLIBS="
    info="${red} no${normal} [agg not found]"
    ret=1
  else
    $tmpout >$tmpver 2>&1
    info="${green}yes${normal}"
  fi
else
  info="${yellow} no${normal} [disabled]"
  aggdefs="AGGDEFS=-DNO_AGG AGGLIBS="
  ret=1
fi
printf "%12s: %s\n" "agg" "$info" >&2
rm -f $tmpsrc $tmpout $tmpver

if [ "$xerces" != "no" ]
then
  tmpout=`mktemp /tmp/a.out.XXXXX`
  tmpsrc=`mktemp /tmp/a$$XXXXX.c`
  tmpver=`mktemp /tmp/a$$XXXXX.txt`
  cat >$tmpsrc << eof
#include <stdio.h>
#include <xercesc/util/XercesVersion.hpp>

int main(void) {
    const char *version = XERCES_FULLVERSIONDOT;
    printf("%s\n", version);
    return 0;
}
eof
  if [ "`which pkg-config 2>/dev/null`" != "" ]; then
    xercesc_cflags="`pkg-config xerces-c --cflags 2>/dev/null`"
    xercesc_libs="`pkg-config xerces-c --libs 2>/dev/null`"
  else
    xercesc_cflags=""
    xercesc_libs=""
  fi
  cmd="${CXX} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc $xercesc_cflags"
  $cmd $xercesc_libs >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    xercescdefs="XERCESCDEFS=-DNO_XERCES_C XERCESCINC= XERCESCLIBS="
    info="${red} no${normal} [xercesc not found]"
    ret=1
  else
    $tmpout >$tmpver 2>&1
    xercescdefs=""
    if [ -n "$xercesc_cflags" ]; then
      xercescdefs="${xercescdefs} XERCESCINC=${xercesc_cflags}"
    fi
    if [ -n "$xercesc_libs" ]; then
      xercescdefs="${xercescdefs} XERCESCLIBS=${xercesc_libs}"
    fi
    # Remove a trailing space
    xercescdefs="${xercescdefs# }"
    info="${green}yes${normal} [version `cat $tmpver`]"
  fi
else
  info="${yellow} no${normal} [disabled]"
  xercescdefs="XERCESCDEFS=-DNO_XERCES_C XERCESCINC= XERCESCLIBS="
  ret=1
fi
printf "%12s: %s\n" "Xerces-C++" "$info" >&2
rm -f $tmpsrc $tmpout $tmpver

echo "" >&2
echo $target $wxdefs $qt4defs $qt5defs $qt6defs $gtkdefs $x11defs $xftdefs $gsdefs $glfwdefs $gldefs $zmqdefs $avdefs $cairodefs $tiffdefs $aggdefs $xercescdefs $extradefs