Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

Commit

Permalink
gcc-4.8: post-link.sh: Added a test step, so users know right away if…
Browse files Browse the repository at this point in the history
… the gcc package doesn't work on their system.
  • Loading branch information
stuarteberg committed May 4, 2015
1 parent 2d63e2c commit 9bd7451
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion gcc-4.8/post-link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if [ "$(uname)" != "Darwin" ]; then
for obj_file in $C_RUNTIME_OBJ_FILES; do
obj_file_full_path=`gcc -print-file-name=$obj_file`
if [[ $obj_file_full_path != $obj_file ]]; then
ln -s $obj_file_full_path ${PREFIX}/lib/gcc/*/*/
ln -f -s $obj_file_full_path ${PREFIX}/lib/gcc/*/*/
fi
done

Expand All @@ -38,3 +38,62 @@ if [ "$(uname)" != "Darwin" ]; then
sed -i ':a;N;$!ba;s|\(*cpp:\n[^\n]*\)|\1 -I'${INCDIR}'|g' ${SPECS_FILE}
done
fi

## TEST: Here we verify that gcc can build a simple "Hello world" program for both C and C++.
##
## Note: This tests the gcc package's ability to actually function as a compiler.
## Therefore, packages should never depend on the gcc package as a 'run' dependency,
## i.e. just for its packaged libraries (they should depend on 'libgcc' instead).
## That way, if there are systems which can't use this gcc package for its
## compiler (due to portability issues) can still use packages produced with it.

workdir=`mktemp -d` && cd $workdir

# Write test programs.
cat > hello.c <<EOF
#include <stdio.h>
int main()
{
printf("Hello, world! I can compile C.\n");
return 0;
}
EOF

cat > hello.cpp <<EOF
#include <iostream>
int main()
{
std::cout << "Hello, world! I can compile C++." << std::endl;
return 0;
}
EOF

set +e

# Compile.
(
set -e
gcc -o hello_c.out hello.c
g++ -o hello_cpp.out hello.cpp
)
SUCCESS=$?
if [ $SUCCESS -ne 0 ]; then
echo "Installation failed: gcc is not able to compile a simple 'Hello, World' program."
rm -r $workdir
exit 1;
fi

# Execute the compiled output.
(
set -e
./hello_c.out > /dev/null
./hello_cpp.out > /dev/null
)
SUCCESS=$?
if [ $SUCCESS -ne 0 ]; then
echo "Installation failed: Compiled test program did not execute cleanly."
rm -r $workdir
exit 1;
fi

rm -r $workdir

0 comments on commit 9bd7451

Please sign in to comment.