Skip to content

Commit edd48f1

Browse files
committed
selfcheck.sh: also run with system includes made available
1 parent 4056cd5 commit edd48f1

2 files changed

Lines changed: 94 additions & 3 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test: testrunner simplecpp
2222
python3 -m pytest integration_test.py -vv
2323

2424
selfcheck: simplecpp
25-
./selfcheck.sh
25+
CXX=$(CXX) ./selfcheck.sh
2626

2727
simplecpp: main.o simplecpp.o
2828
$(CXX) $(LDFLAGS) main.o simplecpp.o -o simplecpp

selfcheck.sh

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,99 @@ output=$(./simplecpp simplecpp.cpp -e -f 2>&1)
44
ec=$?
55
errors=$(echo "$output" | grep -v 'Header not found: <')
66
if [ $ec -ne 0 ]; then
7-
# only fail if got errors which do not refer to missing system includes
7+
# only fail if we got errors which do not refer to missing system includes
88
if [ ! -z "$errors" ]; then
99
exit $ec
1010
fi
11-
fi
11+
fi
12+
13+
if [ -z "$CXX" ]; then
14+
exit 0
15+
fi
16+
17+
cxx_type=$($CXX --version | head -1 | cut -d' ' -f1)
18+
if [ "$cxx_type" = "Ubuntu" ]; then
19+
cxx_type=$($CXX --version | head -1 | cut -d' ' -f2)
20+
fi
21+
# TODO: how to get built-in include paths from compiler?
22+
if [ "$cxx_type" = "g++" ]; then
23+
gcc_ver=$($CXX -dumpversion)
24+
defs=
25+
defs="$defs -D__GNUC__"
26+
defs="$defs -D__STDC__"
27+
defs="$defs -D__STDC_HOSTED__"
28+
defs="$defs -D__CHAR_BIT__=8"
29+
defs="$defs -D__x86_64__"
30+
defs="$defs -D__has_builtin(x)=(1)"
31+
defs="$defs -D__has_cpp_attribute(x)=(1)"
32+
defs="$defs -D__has_attribute(x)=(1)"
33+
# some required include paths might differ per distro
34+
inc=
35+
inc="$inc -I/usr/include"
36+
inc="$inc -I/usr/include/linux"
37+
inc="$inc -I/usr/include/c++/$gcc_ver"
38+
if [ -d "/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" ]; then
39+
inc="$inc -I/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu"
40+
fi
41+
if [ -d "/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include" ]; then
42+
inc="$inc -I/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include"
43+
fi
44+
if [ -d "/usr/lib/gcc/x86_64-linux-gnu/$gcc_ver/include" ]; then
45+
inc="$inc -I/usr/lib/gcc/x86_64-linux-gnu/$gcc_ver/include"
46+
fi
47+
if [ -d "/usr/include/x86_64-linux-gnu" ]; then
48+
inc="$inc -I/usr/include/x86_64-linux-gnu"
49+
inc="$inc -I/usr/include/x86_64-linux-gnu/c++/$gcc_ver"
50+
fi
51+
./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc
52+
ec=$?
53+
if [ $ec -ne 0 ]; then
54+
exit $ec
55+
fi
56+
elif [ "$cxx_type" = "clang" ]; then
57+
clang_ver=$($CXX -dumpversion)
58+
clang_ver=${clang_ver%%.*}
59+
find /usr/include -name cctype
60+
defs=
61+
defs="$defs -D__BYTE_ORDER__"
62+
defs="$defs -D__linux__"
63+
defs="$defs -D__x86_64__"
64+
defs="$defs -D__SIZEOF_SIZE_T__=8"
65+
defs="$defs -D__has_feature(x)=(1)"
66+
defs="$defs -D__has_extension(x)=(1)"
67+
defs="$defs -D__has_attribute(x)=(0)"
68+
defs="$defs -D__has_cpp_attribute(x)=(0)"
69+
defs="$defs -D__has_include_next(x)=(0)"
70+
defs="$defs -D__has_builtin(x)=(1)"
71+
# some required include paths might differ per distro
72+
inc=
73+
if [ -d "/usr/include/c++/v1" ]; then
74+
inc="$inc -I/usr/include/c++/v1"
75+
elif [ -d "/usr/include/c++/$clang_ver" ]; then
76+
inc="$inc -I/usr/include/c++/$clang_ver"
77+
fi
78+
inc="$inc -I/usr/include"
79+
inc="$inc -I/usr/lib/clang/$clang_ver/include"
80+
if [ -d "/usr/include/x86_64-linux-gnu" ]; then
81+
inc="$inc -I/usr/include/x86_64-linux-gnu"
82+
fi
83+
./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc
84+
ec=$?
85+
if [ $ec -ne 0 ]; then
86+
exit $ec
87+
fi
88+
elif [ "$cxx_type" = "Apple" ]; then
89+
find /Applications -name endian.h
90+
xcode_path="/Applications/Xcode_16.4.app"
91+
if [ ! -d "$xcode_path" ]; then
92+
xcode_path="/Applications/Xcode_15.2.app"
93+
fi
94+
./simplecpp simplecpp.cpp -e -f -std=gnu++11 -D__BYTE_ORDER__ -D__APPLE__ -I"$xcode_path/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" -I"$xcode_path/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
95+
ec=$?
96+
if [ $ec -ne 0 ]; then
97+
exit $ec
98+
fi
99+
else
100+
echo "unknown compiler '$cxx_type'"
101+
exit 1
102+
fi

0 commit comments

Comments
 (0)