Browse Source

Switched to a tup-based build

master
dirkson 6 months ago
parent
commit
66d0b52f59
13 changed files with 105 additions and 322 deletions
  1. +2
    -5
      .gitignore
  2. +13
    -1
      README.md
  3. +66
    -0
      Tupfile
  4. +0
    -276
      build
  5. +0
    -0
      inc/parasol.h
  6. +0
    -35
      meson.build
  7. +5
    -5
      src/parasol.c
  8. +4
    -0
      var/android-arm7.config
  9. +4
    -0
      var/android-arm8.config
  10. +4
    -0
      var/dbg.config
  11. +4
    -0
      var/osx.config
  12. +0
    -0
      var/rel.config
  13. +3
    -0
      var/win.config

+ 2
- 5
.gitignore View File

@@ -71,12 +71,9 @@ tags
# Persistent undo
[._]*.un~

# ---> Ninja
.ninja_deps
.ninja_log

# Build framework
meson/*/*
bin/
lib/
.tup/
build-*


+ 13
- 1
README.md View File

@@ -1,3 +1,15 @@
# parasol

A basic wrapper around libuv's functions to smooth our their use.
A basic wrapper around libuv's functions to smooth our their use.

# Building

tup init
tup

Additionally, variants such as a debug build and a win64/osx cross compile are available in var/. The default build is 'rel', for release. To use:

tup init
tup variant var/dbg.config
tup


+ 66
- 0
Tupfile View File

@@ -0,0 +1,66 @@
CFLAGS = -std=c99 -Werror -Wall -Wpedantic
CFLAGS += -D_XOPEN_SOURCE=600
ifndef DISABLE_SSE
CFLAGS += -msse -msse2 -msse3
endif
#-D_GNU_SOURCE
HEADERS = inc/parasol.h

ifdef DEBUG
CFLAGS += -Og
CFLAGS += -DPARASOL_DEBUG
CFLAGS += -ggdb3
CFLAGS += -Db_sanitize=address
else
CFLAGS += -O3
CFLAGS += -flto
endif

ifdef CC
CC = @(TARGET)@(CC)
else
CC = gcc
endif

ifdef PKGCONFIG_DIR
PKGCONFIG = PKG_CONFIG_PATH=@(PKGCONFIG_DIR) PKG_CONFIG_LIBDIR=@(PKGCONFIG_DIR) pkg-config
else
PKGCONFIG = @(TARGET)pkg-config
endif

# Compilation binary dependencies - If the binary changes, we rebuild
# Normally tup needs suid to do this. This is an attempt to do this without that.
: |> ^ cksum cc ^ cksum `which $(CC)` > %o |> tup/cc.sum
: |> ^ cksum ar ^ cksum `which @(TARGET)ar` > %o |> tup/ar.sum
: |> ^ cksum ld ^ cksum `which @(TARGET)ld` > %o |> tup/ld.sum
: |> ^ cksum pkg-config ^ cksum `which $(PKGCONFIG)` > %o |> tup/pkg-config.sum

ifndef LD
LDFLAGS += -fuse-ld=gold -fuse-linker-plugin -fno-fat-lto-objects
else
LDFLAGS += @(LD)
endif

CFLAGS += -Iinc
CFLAGS += `$(PKGCONFIG) --cflags libuv`

ifndef SHAREDLIBS
LDFLAGS += -static
endif

LDFLAGS += `@(TARGET)pkg-config --libs libuv`

# Macros
!cc-obj = | <header> tup/cc.sum |> ^ CC %f^ $(CC) $(CFLAGS) -c %f -o %o |>
!cc-bin = | <header> tup/cc.sum |> ^ CC %f^ $(CC) $(CFLAGS) %f -o %o $(LDFLAGS) |>
!ar = | tup/ar.sum |> ^ AR %f^ @(TARGET)ar rcs %o %f |>

:foreach src/*.c |> !cc-obj |> obj/%B.o

:obj/*.o |> !ar |> lib/libparasol.a

:foreach src/examples/*.c |> !cc-bin |> bin/%B


#Copy over the include file to any variants
:foreach inc/*.h |> !tup_preserve |> inc/%b | <header>

+ 0
- 276
build View File

@@ -1,276 +0,0 @@
#!/bin/bash

#************
#***CONFIG***
#************

#If COMPILER isn't set, the script will attempt to figure it out itself.
#If you change the compiler, you'll need to clean your build.
#COMPILER=musl-gcc

#If this isn't set, the script will attempt to find ninja and samu, in that order.
#Alternatives include samurai's "samu"
#NINJACOMMAND=ninja

#Directories
BUILDDIR=meson
DOCDIR=doc
BINDIR=bin
LIBDIR=lib
DEPDIR=subprojects

#***********
#***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, with --werror added"
echo "-c OR --clean : Cleans up current project meson/ninja/osmia files"
echo "-fc OR --full-clean : Fully clean - Removes osmia dependencies too"
echo "-a OR --add-san : Clang's address sanitizer"
echo "-w32 OR --win32 : Cross-compile for win32 using subprojects/win32cross.txt"
echo "-w OR --win : cross-compile for win64 using subprojects/win64cross.txt"
echo "-o OR --osx : cross-compile for OSX"
}
osmia_clean () {
rm -rf $BUILDDIR $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
}



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
MESONOPTS="--werror"
;;
-a)
COMPILER="clang"
DIR=debug
BLD=debug
MESONOPTS=-Db_sanitize=address
MESONOPTS="--werror"
;;
-w32|-win32|--win32|-window32|--windows32)
DIR=release
BLD=release
MESONOPTS="--cross-file $DEPDIR/win32cross.txt"
;;
-w|-win|--win|--window|--windows|-w64|-win64|--win64|--windows64|--windows64)
DIR=release
BLD=release
MESONOPTS="--cross-file $DEPDIR/win64cross.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
;;
-fc|-fullclean|--fullclean|-full-clean|--full-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
#rm -rf $DEPDIR
echo "osmia: fully 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 "$NINJACOMMAND" ]; then
NINJACOMMAND=ninja
if [ ! -x "$(command -v $NINJACOMMAND)" ]; then
NINJACOMMAND=samu
if [ ! -x "$(command -v $NINJACOMMAND)" ]; 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 $NINJACOMMAND)" ]; 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 "$COMPILER" ]; then
if [ -x "$(command -v clang)" ]; then
COMPILER="clang"
elif [ -x "$(command -v musl-gcc)" ]; then
COMPILER="musl-gcc -static"
elif [ -x "$(command -v gcc)" ]; then
COMPILER="gcc"
elif [ -x "$(command -v tcc)" ]; then
COMPILER="tcc"
elif [ -x "$(command -v icc)" ]; then
COMPILER="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 $COMPILER)" ]; 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

#Grab dependencies
if [ -d "$DEPDIR" ] && [ -e $DEPDIR/dependencies ]; then
cd "$DEPDIR"
source ../$DEPDIR/dependencies
cd ../
fi


#Set up basic directory structure, if needed
mkdir -p $BUILDDIR 2> /dev/null

#MESONOPTS=MESONOPTS:"-Dc_args=$3"

if [ ! -d "$BUILDDIR/$DIR" ]; then
export CC="$CACHE $COMPILER"
#Run meson if required
mkdir $BUILDDIR/$DIR
meson $BUILDDIR/$DIR $MESONOPTS --buildtype $BLD
if [ ! $? -eq 0 ]; then
#Generally an error here means we need to clean before the next run
tail $BUILDDIR/$DIR/meson-logs/meson-log.txt
cp $BUILDDIR/$DIR/meson-logs/meson-log.txt meson-log.txt
echo "osmia: meson returned an error. Please check meson-log.txt for more info."
osmia_clean
exit 1
fi
#else
#May wish to look into this in the future
#meson configure $MESONOPTS
fi

#Actually build
cd $BUILDDIR/$DIR
$NINJACOMMAND $2
if [ ! $? -eq 0 ]; then
cd ../../
exit 1
fi
cd ../../

#set up symlinks
osmia_symlink "$BUILDDIR/$DIR/*" "-name *.a -o -name *.so -o -name *.dll" $LIBDIR
osmia_symlink "$BUILDDIR/$DIR/*" "-not -name *.so -not -name *.dll -executable -not -name sanitycheckc.exe" $BINDIR
osmia_symlink "$BUILDDIR/$DIR/*" "-name *.html -o -name *.htm" $DOCDIR

echo "osmia: successful build."

exit 0

include/parasol.h → inc/parasol.h View File


+ 0
- 35
meson.build View File

@@ -1,35 +0,0 @@
project('parasol', 'c', default_options : ['default_library=static', 'c_std=c99'], subproject_dir : 'meson')
add_project_arguments(['-Werror', '-Wall', '-Wpedantic', '-D_XOPEN_SOURCE=600', '-D_GNU_SOURCE'], language : 'c')


incdir = include_directories(['include', 'src'])



if get_option('buildtype').startswith('debug')
add_project_arguments('-DPARASOL_DEBUG', language : 'c')
else
endif



depuv = dependency('libuv', required: true)

libparasol = library('parasol', 'src/parasol.c', include_directories : incdir, dependencies: [depuv])
parasol_dep = declare_dependency(link_with : libparasol, include_directories : incdir)

headers = files([
'include/parasol.h'
])

install_headers(headers)

pkg = import('pkgconfig')

pkg.generate(name: 'parasol', description: 'parasol', libraries: libparasol)


if not meson.is_subproject()
executable('parasol-example', 'src/examples/basic.c', include_directories : incdir, dependencies: [parasol_dep])
endif


+ 5
- 5
src/parasol.c View File

@@ -22,10 +22,10 @@ void ReceiveTcpFile(uv_stream_t*, ssize_t, const uv_buf_t*);

typedef struct parasol_data_t
{
int
do_ipv6 : 1
;
//Receive "packet" callbacks
int
do_ipv6 : 1
;
//Receive "packet" callbacks

//UV data
uv_loop_t *loop;
@@ -542,7 +542,7 @@ void ReceiveTcpData(uv_stream_t* Stream, ssize_t NumberRead, const uv_buf_t* Buf

//ScrumbleDebug("Got packet of length: %i", PacketData->Length);

//If we got here, we know that we've got enough for a message.
//If we got here, we know that we've got enough for a message.

//DoStuffBasedOnMessage();
parasol_data.get_tcp_callback(PacketData->Length, PacketData->Message, Stream);


+ 4
- 0
var/android-arm7.config View File

@@ -0,0 +1,4 @@
CONFIG_CC=clang
CONFIG_TARGET=arm-linux-androideabi-
CONFIG_DISABLE_SSE=y
CONFIG_PKGCONFIG_DIR=/opt/android/lib/pkgconfig/

+ 4
- 0
var/android-arm8.config View File

@@ -0,0 +1,4 @@
CONFIG_CC=clang
CONFIG_TARGET=aarch64-linux-android-
CONFIG_DISABLE_SSE=y
CONFIG_PKGCONFIG_DIR=/opt/android/lib/pkgconfig/

+ 4
- 0
var/dbg.config View File

@@ -0,0 +1,4 @@
CONFIG_CC=clang
CONFIG_TARGET=
CONFIG_DEBUG=y
CONFIG_LD=-fuse-ld=lld

+ 4
- 0
var/osx.config View File

@@ -0,0 +1,4 @@
CONFIG_CC=clang
CONFIG_TARGET=x86_64-apple-darwin19-
CONFIG_SHAREDLIBS=y
CONFIG_LD=

+ 0
- 0
var/rel.config View File


+ 3
- 0
var/win.config View File

@@ -0,0 +1,3 @@
CONFIG_CC=gcc
CONFIG_TARGET=x86_64-w64-mingw32.static-
CONFIG_LD=

Loading…
Cancel
Save