Add build script
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 11s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 11s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 11s
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 11s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 11s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 11s
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,3 +1,8 @@
|
||||
[Bb]uild*
|
||||
[Bb]uild*/
|
||||
.cache
|
||||
/*.txt
|
||||
*.o
|
||||
*.so
|
||||
*.a
|
||||
BUILD
|
||||
install
|
||||
|
54
build.sh
Executable file
54
build.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
BUILD_DIR="BUILD"
|
||||
INSTALL_DIR="$(pwd)/install"
|
||||
CFLAGS="-std=gnu99 -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token"
|
||||
BUILD_SHARED=1
|
||||
PTHREAD_SUPPORT=1
|
||||
POSIX_SUPPORT=1
|
||||
SRC_DIR="src"
|
||||
INCLUDE_DIR="include"
|
||||
OUTPUT_NAME="libdcfg"
|
||||
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--debug) CFLAGS="$CFLAGS -g -O0" ;;
|
||||
--release) CFLAGS="$CFLAGS -O2" ;;
|
||||
--no-pthread) PTHREAD_SUPPORT=0 ;;
|
||||
--no-posix) POSIX_SUPPORT=0 ;;
|
||||
--clean) rm -rf "$BUILD_DIR" "$INSTALL_DIR"; echo "Cleaned."; exit 0 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Setup directories
|
||||
mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include"
|
||||
|
||||
# Compiler and linker
|
||||
CC=${CC:-cc}
|
||||
|
||||
if [ "$PTHREAD_SUPPORT" -eq 1 ]; then
|
||||
CFLAGS="$CFLAGS -DDCFG_PTHREAD_SUPPORT"
|
||||
LIBS="$LIBS -lpthread"
|
||||
fi
|
||||
if [ "$POSIX_SUPPORT" -eq 1 ]; then
|
||||
CFLAGS="$CFLAGS -DDCFG_POSIX_SUPPORT"
|
||||
fi
|
||||
|
||||
echo "Building DCFG..."
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
set -x
|
||||
$CC $CFLAGS -fPIC -shared "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o "$OUTPUT_NAME.so" $LIBS
|
||||
|
||||
$CC $CFLAGS -c "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR"
|
||||
ar rcs "$OUTPUT_NAME.a" dcfg.o
|
||||
|
||||
set +x
|
||||
|
||||
echo "Installing..."
|
||||
cp -r "../$INCLUDE_DIR/"* "$INSTALL_DIR/include/"
|
||||
cp "$OUTPUT_NAME.so" "$INSTALL_DIR/lib/"
|
||||
cp "$OUTPUT_NAME.a" "$INSTALL_DIR/lib/"
|
||||
|
||||
echo "Done. Installed to $INSTALL_DIR"
|
19
src/dcfg.c
19
src/dcfg.c
@@ -169,6 +169,8 @@ struct dcfg_Value {
|
||||
Instance *instance;
|
||||
dcfg_ValueType type;
|
||||
SourceLocation location;
|
||||
int i_sourcev_idx;
|
||||
int i_source_pathv_idx;
|
||||
|
||||
union {
|
||||
int64_t i;
|
||||
@@ -194,6 +196,9 @@ struct dcfg_Instance {
|
||||
dcfg_FtellFn ftell;
|
||||
|
||||
char last_error[256];
|
||||
|
||||
StringView *sourcev; // Strings should be freed.
|
||||
StringView *source_pathv; // Strings should be freed.
|
||||
};
|
||||
|
||||
#define ALLOC(sz) (instance->alloc((sz)))
|
||||
@@ -248,6 +253,9 @@ dcfg_Instance *dcfg_make_instance(dcfg_InstanceCreateInfo const *create_info)
|
||||
assert(instance->fseek);
|
||||
assert(instance->ftell);
|
||||
|
||||
instance->sourcev = vector_create();
|
||||
instance->source_pathv = vector_create();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -255,6 +263,9 @@ void dcfg_destroy_instance(dcfg_Instance *instance)
|
||||
{
|
||||
assert(instance);
|
||||
|
||||
vector_free(instance->source_pathv);
|
||||
vector_free(instance->sourcev);
|
||||
|
||||
pthread_mutex_lock(&instance->mtx);
|
||||
{ // De-init other instance things
|
||||
}
|
||||
@@ -1109,8 +1120,8 @@ dcfg_Value *dcfg_parse(dcfg_Instance *instance, dcfg_StringView const file_path)
|
||||
|
||||
StringView str = {
|
||||
.size = size,
|
||||
.data = ALLOC(size),
|
||||
};
|
||||
str.data = ALLOC(size);
|
||||
if (!fread((void *)str.data, str.size, 1, fp)) {
|
||||
FREE(abs);
|
||||
FREE((void *)str.data);
|
||||
@@ -1150,6 +1161,12 @@ dcfg_Value *dcfg_parse(dcfg_Instance *instance, dcfg_StringView const file_path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vector_add(&instance->sourcev, str);
|
||||
vector_add(&instance->source_pathv, abs_sv);
|
||||
|
||||
v->i_sourcev_idx = vector_size(instance->sourcev) - 1;
|
||||
v->i_source_pathv_idx = vector_size(instance->source_pathv) - 1;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user