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

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-08-07 00:23:46 +03:00
parent da1725982c
commit b1e03148b7
2 changed files with 63 additions and 39 deletions

View File

@@ -3,8 +3,8 @@
set -e set -e
BUILD_DIR="BUILD" BUILD_DIR="BUILD"
INSTALL_DIR="$(pwd)/install" INSTALL_DIR=$PWD/install
CFLAGS="-std=c99 -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token -lm" CFLAGS="-Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token"
BUILD_SHARED=1 BUILD_SHARED=1
PTHREAD_SUPPORT=1 PTHREAD_SUPPORT=1
POSIX_SUPPORT=1 POSIX_SUPPORT=1
@@ -20,53 +20,75 @@ for arg in "$@"; do
--release) CFLAGS="$CFLAGS -O2" ;; --release) CFLAGS="$CFLAGS -O2" ;;
--no-pthread) PTHREAD_SUPPORT=0 ;; --no-pthread) PTHREAD_SUPPORT=0 ;;
--no-posix) POSIX_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 ;; --clean) rm -rf "$BUILD_DIR" "$INSTALL_DIR"; echo "Cleaned."; exit 0 ;;
esac esac
done 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 # Setup directories
mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include" "$INSTALL_DIR/bin" mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include" "$INSTALL_DIR/bin"
# Compiler and linker # Compiler and linker
CC=${CC:-cc} CC=${CC:-cc}
if [ "$OS" = "SunOS" ] && [ "$CC" = "cc" ]; then
CFLAGS="$CFLAGS -xc99"
else
CFLAGS="$CFLAGS -std=c99"
fi
if [ "$PTHREAD_SUPPORT" -eq 1 ]; then if [ "$PTHREAD_SUPPORT" -eq 1 ]; then
CFLAGS="$CFLAGS -DDCFG_PTHREAD_SUPPORT" CFLAGS="$CFLAGS -DDCFG_PTHREAD_SUPPORT=1"
if [ "$OS" = "SunOS" ]; then
LIBS="$LIBS -mt"
else
LIBS="$LIBS -lpthread" LIBS="$LIBS -lpthread"
fi
fi fi
if [ "$POSIX_SUPPORT" -eq 1 ]; then if [ "$POSIX_SUPPORT" -eq 1 ]; then
CFLAGS="$CFLAGS -DDCFG_POSIX_SUPPORT" CFLAGS="$CFLAGS -DDCFG_POSIX_SUPPORT=1"
fi fi
CFLAGS="$CFLAGS $PIC_FLAG -lm"
echo "Building DCFG..." echo "Building DCFG..."
cd "$BUILD_DIR" cd "$BUILD_DIR"
set -x set -x
# Shared library # 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 # Static library
$CC $CFLAGS -c "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" $CC -c $CFLAGS "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o dcfg.o
ar rcs "$OUTPUT_NAME.a" dcfg.o if [ "$OS" = "SunOS" ]; then
set +x CC -xar -o "$OUTPUT_NAME.a" dcfg.o
# else
# Build programs if requested 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 if [ "$BUILD_PROGRAMS" -eq 1 ]; then
echo "Building example programs..." for prog in ../"$PROGRAMS_DIR"/*.c; do
for src in "../$PROGRAMS_DIR"/*.c; do prog_name=`basename "$prog" .c`
prog=$(basename "$src" .c) $CC $CFLAGS "$prog" -I"../$INCLUDE_DIR" $OUTPUT_NAME.a $LIBS -o "$prog_name"
echo "Building $prog..." cp "$prog_name" "$INSTALL_DIR/bin/"
$CC $CFLAGS -c "$src" -I"../$INCLUDE_DIR"
mkdir -p bin
$CC $CFLAGS "$prog.o" "$OUTPUT_NAME.a" $LIBS -o "bin/$prog"
done done
fi 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" echo "Done. Installed to $INSTALL_DIR"

View File

@@ -26,9 +26,6 @@
# define DCFG_UTF8_SUPPORT 1 # define DCFG_UTF8_SUPPORT 1
#endif #endif
#include <inttypes.h>
#include <stdio.h>
#include "meta.h" #include "meta.h"
#if DCFG_UTF8_SUPPORT #if DCFG_UTF8_SUPPORT
@@ -37,10 +34,6 @@
#include "vendor/vec.h" #include "vendor/vec.h"
#if DCFG_POSIX_SUPPORT #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 # define _POSIX_C_SOURCE 200809L
#else #else
# ifdef _POSIX_C_SOURCE # ifdef _POSIX_C_SOURCE
@@ -68,18 +61,21 @@ typedef struct {
# define PTHREAD_MUTEX_RECURSIVE_NP 0 # define PTHREAD_MUTEX_RECURSIVE_NP 0
# endif # endif
static void pthread_mutex_init(pthread_mutex_t *, void *) { } static void pthread_mutex_init(pthread_mutex_t *m, void *data) { }
static void pthread_mutex_destroy(pthread_mutex_t *) { } static void pthread_mutex_destroy(pthread_mutex_t *m) { }
static void pthread_mutex_lock(pthread_mutex_t *) { } static void pthread_mutex_lock(pthread_mutex_t *m) { }
static void pthread_mutex_unlock(pthread_mutex_t *) { } static void pthread_mutex_unlock(pthread_mutex_t *m) { }
pthread_mutexattr_init(pthread_mutexattr_t *); void pthread_mutexattr_init(pthread_mutexattr_t *attr);
static void pthread_mutexattr_settype(pthread_mutexattr_t *, int) { } static void pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { }
#endif #endif
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h> #include <math.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -387,7 +383,10 @@ struct dcfg_Instance {
static void *alloc(size_t size) { return calloc(1, size); } static void *alloc(size_t size) { return calloc(1, size); }
#if DCFG_POSIX_SUPPORT #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); } 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); } int fseek_(void *f, size_t p, int o) { return fseek(f, p, o); }
long ftell_(void *f) { return ftell(f); } 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->type = dcfg_ValueType_Object;
lib->v.o.entryv = vector_create(); lib->v.o.entryv = vector_create();
if (!lib->v.o.entryv) { if (!lib->v.o.entryv) {
strcpy(
top->instance->last_error, "Failed to allocate standard library");
inst->free(lib); inst->free(lib);
return false; 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) { for (size_t i = 0; i < function_count; ++i) {
Value *fn = inst->alloc(sizeof *fn); Value *fn = inst->alloc(sizeof *fn);
if (!fn) { if (!fn) {
strcpy(top->instance->last_error, "Failed to allocate function");
dcfg_destroy(lib); dcfg_destroy(lib);
return false; return false;
} }