Skip to content

Commit 96f2ec1

Browse files
committed
selfcheck.sh: also run with system includes made available
1 parent cf65a2f commit 96f2ec1

File tree

2 files changed

+112
-3
lines changed

2 files changed

+112
-3
lines changed

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: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,117 @@ 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+
elif [ "$cxx_type" = "clang" ]; then
52+
clang_ver=$($CXX -dumpversion)
53+
clang_ver=${clang_ver%%.*}
54+
defs=
55+
defs="$defs -D__BYTE_ORDER__"
56+
defs="$defs -D__linux__"
57+
defs="$defs -D__x86_64__"
58+
defs="$defs -D__SIZEOF_SIZE_T__=8"
59+
defs="$defs -D__has_feature(x)=(1)"
60+
defs="$defs -D__has_extension(x)=(1)"
61+
defs="$defs -D__has_attribute(x)=(0)"
62+
defs="$defs -D__has_cpp_attribute(x)=(0)"
63+
defs="$defs -D__has_include_next(x)=(0)"
64+
defs="$defs -D__has_builtin(x)=(1)"
65+
# some required include paths might differ per distro
66+
inc=
67+
if [ -d "/usr/include/c++/v1" ]; then
68+
inc="$inc -I/usr/include/c++/v1"
69+
fi
70+
if [ -d "/usr/lib/llvm-$clang_ver/include/c++/v1" ]; then
71+
inc="$inc -I/usr/lib/llvm-$clang_ver/include/c++/v1"
72+
fi
73+
inc="$inc -I/usr/include"
74+
inc="$inc -I/usr/lib/clang/$clang_ver/include"
75+
if [ -d "/usr/include/x86_64-linux-gnu" ]; then
76+
inc="$inc -I/usr/include/x86_64-linux-gnu"
77+
fi
78+
elif [ "$cxx_type" = "Apple" ]; then
79+
appleclang_ver=$($CXX -dumpversion)
80+
appleclang_ver=${appleclang_ver%%.*}
81+
xcode_path="/Applications/Xcode_16.4.app"
82+
if [ ! -d "$xcode_path" ]; then
83+
xcode_path="/Applications/Xcode_15.2.app"
84+
fi
85+
sdk_path="$xcode_path/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
86+
defs=
87+
defs="$defs -D__BYTE_ORDER__"
88+
defs="$defs -D__APPLE__"
89+
defs="$defs -D__GNUC__=15"
90+
defs="$defs -D__x86_64__"
91+
defs="$defs -D__SIZEOF_SIZE_T__=8"
92+
defs="$defs -D__has_feature(x)=(0)"
93+
defs="$defs -D__has_extension(x)=(1)"
94+
defs="$defs -D__has_attribute(x)=(0)"
95+
defs="$defs -D__has_cpp_attribute(x)=(0)"
96+
defs="$defs -D__has_include_next(x)=(0)"
97+
defs="$defs -D__has_builtin(x)=(1)"
98+
defs="$defs -D__is_target_os(x)=(0)"
99+
defs="$defs -D__is_target_arch(x)=(0)"
100+
defs="$defs -D__is_target_vendor(x)=(0)"
101+
defs="$defs -D__is_target_environment(x)=(0)"
102+
defs="$defs -D__is_target_variant_os(x)=(0)"
103+
defs="$defs -D__is_target_variant_environment(x)=(0)"
104+
inc=
105+
inc="$inc -I$sdk_path/usr/include/c++/v1"
106+
inc="$inc -I$sdk_path/usr/include"
107+
inc="$inc -I$sdk_path/usr/include/i386"
108+
if [ -d "$xcode_path/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/$appleclang_ver/include" ]; then
109+
inc="$inc -I$xcode_path/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/$appleclang_ver/include"
110+
fi
111+
else
112+
echo "unknown compiler '$cxx_type'"
113+
exit 1
114+
fi
115+
116+
./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc
117+
ec=$?
118+
if [ $ec -ne 0 ]; then
119+
exit $ec
120+
fi

0 commit comments

Comments
 (0)