summaryrefslogtreecommitdiff
path: root/tools/test_scripts/testheaders.sh
blob: 927356e842840d11d528d2b2345eb08c2bd97378 (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
#!/bin/bash

# Compile each header file, one at a time.
# The compiler will notice if a header file does not include all other header
# files that it depends on.

# Example: In glibmm, go to directory glibmm, and run
#   tools/test_scripts/testheaders.sh -I glib giomm-2.68 gio # compile glibmm/gio/giomm/*.h
#   tools/test_scripts/testheaders.sh giomm-2.68 glib gio    # compile glibmm/glib/glibmm/*.h and glibmm/gio/giomm/*.h
#   tools/test_scripts/testheaders.sh -I glib glibmm-2.68 glib/glibmm/ustring.h # compile glibmm/glib/glibmm/ustring.h

# Usage: testheaders.sh [-I<dir>]... <pkg> [<dir> | <file>]...
# -I<dir> is added to the compiler flags.
# <pkg> is the name of the package, given to pkg-config.

function usage() {
  echo "Usage: $0 [-I<dir>]... <pkg> [<dir> | <file>]..."
  exit 1
}

# Compiler, default: CXX=g++
if test "x$CXX" = x
then
  CXX=g++
fi

# Extra compiler flags, default: CXXFLAGS=-std=c++17
if test "x$CXXFLAGS" = x
then
  CXXFLAGS=-std=c++17
fi

# Search for directories to include in CFLAGS.
idirs=""
while [ $# -gt 0 ]
do
  case "$1" in
    -I) if [ $# -lt 2 ]
        then
          usage
        fi
        idirs+=" -I$2"
        shift; shift
        ;;
    -I*) idirs+=" $1"
         shift
         ;;
    -*) echo "Illegal option: $1"
        usage
        ;;
    *) break
       ;;
  esac
done

# Package name
if [ $# -lt 1 ]
then
  echo "No package name"
  usage
fi
pkg="$1"
shift

# Search for more directories to include in CFLAGS.
for i in "$@"
do
  if [ -d "$i" ]
  then
    idirs+=" -I$i"
  fi
done

CFLAGS="$idirs `pkg-config --cflags $pkg`"
if [ $? -ne 0 ]
then
  echo "pkg-config failed"
  usage
fi
echo CXX=$CXX, CXXFLAGS=$CXXFLAGS
echo CFLAGS=$CFLAGS

# Compile the specified files
for i in "$@"
do
  if [ -d "$i" ]
  then
    for headerfile in $i/${i}mm/*.h
    do
      echo "=== $headerfile"
      $CXX -c -x c++ $CXXFLAGS -o /dev/null $headerfile $CFLAGS
    done
  else
    echo "=== $i"
    $CXX -c -x c++ $CXXFLAGS -o /dev/null $i $CFLAGS
  fi
done