Skip to content

Commit 09edcb6

Browse files
committed
selfcheck.sh: also run with system includes made available
1 parent 40251d2 commit 09edcb6

File tree

2 files changed

+104
-4
lines changed

2 files changed

+104
-4
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: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,111 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
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" ] || [ "$cxx_type" = "Debian" ]; then
19+
cxx_type=$($CXX --version | head -1 | cut -d' ' -f2)
20+
fi
21+
22+
# TODO: generate defines from compiler
23+
if [ "$cxx_type" = "g++" ]; then
24+
defs=
25+
defs="$defs -D__GNUC__"
26+
defs="$defs -D__STDC__"
27+
defs="$defs -D__x86_64__"
28+
defs="$defs -D__STDC_HOSTED__"
29+
defs="$defs -D__CHAR_BIT__=8"
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+
34+
inc=
35+
while read line
36+
do
37+
inc="$inc -I$line"
38+
done <<< "$($CXX -x c++ -v -c -S - 2>&1 < /dev/null | grep -e'^ [/A-Z]' | grep -v /cc1plus)"
39+
elif [ "$cxx_type" = "clang" ]; then
40+
# libstdc++
41+
defs=
42+
defs="$defs -D__x86_64__"
43+
defs="$defs -D__STDC_HOSTED__"
44+
defs="$defs -D__CHAR_BIT__=8"
45+
defs="$defs -D__has_builtin(x)=(1)"
46+
defs="$defs -D__has_cpp_attribute(x)=(1)"
47+
defs="$defs -D__has_feature(x)=(1)"
48+
defs="$defs -D__has_include_next(x)=(0)"
49+
defs="$defs -D__has_attribute(x)=(0)"
50+
defs="$defs -D__building_module(x)=(0)"
51+
52+
inc=
53+
while read line
54+
do
55+
inc="$inc -I$line"
56+
done <<< "$($CXX -x c++ -v -c -S - 2>&1 < /dev/null | grep -e'^ [/A-Z]')"
57+
58+
# TODO: enable
59+
# libc++
60+
#defs=
61+
#defs="$defs -D__x86_64__"
62+
#defs="$defs -D__linux__"
63+
#defs="$defs -D__SIZEOF_SIZE_T__=8"
64+
#defs="$defs -D__has_include_next(x)=(0)"
65+
#defs="$defs -D__has_builtin(x)=(1)"
66+
#defs="$defs -D__has_feature(x)=(1)"
67+
68+
#inc=
69+
#while read line
70+
#do
71+
# inc="$inc -I$line"
72+
#done <<< "$($CXX -x c++ -stdlib=libc++ -v -c -S - 2>&1 < /dev/null | grep -e'^ [/A-Z]')"
73+
elif [ "$cxx_type" = "Apple" ]; then
74+
defs=
75+
defs="$defs -D__BYTE_ORDER__"
76+
defs="$defs -D__APPLE__"
77+
defs="$defs -D__GNUC__=15"
78+
defs="$defs -D__x86_64__"
79+
defs="$defs -D__SIZEOF_SIZE_T__=8"
80+
defs="$defs -D__LITTLE_ENDIAN__"
81+
defs="$defs -D__has_feature(x)=(0)"
82+
defs="$defs -D__has_extension(x)=(1)"
83+
defs="$defs -D__has_attribute(x)=(0)"
84+
defs="$defs -D__has_cpp_attribute(x)=(0)"
85+
defs="$defs -D__has_include_next(x)=(0)"
86+
defs="$defs -D__has_builtin(x)=(1)"
87+
defs="$defs -D__is_target_os(x)=(0)"
88+
defs="$defs -D__is_target_arch(x)=(0)"
89+
defs="$defs -D__is_target_vendor(x)=(0)"
90+
defs="$defs -D__is_target_environment(x)=(0)"
91+
defs="$defs -D__is_target_variant_os(x)=(0)"
92+
defs="$defs -D__is_target_variant_environment(x)=(0)"
93+
94+
inc=
95+
while read line
96+
do
97+
inc="$inc -I$line"
98+
# TODO: pass the framework path as such when possible
99+
done <<< "$($CXX -x c++ -v -c -S - 2>&1 < /dev/null | grep -e'^ [/A-Z]' | sed 's/ (framework directory)//g')"
100+
echo $inc
101+
else
102+
echo "unknown compiler '$cxx_type'"
103+
exit 1
104+
fi
105+
106+
# run with -std=gnuc++* so __has_include(...) is available
107+
./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc
108+
ec=$?
109+
if [ $ec -ne 0 ]; then
110+
exit $ec
111+
fi

0 commit comments

Comments
 (0)