Created
August 19, 2018 19:33
-
-
Save Gydo194/e4b685ff5198619ed978f59422f4a2d2 to your computer and use it in GitHub Desktop.
C/C++ auto-compile shell script
This file contains hidden or 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 | |
COMPILER="/usr/bin/gcc"; | |
OPTIONS="-c -o"; | |
FINAL_OPTIONS="-o"; | |
MAIN_FILENAME="main"; | |
BUILDDIR="build"; | |
SRCDIR="src"; | |
EXTENSION="*.c"; | |
OBJECT_EXTENSION="o"; | |
if [ -d "$BUILDDIR" ]; then | |
echo "Cleaning build directory..." | |
rm $BUILDDIR/* 2>&1 > /dev/null; | |
else | |
echo "Making build directory..." | |
mkdir $BUILDDIR; | |
fi | |
echo "Finding source files..." | |
FILES=`find "$SRCDIR" -type f -name "$EXTENSION"` | |
echo "Found source files: $FILES" | |
echo "Compiling source files..." | |
for i in $FILES | |
do | |
OUTFILE=`basename "${i%.*}"`; | |
OUTFILE="$BUILDDIR/$OUTFILE.o"; | |
echo "Compiling file \"$i\" to \"$OUTFILE\""; | |
$COMPILER $OPTIONS $OUTFILE $i; | |
done | |
echo "Linking Object Files..."; | |
$COMPILER $FINAL_OPTIONS $MAIN_FILENAME $BUILDDIR/*; | |
echo "Done."; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment