Skip to content

Commit e53b8c4

Browse files
committed
selfcheck.sh: also run with system includes made available
1 parent cfd1797 commit e53b8c4

2 files changed

Lines changed: 71 additions & 3 deletions

File tree

Makefile

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

1818
selfcheck: simplecpp
19-
./selfcheck.sh
19+
CXX=$(CXX) ./selfcheck.sh
2020

2121
simplecpp: main.o simplecpp.o
2222
$(CXX) $(LDFLAGS) main.o simplecpp.o -o simplecpp

selfcheck.sh

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,76 @@ 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__has_builtin(x)=(1)"
30+
defs="$defs -D__has_cpp_attribute(x)=(1)"
31+
defs="$defs -D__has_attribute(x)=(1)"
32+
# some required include paths might differ per distro
33+
inc=
34+
inc="$inc -I/usr/include"
35+
inc="$inc -I/usr/include/linux"
36+
inc="$inc -I/usr/include/c++/$gcc_ver"
37+
inc="$inc -I/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu"
38+
inc="$inc -I/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include"
39+
if [ -d "/usr/include/x86_64-linux-gnu" ]; then
40+
inc="inc -I/usr/include/x86_64-linux-gnu/c++/$gcc_ver"
41+
fi
42+
./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc
43+
ec=$?
44+
if [ $ec -ne 0 ]; then
45+
exit $ec
46+
fi
47+
elif [ "$cxx_type" = "clang" ]; then
48+
clang_ver=$($CXX -dumpversion)
49+
clang_ver=${clang_ver%%.*}
50+
find /usr/include -name stubs-32.h
51+
cxx_inc="/usr/include/c++/v1"
52+
if [ ! -d "$cxx_inc" ]; then
53+
cxx_inc="/usr/lib/llvm-$clang_ver/include/c++/v1"
54+
fi
55+
# some required include paths might differ per distro
56+
extra_inc=
57+
if [ -d "/usr/include/x86_64-linux-gnu" ]; then
58+
extra_inc="$extra_inc -I/usr/include/x86_64-linux-gnu"
59+
fi
60+
./simplecpp simplecpp.cpp -e -f -std=gnu++11 -D__BYTE_ORDER__ -D__linux__ -D"__has_feature(x)=(1)" -D"__has_extension(x)=(1)" -D"__has_attribute(x)=(0)" -D"__has_cpp_attribute(x)=(0)" -D"__has_include_next(x)=(0)" -D"__has_builtin(x)=(1)" -I"$cxx_inc" -I"/usr/include" -I"/usr/lib/clang/$clang_ver/include" $extra_inc
61+
ec=$?
62+
if [ $ec -ne 0 ]; then
63+
exit $ec
64+
fi
65+
elif [ "$cxx_type" = "Apple" ]; then
66+
find /Applications -name endian.h
67+
xcode_path="/Applications/Xcode_16.4.app"
68+
if [ ! -d "$xcode_path" ]; then
69+
xcode_path="/Applications/Xcode_15.2.app"
70+
fi
71+
./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"
72+
ec=$?
73+
if [ $ec -ne 0 ]; then
74+
exit $ec
75+
fi
76+
else
77+
echo "unknown compiler '$cxx_type'"
78+
exit 1
79+
fi

0 commit comments

Comments
 (0)