Created
March 17, 2020 04:55
-
-
Save jaasonw/e912ec69f96a0ef2b11e47ce02f1519b to your computer and use it in GitHub Desktop.
builds small c++ projects, rewritten in bash so python is no longer required
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 | |
# a simple build script suitable for compiling small projects | |
# written by jason wong | |
COMPILER="g++" | |
MAIN="main.cpp" | |
EXECUTABLE="a.exe" | |
# include and source directories | |
INCLUDES=( include ) | |
SOURCES=( src ) | |
LINK=( ) | |
# compiler flags | |
FLAGS=( | |
-std=c++11 | |
-Wall | |
-Wextra | |
) | |
# you can ignore the rest of these | |
flag_str="" | |
for f in "${FLAGS[@]}"; do | |
flag_str="$flag_str $f" | |
done | |
include="" | |
for i in "${INCLUDES[@]}"; do | |
include="$include -I\"$i/\"" | |
done | |
sources="" | |
for directory in "${SOURCES[@]}"; do | |
srcs=($(find ./$directory/ -type f | cut -d/ -f2-)) | |
for src in "${srcs[@]}"; do | |
sources="$sources \"$src\"" | |
done | |
done | |
link="" | |
for l in "${LINK[@]}"; do | |
link="$link -l$l" | |
done | |
cmd="$COMPILER $flag_str $include -o $EXECUTABLE $MAIN $sources $link" | |
echo $cmd | |
t1=$SECONDS | |
eval $cmd | |
t2=$SECONDS | |
duration=$(( t2 - t1 )) | |
echo "Operation time Elapsed: $duration seconds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment