Created
December 27, 2014 23:51
-
-
Save dkorolev/7bc22c01732831a78c31 to your computer and use it in GitHub Desktop.
check-headers.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Checks that every header can be compiled independently. | |
# | |
# Compiles each header with g++ and clang++, then links them all together | |
# to confirm the one-definition-rule is not violated, i.e., all the | |
# `inline`-s are set and the library really is header-only. | |
set -u -e | |
CPPFLAGS="-std=c++11 -g -Wall -W" | |
LDFLAGS="-pthread" | |
TMPDIR=.tmp | |
rm -rf $TMPDIR/headers | |
mkdir -p $TMPDIR/headers | |
echo -e -n "\033[1mCompiling\033[0m:\033[36m" | |
for i in *.h ; do | |
echo -n " $i" | |
ln -sf $PWD/$i $PWD/$TMPDIR/headers/$i.g++.cc | |
ln -sf $PWD/$i $PWD/$TMPDIR/headers/$i.clang++.cc | |
g++ -I . ${CPPFLAGS} -c $PWD/$TMPDIR/headers/$i.g++.cc -o $PWD/$TMPDIR/headers/$i.g++.o ${LDFLAGS} | |
clang++ -I . ${CPPFLAGS} -c $PWD/$TMPDIR/headers/$i.clang++.cc -o $PWD/$TMPDIR/headers/$i.clang++.o ${LDFLAGS} | |
done | |
echo | |
echo -e -n "\033[0m\033[1mLinking\033[0m:\033[1m\033[32m " | |
echo -e '#include <cstdio>\nint main() { printf("OK\\n"); }\n' >$TMPDIR/headers/main.cc | |
g++ -c $CPPFLAGS -o $TMPDIR/headers/main.o $TMPDIR/headers/main.cc $LDFLAGS | |
gcc -o $TMPDIR/headers/main $TMPDIR/headers/*.o $LDFLAGS | |
$TMPDIR/headers/main | |
echo -e -n "\033[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment