Make this buildable on SunOS
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 19s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 20s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 11s
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 19s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 20s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 11s
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
72
build.sh
72
build.sh
@@ -3,8 +3,8 @@
|
||||
set -e
|
||||
|
||||
BUILD_DIR="BUILD"
|
||||
INSTALL_DIR="$(pwd)/install"
|
||||
CFLAGS="-std=c99 -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token -lm"
|
||||
INSTALL_DIR=$PWD/install
|
||||
CFLAGS="-Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token"
|
||||
BUILD_SHARED=1
|
||||
PTHREAD_SUPPORT=1
|
||||
POSIX_SUPPORT=1
|
||||
@@ -20,53 +20,75 @@ for arg in "$@"; do
|
||||
--release) CFLAGS="$CFLAGS -O2" ;;
|
||||
--no-pthread) PTHREAD_SUPPORT=0 ;;
|
||||
--no-posix) POSIX_SUPPORT=0 ;;
|
||||
--with-programs) BUILD_PROGRAMS=1 ;;
|
||||
--no-programs) BUILD_PROGRAMS=0 ;;
|
||||
--clean) rm -rf "$BUILD_DIR" "$INSTALL_DIR"; echo "Cleaned."; exit 0 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Detect SunOS
|
||||
OS=`uname`
|
||||
echo "Detected os:" $OS
|
||||
SHARED_FLAG="-shared"
|
||||
PIC_FLAG="-fPIC"
|
||||
if [ "$OS" = "SunOS" ]; then
|
||||
SHARED_FLAG="-G"
|
||||
PIC_FLAG="-KPIC"
|
||||
CFLAGS=`echo "$CFLAGS" | sed 's/-pedantic//g'`
|
||||
fi
|
||||
|
||||
# Setup directories
|
||||
mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include" "$INSTALL_DIR/bin"
|
||||
|
||||
# Compiler and linker
|
||||
CC=${CC:-cc}
|
||||
|
||||
if [ "$OS" = "SunOS" ] && [ "$CC" = "cc" ]; then
|
||||
CFLAGS="$CFLAGS -xc99"
|
||||
else
|
||||
CFLAGS="$CFLAGS -std=c99"
|
||||
fi
|
||||
|
||||
if [ "$PTHREAD_SUPPORT" -eq 1 ]; then
|
||||
CFLAGS="$CFLAGS -DDCFG_PTHREAD_SUPPORT"
|
||||
LIBS="$LIBS -lpthread"
|
||||
CFLAGS="$CFLAGS -DDCFG_PTHREAD_SUPPORT=1"
|
||||
if [ "$OS" = "SunOS" ]; then
|
||||
LIBS="$LIBS -mt"
|
||||
else
|
||||
LIBS="$LIBS -lpthread"
|
||||
fi
|
||||
fi
|
||||
if [ "$POSIX_SUPPORT" -eq 1 ]; then
|
||||
CFLAGS="$CFLAGS -DDCFG_POSIX_SUPPORT"
|
||||
CFLAGS="$CFLAGS -DDCFG_POSIX_SUPPORT=1"
|
||||
fi
|
||||
|
||||
CFLAGS="$CFLAGS $PIC_FLAG -lm"
|
||||
|
||||
echo "Building DCFG..."
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
set -x
|
||||
|
||||
# Shared library
|
||||
$CC $CFLAGS -fPIC -shared "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o "$OUTPUT_NAME.so" $LIBS
|
||||
$CC $CFLAGS $SHARED_FLAG "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o "$OUTPUT_NAME.so" $LIBS
|
||||
|
||||
# Static library
|
||||
$CC $CFLAGS -c "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR"
|
||||
ar rcs "$OUTPUT_NAME.a" dcfg.o
|
||||
set +x
|
||||
#
|
||||
# Build programs if requested
|
||||
$CC -c $CFLAGS "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o dcfg.o
|
||||
if [ "$OS" = "SunOS" ]; then
|
||||
CC -xar -o "$OUTPUT_NAME.a" dcfg.o
|
||||
else
|
||||
ar rcs "$OUTPUT_NAME.a" dcfg.o
|
||||
fi
|
||||
|
||||
|
||||
cp "$OUTPUT_NAME.so" "$INSTALL_DIR/lib/"
|
||||
cp "$OUTPUT_NAME.a" "$INSTALL_DIR/lib/"
|
||||
cp -r "../$INCLUDE_DIR/"* "$INSTALL_DIR/include/"
|
||||
|
||||
if [ "$BUILD_PROGRAMS" -eq 1 ]; then
|
||||
echo "Building example programs..."
|
||||
for src in "../$PROGRAMS_DIR"/*.c; do
|
||||
prog=$(basename "$src" .c)
|
||||
echo "Building $prog..."
|
||||
$CC $CFLAGS -c "$src" -I"../$INCLUDE_DIR"
|
||||
mkdir -p bin
|
||||
$CC $CFLAGS "$prog.o" "$OUTPUT_NAME.a" $LIBS -o "bin/$prog"
|
||||
for prog in ../"$PROGRAMS_DIR"/*.c; do
|
||||
prog_name=`basename "$prog" .c`
|
||||
$CC $CFLAGS "$prog" -I"../$INCLUDE_DIR" $OUTPUT_NAME.a $LIBS -o "$prog_name"
|
||||
cp "$prog_name" "$INSTALL_DIR/bin/"
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Installing library..."
|
||||
cp -r "../$INCLUDE_DIR/"* "$INSTALL_DIR/include/"
|
||||
cp "$OUTPUT_NAME.so" "$INSTALL_DIR/lib/"
|
||||
cp "$OUTPUT_NAME.a" "$INSTALL_DIR/lib/"
|
||||
cp -r "bin/"* "$INSTALL_DIR/bin/"
|
||||
|
||||
echo "Done. Installed to $INSTALL_DIR"
|
||||
|
30
src/dcfg.c
30
src/dcfg.c
@@ -26,9 +26,6 @@
|
||||
# define DCFG_UTF8_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "meta.h"
|
||||
|
||||
#if DCFG_UTF8_SUPPORT
|
||||
@@ -37,10 +34,6 @@
|
||||
#include "vendor/vec.h"
|
||||
|
||||
#if DCFG_POSIX_SUPPORT
|
||||
# ifdef __sun
|
||||
// FIXME: Fix this stupid shit!
|
||||
# error "realpath() is dumb and stupid on sun. sorry not sorry."
|
||||
# endif
|
||||
# define _POSIX_C_SOURCE 200809L
|
||||
#else
|
||||
# ifdef _POSIX_C_SOURCE
|
||||
@@ -68,18 +61,21 @@ typedef struct {
|
||||
# define PTHREAD_MUTEX_RECURSIVE_NP 0
|
||||
# endif
|
||||
|
||||
static void pthread_mutex_init(pthread_mutex_t *, void *) { }
|
||||
static void pthread_mutex_destroy(pthread_mutex_t *) { }
|
||||
static void pthread_mutex_lock(pthread_mutex_t *) { }
|
||||
static void pthread_mutex_unlock(pthread_mutex_t *) { }
|
||||
pthread_mutexattr_init(pthread_mutexattr_t *);
|
||||
static void pthread_mutexattr_settype(pthread_mutexattr_t *, int) { }
|
||||
static void pthread_mutex_init(pthread_mutex_t *m, void *data) { }
|
||||
static void pthread_mutex_destroy(pthread_mutex_t *m) { }
|
||||
static void pthread_mutex_lock(pthread_mutex_t *m) { }
|
||||
static void pthread_mutex_unlock(pthread_mutex_t *m) { }
|
||||
void pthread_mutexattr_init(pthread_mutexattr_t *attr);
|
||||
static void pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { }
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -387,7 +383,10 @@ struct dcfg_Instance {
|
||||
static void *alloc(size_t size) { return calloc(1, size); }
|
||||
|
||||
#if DCFG_POSIX_SUPPORT
|
||||
static char *realpath_(char const *s) { return realpath(s, NULL); }
|
||||
static char *realpath_(char const *s) {
|
||||
char buf[PATH_MAX];
|
||||
return strdup(realpath(s, buf));
|
||||
}
|
||||
void *fopen_(char const *f, char const *a) { return fopen(f, a); }
|
||||
int fseek_(void *f, size_t p, int o) { return fseek(f, p, o); }
|
||||
long ftell_(void *f) { return ftell(f); }
|
||||
@@ -2052,6 +2051,8 @@ bool dcfg_Value_evaluate_toplevel(dcfg_Value *top, dcfg_Value **out_value,
|
||||
lib->type = dcfg_ValueType_Object;
|
||||
lib->v.o.entryv = vector_create();
|
||||
if (!lib->v.o.entryv) {
|
||||
strcpy(
|
||||
top->instance->last_error, "Failed to allocate standard library");
|
||||
inst->free(lib);
|
||||
return false;
|
||||
}
|
||||
@@ -2059,6 +2060,7 @@ bool dcfg_Value_evaluate_toplevel(dcfg_Value *top, dcfg_Value **out_value,
|
||||
for (size_t i = 0; i < function_count; ++i) {
|
||||
Value *fn = inst->alloc(sizeof *fn);
|
||||
if (!fn) {
|
||||
strcpy(top->instance->last_error, "Failed to allocate function");
|
||||
dcfg_destroy(lib);
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user