Browse Source

Initial commit

master
dirkson 1 year ago
parent
commit
f9d627631f
6 changed files with 327 additions and 2 deletions
  1. +7
    -2
      README.md
  2. +268
    -0
      build
  3. +18
    -0
      include/scrumblevox.h
  4. +16
    -0
      meson.build
  5. +9
    -0
      src/scrumblevox.c
  6. +9
    -0
      src/tool.c

+ 7
- 2
README.md View File

@ -1,3 +1,8 @@
# scrumblegox
# scrumblevox
A translation tool to transform ScrumbleShip blocks to/from goxel save files.
A library and tool for converting to and from the Scrumble Voxel Format
## TODO
* .gox goxel format support
* .vox magica voxel format support

+ 268
- 0
build View File

@ -0,0 +1,268 @@
#!/bin/bash
#************
#***CONFIG***
#************
#If CC isn't set, the script will attempt to figure it out itself.
#CC=musl-gcc
#If this isn't set, the script will attempt to find ninja and samu, in that order.
#Alternatives include samurai's "samu"
#NINJA=ninja
#Directories
MDIR=meson
BINDIR=bin
LIBDIR=lib
#***********
#***OSMIA***
#***********
#
# This is osmia, a build script for meson.
#
# Official URL:
# https://git.orangehattech.com/dirkson/osmia
#
#*************
#***LICENSE***
#*************
#
# MIT License
#
# Copyright (c) 2018 Dirkson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#Functions
osmia_help () {
echo "Osmia build script for meson."
echo "Usage: ./build [-mode] [target]"
echo "Target will be passed to ninja directly"
echo "Mode defaults to release, or is one of the following:"
echo "-r OR --release : Builds using Meson's release mode"
echo "-d OR --debug : Builds using Meson's debug mode"
echo "-c OR --clean : Cleans up current project meson/ninja/osmia files"
echo "-a OR --add-san : Clang's address sanitizer"
echo "-w32 OR --win32 : Cross-compile for win32 using $MDIR/win32.txt"
echo "-w OR --win : cross-compile for win64 using $MDIR/win64.txt"
echo "-o OR --osx : cross-compile for OSX"
}
osmia_clean () {
rm -rf $MDIR/release $MDIR/debug $BINDIR $LIBDIR
}
osmia_symlink () {
FILES="$(find $1 -maxdepth 1 -type f $2 2> /dev/null)"
if [ ! -z "$FILES" ]; then
mkdir -p $3 2> /dev/null
rm -rf $3/* 2> /dev/null
for I in $FILES; do
ln -s ../$I $3/
done
fi
}
osmia_get () {
if [ ! -d "$1" ]; then
$2
if [ ! $? -eq 0 ]; then
echo "osmia: git command failed: $1"
exit 1
fi
if [ ! -d "$1" ]; then
echo "osmia: could not find directory: $1"
exit 1
fi
fi
}
#Begin
#If we needed to clean, clean.
if [ -e "$MDIR/osmia/clean" ]; then
osmia_clean
rm $MDIR/osmia/clean
fi
clear
err=0;
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
err=1
echo "osmia: er... Yeah, don't source this file."
return 1
fi
#What type of build?
case "$1" in
-d|-debug|--debug)
DIR=debug
BLD=debug
;;
-a)
COMPILER="clang"
DIR=debug
BLD=debug
MESONOPTS=-Db_sanitize=address
;;
-w32|-win32|--win32|-window32|--windows32)
DIR=release
BLD=release
MESONOPTS="--cross-file $MDIR/win32.txt"
;;
-w|-win|--win|--window|--windows|-w64|-win64|--win64|--windows64|--windows64)
DIR=release
BLD=release
MESONOPTS="--cross-file $MDIR/win64.txt"
;;
-c|-clean|--clean)
if [ "$#" -ne 1 ]; then
echo "osmia: you passed additional arguments to clean. I have no idea what you want. Did not clean."
exit 1
fi
osmia_clean
echo "osmia: cleaned."
exit 0
;;
-?|-h|-help|--help)
osmia_help
err=1
;;
-r|--release|*)
DIR=release
BLD=release
;;
esac
#do some basic error checking for the user
if [ -z "$NINJA" ]; then
NINJA=ninja
if [ ! -x "$(command -v $NINJA)" ]; then
NINJA=samu
if [ ! -x "$(command -v $NINJA)" ]; then
echo "osmia: neither ninja nor samu are installed. One of the two is required to build."
echo "osmia: Please install either samurai's samu or ninja-build's ninja."
err=1;
fi
fi
else
if [ ! -x "$(command -v $NINJA)" ]; then
echo "osmia: manually specified ninja command not found"
err=1;
fi
fi
if [ ! -x "$(command -v meson)" ]; then
echo "osmia: meson not installed. The meson build system is required to build, please install.";
err=1;
fi
if [ -z "$CC" ]; then
if [ -x "$(command -v clang)" ]; then
CC="clang"
elif [ -x "$(command -v gcc)" ]; then
CC="gcc"
elif [ -x "$(command -v tcc)" ]; then
CC="tcc"
elif [ -x "$(command -v icc)" ]; then
CC="icc"
else
echo "osmia: unable to find any compiler at all. Please install one: clang, musl-gcc, gcc, tcc, icc"
err=1
fi
else
if [ ! -x "$(command -v $CC)" ]; then
echo "osmia: manually specified compiler does not exist. Failing."
err=1
fi
fi
if [ ! -x "$(command -v ccache)" ]; then
CACHE=""
echo "osmia: ccache not installed. Installing it could speed the build up. Hint Hint."
else
CACHE="ccache"
fi
if [ "$#" -gt 2 ]; then
osmia_help
echo "osmia: failed, too many parameters."
err=1;
fi
#Note: For exit '0' is 'true' and '1' in 'false', in spite of all logic.
if [ $err -ne 0 ]; then
exit 1
fi
#Check if our CC changed. If it did, clean
if [ -e "$MDIR/osmia/cc" ]; then
if [ "$CC" != $(cat $MDIR/osmia/cc) ]; then
echo "osmia: compiler changed. Forced to clean."
osmia_clean
fi
fi
#Grab dependencies
if [ -e $MDIR/dependencies ]; then
cd "$MDIR"
source ./dependencies
cd ../
fi
mkdir -p $MDIR/osmia/ 2> /dev/null
if [ ! -d "$MDIR/$DIR" ]; then
echo $CC > $MDIR/osmia/cc
export CC="$CACHE $CC"
#Run meson if required
mkdir $MDIR/$DIR
meson $MDIR/$DIR $MESONOPTS --buildtype $BLD
if [ ! $? -eq 0 ]; then
#Generally an error here means we need to clean before the next run
tail $MDIR/$DIR/meson-logs/meson-log.txt
touch $MDIR/osmia/clean
echo "osmia: meson returned an error. Please check $MDIR/$DIR/meson-logs/meson-log.txt for more info."
exit 1
fi
#else
#May wish to look into this in the future
#meson configure $MESONOPTS
fi
#Actually build
cd $MDIR/$DIR
$NINJA $2
if [ ! $? -eq 0 ]; then
cd ../../
exit 1
fi
cd ../../
#set up symlinks
osmia_symlink "$MDIR/$DIR/*" "-name *.a -o -name *.so -o -name *.dll" $LIBDIR
osmia_symlink "$MDIR/$DIR/*" "-not -name *.so -not -name *.dll -executable -not -name sanitycheckc.exe" $BINDIR
echo "osmia: successful build."
exit 0

+ 18
- 0
include/scrumblevox.h View File

@ -0,0 +1,18 @@
/*
Copyright (c) 2019 Orangehattech, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE NO OR OTHER DEALINGS IN THE SOFTWARE.
*/
// ***Include guards***
#pragma once //Speeds up compilation on platforms that support it
#ifndef LOB_INCLUDED
#define LOB_INCLUDED
// ***Include guards***
#endif

+ 16
- 0
meson.build View File

@ -0,0 +1,16 @@
project('scrumblegox', 'c', default_options : ['default_library=static', 'c_std=c99'], subproject_dir : 'meson')
add_project_arguments(['-Werror', '-Wall', '-Wpedantic', '-Wextra'], language : 'c')
incdir = include_directories('include')
libscrumblevox = library('scrumblevox', 'src/scrumblevox.c', include_directories : incdir)
scrumblevox_dep = declare_dependency(link_with : libscrumblevox, include_directories : incdir)
if not meson.is_subproject()
executable('scrumblevox', 'src/tool.c', include_directories : incdir, dependencies: scrumblevox_dep)
#Test binary
#executable('svtest', 'src/test.c', include_directories : incdir, dependencies: [scrumblevox_dep])
endif

+ 9
- 0
src/scrumblevox.c View File

@ -0,0 +1,9 @@
#include "scrumblevox.h"
int scrumblevox_new() {
return 0;
}

+ 9
- 0
src/tool.c View File

@ -0,0 +1,9 @@
#include "scrumblevox.h"
int main() {
return 0;
}

Loading…
Cancel
Save