Compare commits

...

8 Commits

8 changed files with 121 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,5 +1,8 @@
/bin/*
!/bin/.placeholder
/dependencies/*
!/dependencies/.placeholder
# ignore nano's temp files
*.swp

View File

@ -16,3 +16,43 @@ Immediate goals:
- NBT library
- [ ] parse NBT
- [ ] decode and encode data
## Project Setup Instructions
### Prerequisites:
This project requires bash and a C++20 compiler.
The project setup requires wget or curl, gzip, and tar.
**For people using other shells than bash:** You need to at least have bash
installed to use the scripts, but using it as your shell while working on
this project also allows you to use the provided aliases.
If you dont want to use bash as your shell, not even temporarily for this
project, you can use the scripts by running them from the project's base
directory and run any generated executables with `LD_LIBRARY_PATH` set to
point to `bin/lib`.
### Setup
- `git clone` this repository
- if using bash:
- `source` the file `setupenv.bashrc` from the project's base directory
to load the provided shell environment
- `setup_project`
- if not using bash or not using the provided environment:
- `cd` to the project's base directory
- `scripts/setup_project.sh`
This will download the following dependenceis:
- [tiny-utf8](https://github.com/DuffsDevice/tiny-utf8)
### Building
To build the project, just use the `build` alias or invoke the `build.sh`
script from the project's base directory.
`build` and `build.sh` accept the environment variables `CXX` and `CXXFLAGS`. `CXXFLAGS` must at least specify the C++ version.

0
dependencies/.placeholder vendored Normal file
View File

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
if [ -z "$CXX" ]; then
CXX="c++"

View File

@ -1,3 +1,5 @@
#!/usr/bin/env bash
rm -rv ./bin
mkdir -v ./bin
set -v

6
scripts/clean_dependencies.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
rm -rv ./dependencies
mkdir -v ./dependencies
set -v
echo -n "" > ./dependencies/.placeholder

49
scripts/setup_project.sh Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env bash
# figure out if using wget or curl
echo -n "Wget or curl? "
if command -v wget >/dev/null 2>&1; then
USE_WGET=yes
echo "wget"
else
if command -v curl >/dev/null 2>&1; then
USE_WGET=no
echo "curl"
else
echo "Neither wget nor curl found. Aborting."
exit 1
fi
fi
function download {
URL="$1"
DESTINATION="$2"
echo -n "Downloading $URL to $DESTINATION... "
if [ $USE_WGET = yes ]; then
wget -O "$DESTINATION" "$URL" >/dev/null 2>&1
else
curl -L "$URL" --output "$DESTINATION" >/dev/null 2>&1
fi
echo "done."
}
echo "Cleaning build files..."
scripts/clean.sh
echo "Cleaning dependencies..."
scripts/clean_dependencies.sh
mkdir -v dependencies/tmp
download https://github.com/DuffsDevice/tiny-utf8/archive/refs/tags/v4.4.3.tar.gz dependencies/tmp/tiny-utf8.tar.gz
#TODO: verify the files we have downloaded
#TODO: keep the files somewhere else as a cache and only download the ones
# we don't have or that got corrupted
#TODO: once we cache files properly, have clean_dependencies.sh prune
# unknown files from the cache (for example old versions
# of dependencies)
echo -n "Extracting tiny-utf8... "
gzip -d dependencies/tmp/tiny-utf8.tar.gz
tar -xf dependencies/tmp/tiny-utf8.tar -C dependencies
echo "done."
rm -rv dependencies/tmp

20
setupenv.bashrc Normal file
View File

@ -0,0 +1,20 @@
PROJECT_BASE_DIR="$( cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 ; pwd -P )"
alias clean="pushd \"$PROJECT_BASE_DIR\" >/dev/null 2>&1; scripts/clean.sh; popd >/dev/null 2>&1"
alias clean_dependencies="pushd \"$PROJECT_BASE_DIR\" >/dev/null 2>&1; scripts/clean_dependencies.sh; popd >/dev/null 2>&1"
alias setup_project="pushd \"$PROJECT_BASE_DIR\" >/dev/null 2>&1; scripts/setup_project.sh; popd >/dev/null 2>&1"
function build {
pushd "$PROJECT_BASE_DIR" >/dev/null 2>&1
CXX="$CXX" CXXFLAGS="$CXXFLAGS" scripts/build.sh
popd >/dev/null 2>&1
}
if [ -z "$LD_LIBRARY_PATH" ]; then
export LD_LIBRARY_PATH="$PROJECT_BASE_DIR"/bin/lib
else
export LD_LIBRARY_PATH="$PROJECT_BASE_DIR"/bin/lib:"LD_LIBRARY_PATH"
fi
unset PROJECT_BASE_DIR