165 lines
4.1 KiB
Bash
Executable File
165 lines
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
# --- Defaults ---
|
|
userFlag=0
|
|
testsFlag=0
|
|
buildDir="build"
|
|
installDir="$HOME/.local/4DSSE"
|
|
|
|
# --- Help Menu ---
|
|
show_help() {
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [OPTIONS]
|
|
|
|
Options:
|
|
--user Build and Install as a release for. Intended for end users.
|
|
--tests Build and run tests.
|
|
--buildDir Specify the build directory. Default is "${buildDir}".
|
|
--installDir Specify the install directory. Default is "${installDir}".
|
|
-h, --help Show this help message and exit
|
|
|
|
You can use these flags in any order. Flags not passed will get default values.
|
|
|
|
Examples:
|
|
For an end user who wants a seemless experience 4DSSE:
|
|
./mk --user
|
|
For developers who want to modify the source:
|
|
./mk
|
|
For developers who want to run tests:
|
|
./mk --tests
|
|
EOF
|
|
}
|
|
|
|
# --- Parse Arguments ---
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--user)
|
|
userFlag=1
|
|
shift
|
|
;;
|
|
--tests)
|
|
testsFlag=1
|
|
shift
|
|
;;
|
|
--buildDir)
|
|
buildDir=1
|
|
shift
|
|
;;
|
|
--installDir)
|
|
installDir=1
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
echo "Use --help for usage information."
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
RED="\033[0;31m"
|
|
GREEN="\033[0;32m"
|
|
YELLOW="\033[0;33m"
|
|
BLUE="\033[0;34m"
|
|
NC="\033[0m" # No Color
|
|
|
|
# Log file.
|
|
LOGDIR="4DSSE_logs"
|
|
if [[ ! -d "$LOGDIR" ]]; then
|
|
echo -e "${BLUE}[Info] Creating log directory...${NC}"
|
|
mkdir "$LOGDIR"
|
|
else
|
|
echo -e "${BLUE}[Info] Log directory already exists. Skipping...${NC}"
|
|
fi
|
|
LOGFILE="${LOGDIR}/4DSSE-install-log.txt"
|
|
|
|
|
|
# Log function: prints to stdout and appends to logfile.
|
|
log() {
|
|
local message="$1"
|
|
# Print the colored message to stdout.
|
|
echo -e "$message"
|
|
# Strip ANSI escape sequences and append the cleaned message to the log file.
|
|
echo -e "$message" | sed -r 's/\x1B\[[0-9;]*[mK]//g' >> "$LOGFILE"
|
|
}
|
|
|
|
if [[ -f "$LOGFILE" ]]; then
|
|
# Get the calendar datetime of the log file creation.
|
|
# convert UNIX timestamp to human-readable date
|
|
rm "$LOGFILE"
|
|
log "${BLUE}[Info] Old log file removed.${NC}"
|
|
fi
|
|
touch "$LOGFILE"
|
|
|
|
# --- Build 4DSSE ---
|
|
log "${BLUE}[Info] Building 4DSSE...${NC}"
|
|
if [[ $userFlag -eq 1 ]]; then
|
|
log "${BLUE}[Info] Installing 4DSSE in user mode...${NC}"
|
|
else
|
|
log "${BLUE}[Info] Installing 4DSSE for developers...${NC}"
|
|
fi
|
|
|
|
if [[ $testsFlag -eq 1 ]]; then
|
|
log "${BLUE}[Info] Building with tests...${NC}"
|
|
else
|
|
log "${BLUE}[Info] Building without tests...${NC}"
|
|
fi
|
|
|
|
# --- First check Boost status ---
|
|
log "${BLUE}[Info] Checking Boost status...${NC}"
|
|
# if the following script exists with anything other than a 0 status the script will exit
|
|
if [[ -f ./build-config/boost/.boost_installed ]]; then
|
|
log "${BLUE}[Info] Boost already installed. Skipping...${NC}"
|
|
else
|
|
log "${BLUE}[Info] Installing Boost...${NC}"
|
|
if ! ./build-config/boost/install.sh; then
|
|
log "${RED}[Error] Boost check failed. Exiting...${NC}"
|
|
exit 1
|
|
else
|
|
touch ./build-config/boost/.boost_installed
|
|
log "${GREEN}[Success] Boost check passed.${NC}"
|
|
fi
|
|
fi
|
|
|
|
# --- Check if the build dir has been configured with the correct flags ---
|
|
log "${BLUE}[Info] Configuring build directory...${NC}"
|
|
if [ -f "$buildDir/build.ninja" ]; then
|
|
log "${BLUE}[Info] Build directory already configured. Skipping...${NC}"
|
|
else
|
|
if [[ $userFlag -eq 1 ]]; then
|
|
meson setup "$buildDir" -Duser_mode=true --buildtype=release
|
|
else
|
|
if [[ $testsFlag -eq 1 ]]; then
|
|
meson setup "$buildDir" --buildtype=debug
|
|
else
|
|
meson setup "$buildDir" --buildtype=debug -Dbuild_tests=false
|
|
fi
|
|
fi
|
|
log "${GREEN}[Success] Build directory configured successfully.${NC}"
|
|
fi
|
|
|
|
log "${BLUE}[Info] Building 4DSSE...${NC}"
|
|
meson compile -C "$buildDir"
|
|
|
|
# --- Install 4DSSE ---
|
|
if [[ $userFlag -eq 1 ]]; then
|
|
log "${BLUE}[Info] Installing 4DSSE in user mode...${NC}"
|
|
meson install -C "$buildDir" --no-rebuild --prefix="$installDir"
|
|
fi
|
|
|
|
if [[ $testsFlag -eq 1 ]]; then
|
|
log "${BLUE}[Info] Running tests...${NC}"
|
|
meson test -C "$buildDir"
|
|
fi
|
|
|
|
if [[ $userFlag -eq 1 ]]; then
|
|
log "${GREEN}[Success] 4DSSE built and installed successfully.${NC}"
|
|
else
|
|
log "${GREEN}[Success] 4DSSE built successfully.${NC}"
|
|
fi |