mirror of
https://github.com/SileNce5k/jscripts.git
synced 2025-04-19 19:16:18 +02:00
Add build.sh
A script that builds each C and C++ file into their own executables
This commit is contained in:
parent
117ab9b1c7
commit
3b899a2a30
1 changed files with 68 additions and 0 deletions
68
build.sh
Normal file
68
build.sh
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
CXX=${CXX:-g++}
|
||||||
|
CC=${CC:-gcc}
|
||||||
|
CFLAGS=${CFLAGS:-}
|
||||||
|
CXXFLAGS=${CXXFLAGS:-}
|
||||||
|
|
||||||
|
compile_c_files() {
|
||||||
|
local strict=$1
|
||||||
|
for file in *.c; do
|
||||||
|
if [[ -f "$file" ]]; then
|
||||||
|
filename=$(basename "$file")
|
||||||
|
extension="${filename##*.}"
|
||||||
|
filename="${filename%.*}"
|
||||||
|
executable="c_$filename"
|
||||||
|
if [[ "$file" -nt "$executable" ]]; then
|
||||||
|
if $CC $CFLAGS $strict -o "$executable" "$file"; then
|
||||||
|
if [[ "$OSTYPE" == "msys" ]]; then
|
||||||
|
executable="$executable.exe"
|
||||||
|
fi
|
||||||
|
echo "Compiled $file to $executable"
|
||||||
|
else
|
||||||
|
echo -e "\e[31mCompilation failed for $file\e[0m"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$file is up to date"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
compile_cpp_files() {
|
||||||
|
local strict=$1
|
||||||
|
for file in *.cpp; do
|
||||||
|
if [[ -f "$file" ]]; then
|
||||||
|
filename=$(basename "$file")
|
||||||
|
extension="${filename##*.}"
|
||||||
|
filename="${filename%.*}"
|
||||||
|
executable="cpp_$filename"
|
||||||
|
if [[ "$file" -nt "$executable" ]]; then
|
||||||
|
if $CXX $CXXFLAGS $strict -o "$executable" "$file"; then
|
||||||
|
if [[ "$OSTYPE" == "msys" ]]; then
|
||||||
|
executable="$executable.exe"
|
||||||
|
fi
|
||||||
|
echo "Compiled $file to $executable"
|
||||||
|
else
|
||||||
|
echo -e "\e[31mCompilation failed for $file\e[0m"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$file is up to date"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [[ "$1" == "--strict" ]]; then
|
||||||
|
strict="-pedantic -Werror -Wall -Wextra"
|
||||||
|
else
|
||||||
|
strict=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
compile_c_files "$strict"
|
||||||
|
|
||||||
|
|
||||||
|
compile_cpp_files "$strict"
|
Loading…
Add table
Reference in a new issue