Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimmak23 committed Jan 30, 2025
2 parents 8308076 + 9ddfd8b commit cd8fe1f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 71 deletions.
3 changes: 2 additions & 1 deletion SDL2_connector/cmake_modules/FetchSDL2Packages.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE) # ? To allow cmake print intermidiate comments
set(FETCHCONTENT_QUIET TRUE)
# set(FETCHCONTENT_QUIET FALSE) # ? To allow cmake print intermidiate comments

# ? Define SDL version and URLs
set(SDL_VERSION "2.30.2") # 2.3.11
Expand Down
92 changes: 54 additions & 38 deletions scripts/bash/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Parameters
# ? Parameters
rebuild=""
config=""
generator=""
Expand Down Expand Up @@ -31,38 +31,21 @@ while [[ $# -gt 0 ]]; do
esac
done

# Validate conflicting options
# ? Validate conflicting options
if { [[ -n "$generator" || -n "$config" ]] && [[ -n "$rebuild" ]]; }; then
echo "Wrong command. '--rebuild' can't be used with '--config' and/or '--generator'."
exit 1
fi

# Define the path to the JSON file
jsonFilePath="build_data.json"

# If NO JSON file exists: create default
if [[ ! -f "$jsonFilePath" ]]; then
echo "Data about previous build not found. Going with 'Ninja' on 'Debug'..."
bash ./scripts/bash/sub_scripts/re_config_all.sh "$jsonFilePath" "Debug" "Ninja"
bash ./scripts/bash/sub_scripts/re_build_game.sh "Debug" "Ninja"
exit 0
fi

# Read and parse the JSON file
jsonData=$(cat "$jsonFilePath")
currentConfig=$(echo "$jsonData" | jq -r '.Config')
currentGenerator=$(echo "$jsonData" | jq -r '.Generator')

# Validate generator
# ? Validate generator
if [[ -n "$generator" ]]; then
case "$generator" in
Ninja)
echo "Specified $generator as generator."
;;
Makefiles)
if [[ "$(uname -s)" == "Linux" || "$(uname -s)" == "Darwin" ]]; then
# generator="Unix Makefiles" #TODO: Currently some problems with such generator, why?
generator="Ninja"
generator="Unix Makefiles"
elif [[ "$(uname -s)" == "MINGW"* || "$(uname -s)" == "MSYS"* || "$(uname -s)" == "CYGWIN"* ]]; then
generator="MinGW Makefiles"
else
Expand All @@ -73,7 +56,7 @@ if [[ -n "$generator" ]]; then
;;
VS)
if [[ "$(uname -s)" == "Linux" || "$(uname -s)" == "Darwin" ]]; then
echo "Using Ninja instread of Visual Studio..."
echo "Using Ninja instead of Visual Studio..."
generator="Ninja"
elif [[ "$(uname -s)" == "MINGW"* || "$(uname -s)" == "MSYS"* || "$(uname -s)" == "CYGWIN"* ]]; then
generator="Visual Studio 17 2022"
Expand All @@ -84,50 +67,78 @@ if [[ -n "$generator" ]]; then
echo "Specified $generator as generator."
;;
*)
echo "Invalid generator specified: $generator. Using 'Ninja' as default..."
generator="Ninja"
echo "Invalid generator specified: $generator. Checking previous built data, if have any..."
;;
esac
else
generator="$currentGenerator"
echo "Continue to use $generator as generator..."
echo "No generator specified! Checking previous built data, if have any..."
fi

# Validate config
if [[ -n "$config" && "$config" != "Debug" && "$config" != "Release" ]]; then
echo "Couldn't proceed with --config $config option. Using '$currentConfig' as before..."
config="$currentConfig"
# ? Validate config
if [[ "$config" != "Debug" && "$config" != "Release" ]]; then
echo "No or corrupt config have been provided. Using previous config instead if we have any..."
fi

# Handle combinations of parameters
# ? Define the path to the JSON file
jsonFilePath="build_data.json"

# ? If NO JSON file exists: create default
if [[ ! -f "$jsonFilePath" ]]; then
echo "Checking built data... Data about previous build not found. 'Debug' and 'Ninja' will be written as built data."
bash ./scripts/bash/sub_scripts/create_build_data.sh "$jsonFilePath" "Debug" "Ninja"
fi

# ? In any case we have built data now
jsonData=$(cat "$jsonFilePath")
currentConfig=$(echo "$jsonData" | jq -r '.Config')
currentGenerator=$(echo "$jsonData" | jq -r '.Generator')

# ^ Handle combinations of parameters

# * build.sh
# ? Doing this only when 'config' and 'generator' parameters didn't provided
if [[ -z "$rebuild" && -z "$config" && -z "$generator" ]]; then
echo "command were: 'bash.sh'. Going with data about previous built: --config $currentConfig --generator $currentGenerator"
bash ./scripts/bash/sub_scripts/re_config_all.sh "$jsonFilePath" "$currentConfig" "$currentGenerator"
bash ./scripts/bash/sub_scripts/re_build_game.sh "$currentConfig" "$currentGenerator"
exit 0
fi

# * build.sh --config 'Debug'/'Release'
# ? Check if new configuration: re-configure all with same generator
if [[ -n "$config" && -z "$generator" ]]; then
if [[ "$config" != "$currentConfig" ]]; then
echo "command were: 'bash.sh --config $config'"
echo "Configuration changed to: $config."
bash ./scripts/bash/sub_scripts/re_config_all.sh "$jsonFilePath" "$config" "$currentGenerator"
bash ./scripts/bash/sub_scripts/re_build_game.sh "$config" "$currentGenerator"
exit 0
else
bash ./scripts/bash/sub_scripts/re_build_game.sh "$currentConfig" "$currentGenerator"
bash ./scripts/bash/sub_scripts/re_build_game.sh "$config" "$currentGenerator"
exit 0
fi
fi

# * build.sh --generator 'Ninja'/'Makefiles'/'VS'
# ? Check if new generator: re-configure all with same configuration
if [[ -n "$generator" && -z "$config" ]]; then
if [[ "$generator" != "$currentGenerator" ]]; then
echo "Generator changed to: $generator. Using 'Debug' as default on new generator..."
bash ./scripts/bash/sub_scripts/re_config_all.sh "$jsonFilePath" "Debug" "$generator"
echo "command were: 'bash.sh --generator $generator'"
bash ./scripts/bash/sub_scripts/re_config_all.sh "$jsonFilePath" "$currentConfig" "$generator"
bash ./scripts/bash/sub_scripts/re_build_game.sh "$currentConfig" "$generator"
exit 0
else
bash ./scripts/bash/sub_scripts/re_build_game.sh "$currentConfig" "$currentGenerator"
bash ./scripts/bash/sub_scripts/re_build_game.sh "$currentConfig" "$generator"
exit 0
fi
fi

# * build.sh --generator 'Ninja'/'MinGW'/'VS' --config 'Debug'/'Release'
# * build.sh --config 'Debug'/'Release' --generator 'Ninja'/'MinGW'/'VS'
if [[ -n "$config" && -n "$generator" ]]; then
echo "Redo with config: $config, generator: $generator"
bash ./scripts/bash/sub_scripts/re_config_all.sh "$jsonFilePath" "$config" "$generator"
bash ./scripts/bash/sub_scripts/re_build_game.sh "$currentConfig" "$currentGenerator"
bash ./scripts/bash/sub_scripts/re_build_game.sh "$config" "$generator"
exit 0
fi

Expand All @@ -136,13 +147,18 @@ if [[ -n "$rebuild" && "$rebuild" != "game" && "$rebuild" != "connector" ]]; the
exit 1
fi

# Handle rebuild cases
if [[ -z "$rebuild" || "$rebuild" == "game" ]]; then
# * build.sh --rebuild game
# ? Rebuilding only game: only game source code have been changed
if [[ "$rebuild" == "game" ]]; then
echo "Just rebuilding game code space..."
bash ./scripts/bash/sub_scripts/re_build_game.sh "$currentConfig" "$currentGenerator"
exit 0
fi

# * build.sh --rebuild connector
# ? Rebuilding connector and game: connector and game source codes have been changed
if [[ "$rebuild" == "connector" ]]; then
echo "Just rebuilding connector and game code space..."
bash ./scripts/bash/sub_scripts/re_build_connector.sh "$currentConfig" "$currentGenerator"
bash ./scripts/bash/sub_scripts/re_build_game.sh "$currentConfig" "$currentGenerator"
exit 0
Expand Down
6 changes: 0 additions & 6 deletions scripts/bash/delete_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ folderList=(
"build"
"SDL2_connector/build"
"SDL2_connector/bin"
"vendor/build"
"vendor/SDL2"
"vendor/ZLIB"
"vendor/JPEG"
"vendor/PNG"
"vendor/SDL2_image"
)

# Path to the sub-script file
Expand Down
4 changes: 3 additions & 1 deletion scripts/bash/sub_scripts/cmake_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ fi
# Navigate to the directory
cd "$directoryPath" || { echo "Failed to navigate to directory: $directoryPath"; exit 1; }

echo "! Using as generator: [$generatorOption]..."
# echo "! Using as generator: [$generatorOption]..."

# Build type configuration and run cmake
if [[ "$config" == "Debug" ]]; then
if [[ "$generatorOption" == "-G Unix Makefiles" ]]; then
# TODO: Maybe some better solution exists
# ! Need this if-else case because of difficulty to parse 'Unix Makefiles' with space between words
cmake .. -Wno-dev -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles"
else
cmake .. -Wno-dev -DCMAKE_BUILD_TYPE=Debug $generatorOption
Expand Down
7 changes: 2 additions & 5 deletions scripts/bash/sub_scripts/re_build_game.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ fi
directoryPath="executables"

# Delete the 'executables' directory
echo "Deleting directory: $directoryPath"
bash ./scripts/bash/sub_scripts/delete.sh "$directoryPath"

# TODO: Check, maybe we can delete this
# Set the directory path based on the config
# directoryPath="executables/$config"
echo "Using generator: '$generator', and config: '$config'"

if [[ "$generator" == "Unix Makefiles" ]]; then
directoryPath="executables/$config"

if [[ ! -d "$directoryPath" ]]; then
echo "It's Makefiles generator: bring back dummy $directoryPath..."
mkdir "$directoryPath"
mkdir -p "$directoryPath"
fi
fi

Expand Down
20 changes: 1 addition & 19 deletions scripts/bash/sub_scripts/re_config_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ if [[ -z "$jsonFilePath" || -z "$config" || -z "$generator" ]]; then
exit 1
fi

# Define a list of parameter sets
parameterSets=("build" "SDL2_connector/build" "SDL2_connector/bin" "vendor/build" "vendor/SDL2" "vendor/SDL2_image" "vendor/JPEG" "vendor/PNG")

# Delete all directories
for directoryPath in "${parameterSets[@]}"; do
echo "Deleting directory: $directoryPath"
bash ./scripts/bash/sub_scripts/delete.sh "$directoryPath"
done
bash ./scripts/bash/delete_all.sh

# Save new build data (using the create_build_data.sh script equivalent in Bash)
echo "Saving new build data to $jsonFilePath"
Expand All @@ -27,18 +21,6 @@ bash ./scripts/bash/sub_scripts/create_build_data.sh "$jsonFilePath" "$config" "
# Generator option code for re-using
generatorOption="-G $generator"

# # ! VENDOR

# # Configuring vendor build
# echo "Configuring vendor build"
# bash ./scripts/bash/sub_scripts/cmake_config.sh "vendor/build" "$config" "$generatorOption"

# echo "current folder: $(pwd)"

# # Building vendor
# echo "Building vendor"
# bash ./scripts/bash/sub_scripts/cmake_build.sh "vendor/build" "$config"

# ! CONNECTOR

# Configuring SDL2_connector build
Expand Down
2 changes: 1 addition & 1 deletion scripts/powershell/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if($config -or $generator){
}
}

# * build.ps1 -generator 'Ninja'/'MinGW'/'VS'
# * build.ps1 -generator 'Ninja'/'Makefiles'/'VS'
# Check if another generator: re-configure all for 'Debug'
if($generator -and -not $config) {
if(-not ($generator -eq $jsonData.Generator)){
Expand Down

0 comments on commit cd8fe1f

Please sign in to comment.