rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 5ef2b0e9c4fb08dd5a5a0b4f7ecb04659cb5777f
parent a7e130e82628da320bd5f9c237e5f72568d12c80
Author: vaplv <vaplv@free.fr>
Date:   Wed, 18 Oct 2023 10:41:04 +0200

Merge branch 'feature_posix_make' into develop

Diffstat:
M.gitignore | 11++++++-----
AMakefile | 359+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 36++++++++++++++++++++----------------
Dcmake/CMakeLists.txt | 284-------------------------------------------------------------------------------
Aconfig.mk | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arsys.pc.in | 10++++++++++
Msrc/mem_proxy_allocator.c | 1-
Msrc/morton.h | 2+-
Msrc/test_time.c | 2+-
10 files changed, 536 insertions(+), 308 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,10 +1,11 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp [Bb]uild* *.sw[po] -*.[ao] +*.[aod] +*.so *~ +test* +!test*.[ch] +.test tags +*.pc diff --git a/Makefile b/Makefile @@ -0,0 +1,359 @@ +# Copyright (C) 2013-2023 Vincent Forest (vaplv@free.fr) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +LIBNAME_STATIC = librsys.a +LIBNAME_SHARED = librsys.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +################################################################################ +# RSys building +################################################################################ +SRC =\ + src/clock_time.c\ + src/cstr.c\ + src/hash.c\ + src/image.c\ + src/library.c\ + src/logger.c\ + src/mem_allocator.c\ + src/mem_lifo_allocator.c\ + src/mem_proxy_allocator.c\ + src/pthread/pthread_condition.c\ + src/pthread/pthread_mutex.c\ + src/quaternion.c\ + src/str.c\ + src/text_reader.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_library: $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ + $$(if [ -n "$(LIBNAME)" ]; then\ + echo "$(LIBNAME)";\ + else\ + echo "$(LIBNAME_SHARED)";\ + fi) + +$(DEP) $(OBJ): config.mk + +$(LIBNAME_SHARED): $(OBJ) + $(CC) $(CFLAGS_SO) -o $@ $(OBJ) $(LDFLAGS_SO) $(LIBS) + +$(LIBNAME_STATIC): librsys.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +librsys.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS_SO) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS_SO) -DRSYS_SHARED_BUILD -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +API =\ + src/algorithm.h\ + src/binary_heap.h\ + src/clock_time.h\ + src/condition.h\ + src/cstr.h\ + src/double2.h\ + src/double3.h\ + src/double4.h\ + src/double22.h\ + src/double33.h\ + src/double44.h\ + src/dynamic_array.h\ + src/dynamic_array_char.h\ + src/dynamic_array_double.h\ + src/dynamic_array_float.h\ + src/dynamic_array_int.h\ + src/dynamic_array_uchar.h\ + src/dynamic_array_u32.h\ + src/dynamic_array_u64.h\ + src/dynamic_array_uint.h\ + src/dynamic_array_size_t.h\ + src/dynamic_array_str.h\ + src/endianness.h\ + src/float2.h\ + src/float3.h\ + src/float4.h\ + src/float22.h\ + src/float33.h\ + src/float44.h\ + src/free_list.h\ + src/hash.h\ + src/hash_table.h\ + src/image.h\ + src/library.h\ + src/list.h\ + src/logger.h\ + src/math.h\ + src/mem_allocator.h\ + src/morton.h\ + src/mutex.h\ + src/quaternion.h\ + src/real2.h\ + src/real3.h\ + src/realX.h\ + src/realX_begin.h\ + src/realX_end.h\ + src/real22.h\ + src/real33.h\ + src/real44.h\ + src/realXY.h\ + src/realXY_begin.h\ + src/realXY_end.h\ + src/ref_count.h\ + src/rsys.h\ + src/signal.h\ + src/str.h\ + src/stretchy_array.h\ + src/text_reader.h + +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + rsys.pc.in > rsys.pc + +# Remove the include directive rather than setting it to "./src". to prevent +# the source directory from having a higher priority than the system include +# directories. In such a situation, the local "math.h" file could be included +# instead of the "math.h" header provided by the C standard library. Note that +# this is no longer a problem with the common pc file: the "math.h" file is +# installed in the "rsys" subdirectory, which is therefore a prefix of the +# header file allowing it to be distinguished from the header of the standard +# library +rsys-local.pc: rsys.pc.in + sed -e '1,2d'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#-I$${includedir}##g'\ + rsys.pc.in > $@ + +install: build_library pkg + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/" $(LIBNAME) + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/rsys" COPYING README.md + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" rsys.pc + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/rsys" $(API) + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/rsys.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/rsys/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/rsys/README.md" + rm -f $$(echo $(API) | sed 's,src\/,$(DESTDIR)$(PREFIX)\/include\/rsys\/,g') + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_tests + +clean: clean_test + rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) librsys.o + rm -f rsys.pc rsys-local.pc + rm -f libtest_lib.so test_lib.o + rm -f .test rsys.pc .test.ppm test_text_reader.txt test.ppm + +distclean: clean + rm -f $(DEP) $(TEST_DEP) + +lint: + shellcheck -o all make.sh + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_algorithm.c\ + src/test_atomic.c\ + src/test_binary_heap.c\ + src/test_condition.c\ + src/test_cstr.c\ + src/test_double22.c\ + src/test_double2.c\ + src/test_double33.c\ + src/test_double3.c\ + src/test_double44.c\ + src/test_double4.c\ + src/test_dynamic_array.c\ + src/test_endianness.c\ + src/test_float22.c\ + src/test_float2.c\ + src/test_float33.c\ + src/test_float3.c\ + src/test_float44.c\ + src/test_float4.c\ + src/test_free_list.c\ + src/test_func_name.c\ + src/test_hash_table.c\ + src/test_hash_sha256.c\ + src/test_image.c\ + src/test_library.c\ + src/test_list.c\ + src/test_logger.c\ + src/test_math.c\ + src/test_mem_allocator.c\ + src/test_misc.c\ + src/test_morton.c\ + src/test_mutex.c\ + src/test_quaternion.c\ + src/test_ref.c\ + src/test_signal.c\ + src/test_str.c\ + src/test_stretchy_array.c\ + src/test_text_reader.c\ + src/test_time.c\ + src/test_vmacros.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +RSYS_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys-local.pc) +RSYS_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys-local.pc) + +build_tests: build_library $(TEST_DEP) .test + @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin + +$(TEST_DEP) $(TEST_OBJ): config.mk + +test: build_tests + @$(SHELL) make.sh run_test $(TEST_SRC) + +.test: Makefile + @echo "Setup tests" + @$(SHELL) make.sh config_test $(TEST_SRC) > .test + +clean_test: + @rm -f libtest_lib.so test_lib.o .test .test.ppm test_text_reader.txt test.ppm + @$(SHELL) make.sh clean_test $(TEST_SRC) + +src/test_algorithm.o \ +src/test_atomic.o \ +src/test_binary_heap.o \ +src/test_double22.o \ +src/test_double2.o \ +src/test_double33.o \ +src/test_double3.o \ +src/test_double44.o \ +src/test_double4.o \ +src/test_dynamic_array.o \ +src/test_endianness.o \ +src/test_float22.o \ +src/test_float2.o \ +src/test_float33.o \ +src/test_float3.o \ +src/test_float44.o \ +src/test_float4.o \ +src/test_free_list.o \ +src/test_func_name.o \ +src/test_hash_sha256.o \ +src/test_hash_table.o \ +src/test_image.o \ +src/test_library.o \ +src/test_list.o \ +src/test_logger.o \ +src/test_math.o \ +src/test_mem_allocator.o \ +src/test_misc.o \ +src/test_morton.o \ +src/test_quaternion.o \ +src/test_ref.o \ +src/test_signal.o \ +src/test_str.o \ +src/test_stretchy_array.o \ +src/test_text_reader.o \ +src/test_time.o \ +src/test_vmacros.o \ +: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + +src/test_cstr.o: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) -Wno-long-long -c $(@:.o=.c) -o $@ + +src/test_condition.o src/test_mutex.o: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) -fopenmp -c $(@:.o=.c) -o $@ + +test_algorithm \ +test_atomic \ +test_endianness \ +test_func_name \ +test_misc \ +test_morton \ +test_ref \ +test_vmacros \ +: config.mk + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) + +test_double22 \ +test_double2 \ +test_double33 \ +test_double3 \ +test_double44 \ +test_double4 \ +test_float22 \ +test_float2 \ +test_float33 \ +test_float3 \ +test_float44 \ +test_float4 \ +test_math \ +: config.mk + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) -lm + +test_binary_heap\ +test_cstr \ +test_dynamic_array \ +test_free_list \ +test_hash_sha256 \ +test_hash_table \ +test_image \ +test_library \ +test_list \ +test_logger \ +test_mem_allocator \ +test_signal \ +test_str \ +test_stretchy_array \ +test_text_reader \ +test_time \ +: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS) + +test_quaternion: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS) -lm + +test_condition test_mutex: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS) -lm -fopenmp + +test_lib.o: src/test_library.c src/rsys.h config.mk + $(CC) $(CFLAGS_SO) -c src/test_library.c -DTEST_LIBRARY_BUILD_LIB -o $@ + +libtest_lib.so: test_lib.o config.mk + $(CC) $(CFLAGS_SO) -o $@ test_lib.o $(LDFLAGS_SO) + +test_library: libtest_lib.so diff --git a/README.md b/README.md @@ -1,19 +1,23 @@ # RSys -C89 library defining several basic components helpful in the development of C -libraries/applications. Among others, it provides macros that describe the host -environment (OS, compiler, etc.) several low level functionalities (thread, -timer, ref counter, etc.), generic containers (dynamic array, hash table, etc.) -and basic mathematics (linear algebra, quaternions, etc.) +RSys is a library written in C89 defining several basic components useful for +developing C programs but not implemented in the standard C library. Among +other things, it provides macros describing the host environment (OS, compiler, +processor architecture, etc.), low-level abstractions (thread, timer, ref +counter, etc.), generic containers (dynamic arrays, table of hashes, linked +lists etc.) or even basic linear algebra to manipulate vectors and matrices of +dimensions 2, 3 or 4. -## How to build +## Requirements -The RSys library uses [CMake](http://www.cmake.org) and the -[RCMake](https://gitlab.com/vaplv/rcmake/#tag-readme) package to build. First, -install the RCMake package in a given `<RCMAKE_DIR>` directory. Then, generate -the CMake project from the `cmake/CMakeLists.txt` file by appending the -`<RCMAKE_DIR>` directory to the `CMAKE_PREFIX_PATH` variable. The resulting -project can be now edited, built, tested and installed as any CMake project. +- C compiler +- POSIX make + +## Installation + +Edit config.mk as needed, then run: + + make clean install ## Release notes @@ -165,8 +169,8 @@ project can be now edited, built, tested and installed as any CMake project. ## License -Copyright (C) 2013-2023 Vincent Forest (vaplv@free.fr). RSys is free software -released under the GPL v3+ license: GNU GPL version 3 or later. You are welcome -to redistribute it under certain conditions; refer to the COPYING files for -details. +Copyright © 2013-2023 Vincent Forest (vaplv@free.fr) +RSys is free software released under the GPL v3+ license: GNU GPL version 3 or +later. You are welcome to redistribute it under certain conditions; refer to +the COPYING files for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,284 +0,0 @@ -# Copyright (C) 2013-2023 Vincent Forest (vaplv@free.fr) -# -# This CMake script is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This CMake script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this CMake script. If not, see <http://www.gnu.org/licenses/>. - -cmake_minimum_required(VERSION 3.0) -project(rsys C) -enable_testing() - -if(POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) -endif() - -set(RSYS_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -option(NO_TEST "Disable the test" OFF) - -################################################################################ -# Check dependencies -################################################################################ -find_package(OpenMP) -find_package(RCMake REQUIRED) -find_package(Threads REQUIRED) - -set(CMAKE_MODULE_PATH ${RCMAKE_SOURCE_DIR}) -include(rcmake) - -################################################################################ -# Configure and define targets -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 13) -set(VERSION_PATCH 0) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -set(RSYS_FILES_SRC - clock_time.c - cstr.c - hash.c - image.c - library.c - logger.c - mem_allocator.c - mem_lifo_allocator.c - mem_proxy_allocator.c - quaternion.c - str.c - text_reader.c) - -if(CMAKE_USE_PTHREADS_INIT) - set(RSYS_FILES_SRC_THREAD - pthread/pthread_condition.c - pthread/pthread_mutex.c) -elseif(CMAKE_USE_WIN32_THREADS_INIT) - set(RSYS_FILES_SRC_THREAD - win32/win32_condition.c - win32/win32_mutex.c) -endif() - -set(RSYS_FILES_INC - io_c99.h) -set(RSYS_FILES_INC_API - algorithm.h - binary_heap.h - clock_time.h - condition.h - cstr.h - double2.h - double3.h - double4.h - double22.h - double33.h - double44.h - dynamic_array.h - dynamic_array_char.h - dynamic_array_double.h - dynamic_array_float.h - dynamic_array_int.h - dynamic_array_uchar.h - dynamic_array_u32.h - dynamic_array_u64.h - dynamic_array_uint.h - dynamic_array_size_t.h - dynamic_array_str.h - endianness.h - float2.h - float3.h - float4.h - float22.h - float33.h - float44.h - free_list.h - hash.h - hash_table.h - image.h - library.h - list.h - logger.h - math.h - mem_allocator.h - morton.h - mutex.h - quaternion.h - real2.h - real3.h - realX.h - realX_begin.h - realX_end.h - real22.h - real33.h - real44.h - realXY.h - realXY_begin.h - realXY_end.h - ref_count.h - rsys.h - signal.h - str.h - stretchy_array.h - text_reader.h) - -set(RSYS_FILES_DOC COPYING README.md) - -# Prepend each file in the `_files' list by `_path' -rcmake_prepend_path(RSYS_FILES_SRC ${RSYS_SOURCE_DIR}) -rcmake_prepend_path(RSYS_FILES_SRC_THREAD ${RSYS_SOURCE_DIR}) -rcmake_prepend_path(RSYS_FILES_INC ${RSYS_SOURCE_DIR}) -rcmake_prepend_path(RSYS_FILES_INC_API ${RSYS_SOURCE_DIR}) -rcmake_prepend_path(RSYS_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -add_library(rsys SHARED - ${RSYS_FILES_SRC} - ${RSYS_FILES_SRC_THREAD} - ${RSYS_FILES_INC} - ${RSYS_FILES_INC_API}) -set_target_properties(rsys - PROPERTIES DEFINE_SYMBOL RSYS_SHARED_BUILD - DEFINE_SYMBOL RSYS_SHARED_BUILD - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -target_link_libraries(rsys ${CMAKE_THREAD_LIBS_INIT}) -if(CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(rsys m) - if(NOT MINGW) - target_link_libraries(rsys dl) - endif() - - # On GLIBC version before 2.17 one has to link with the "rt" library to use - # the clock_gettime function. - find_library(_GLIBC NAMES glib-2.0) - get_filename_component(_GLIB_LIBRARY_DIR ${_GLIBC} PATH) - find_path(_GLIBCONFIG_INCLUDE_DIR NAMES glibconfig.h - HINTS ${_GLIB_LIBRARY_DIR} PATH_SUFFIXES glib-2.0/include) - - if(_GLIBCONFIG_INCLUDE_DIR) - file(STRINGS "${_GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" - _GLIB_MAJOR_LINE REGEX "^#define[ \t]+GLIB_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${_GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" - _GLIB_MINOR_LINE REGEX "^#define[ \t]+GLIB_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${_GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" - _GLIB_PATCH_LINE REGEX "^#define[ \t]+GLIB_MICRO_VERSION[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+GLIB_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" - _GLIB_MAJOR "${_GLIB_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+GLIB_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" - _GLIB_MINOR "${_GLIB_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+GLIB_MICRO_VERSION[ \t]+([0-9]+)$" "\\1" - _GLIB_PATCH "${_GLIB_PATCH_LINE}") - set(_GLIB_VERSION "${_GLIB_MAJOR}.${_GLIB_MINOR}.${_GLIB_PATCH}") - if("${_GLIBC_VERSION}" VERSION_LESS "2.17") - target_link_libraries(rsys rt) - endif() - endif() - -endif() - -rcmake_setup_devel(rsys RSys ${VERSION} rsys/rsys_version.h) - -################################################################################ -# Add tests -################################################################################ -if(NOT NO_TEST) - macro(new_test _name) - add_executable(${_name} ${RSYS_SOURCE_DIR}/${_name}.c) - set(_libraries ${ARGN}) - foreach(_lib ${_libraries}) - target_link_libraries(${_name} ${_lib}) - endforeach() - add_test(${_name} ${_name}) - endmacro() - - if(CMAKE_COMPILER_IS_GNUCC) - set(MATH_LIB m) - endif() - - new_test(test_algorithm) - new_test(test_atomic) - new_test(test_binary_heap rsys) - new_test(test_cstr rsys) - new_test(test_double2 ${MATH_LIB}) - new_test(test_double3 ${MATH_LIB}) - new_test(test_double4 ${MATH_LIB}) - new_test(test_double22) - new_test(test_double33 ${MATH_LIB}) - new_test(test_double44) - new_test(test_endianness) - new_test(test_dynamic_array rsys) - new_test(test_float2 ${MATH_LIB}) - new_test(test_float3 ${MATH_LIB}) - new_test(test_float4 ${MATH_LIB}) - new_test(test_float22 ${MATH_LIB}) - new_test(test_float33 ${MATH_LIB}) - new_test(test_float44) - new_test(test_free_list rsys) - new_test(test_func_name) - new_test(test_hash_table rsys) - new_test(test_hash_sha256 rsys) - new_test(test_image rsys) - new_test(test_library rsys) - new_test(test_list rsys) - new_test(test_logger rsys) - new_test(test_math ${MATH_LIB}) - new_test(test_mem_allocator rsys) - new_test(test_misc) - new_test(test_morton) - new_test(test_quaternion rsys) - new_test(test_ref) - new_test(test_signal rsys) - new_test(test_str rsys) - new_test(test_stretchy_array rsys) - new_test(test_text_reader rsys) - new_test(test_time rsys) - new_test(test_vmacros) - - add_library(test_lib SHARED ${RSYS_SOURCE_DIR}/test_library.c) - set_target_properties(test_lib PROPERTIES - COMPILE_DEFINITIONS TEST_LIBRARY_BUILD_LIB - DEBUG_POSTFIX "") - - if(CMAKE_COMPILER_IS_GNUCC) - set_target_properties(test_cstr PROPERTIES COMPILE_FLAGS "-std=c99") - - # Remove a false positive warning - if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 5.4 - OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 7.3) - set_target_properties(test_binary_heap PROPERTIES COMPILE_FLAGS - "-Wno-aggressive-loop-optimizations") - endif() - endif() - - if(NOT OPENMP_FOUND) - message(STATUS "No OpenMP support: multi-threaded tests cannot be generated") - else() - new_test(test_mutex rsys) - new_test(test_condition rsys) - - set_target_properties(test_mutex test_condition PROPERTIES - COMPILE_FLAGS ${OpenMP_C_FLAGS}) - - if(CMAKE_COMPILER_IS_GNUCC) - set_target_properties(test_mutex test_condition PROPERTIES - LINK_FLAGS ${OpenMP_C_FLAGS}) - endif() - endif() -endif() - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS rsys - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${RSYS_FILES_INC_API} DESTINATION include/rsys) -install(FILES ${RSYS_FILES_DOC} DESTINATION share/doc/rsys) diff --git a/config.mk b/config.mk @@ -0,0 +1,71 @@ +VERSION = 0.14.0 +PREFIX = /usr/local + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +################################################################################ +# Tools +################################################################################ +CC = cc +AR = ar +LD = ld +OBJCOPY = objcopy +PKG_CONFIG = pkg-config +RANLIB = ranlib + +# pkg-config flags +PCFLAGS_SHARED = +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wconversion\ + -Wshadow + +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON =\ + -std=c89\ + -pedantic\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) +CFLAGS_SO = $(CFLAGS) -fPIC +CFLAGS_EXE = $(CFLAGS) -fPIE + +################################################################################ +# Linker options +################################################################################ +LIBS = -ldl -lpthread -lm + +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) + +LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined +LDFLAGS_EXE = $(LDFLAGS) -pie + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/make.sh b/make.sh @@ -0,0 +1,68 @@ +#!/bin/sh -e + +# Copyright (C) 2013-2023 Vincent Forest (vaplv@free.fr) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +config_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + test_list="${test_list} ${test}" + printf "%s: %s\n" "${test}" "src/${test}.o" + done + printf "test_bin: %s\n" "${test_list}" +} + +run_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + + printf "%s " "${test}" + if ./"${test}" > /dev/null 2>&1; then + printf "\033[1;32mOK\033[m\n" + else + printf "\033[1;31mError\033[m\n" + fi + done 2> /dev/null +} + +clean_test() +{ + for i in "$@"; do + rm -f "$(basename "${i}" ".c")" + done +} + +install() +{ + prefix=$1 + shift 1 + + mkdir -p "${prefix}" + + for i in "$@"; do + dst="${prefix}/${i##*/}" + + if cmp -s "${i}" "${dst}"; then + printf "Up to date %s\n" "${dst}" + else + printf "Installing %s\n" "${dst}" + cp "${i}" "${prefix}" + fi + done +} + +"$@" diff --git a/rsys.pc.in b/rsys.pc.in @@ -0,0 +1,10 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Name: RSys +Description: RSys library +Version: @VERSION@ +Libs: -L${libdir} -lrsys +Libs.private: -ldl -lpthread -lm +CFlags: -I${includedir} diff --git a/src/mem_proxy_allocator.c b/src/mem_proxy_allocator.c @@ -259,7 +259,6 @@ proxy_dump /******************************************************************************* * Exported functions ******************************************************************************/ - res_T mem_init_proxy_allocator (struct mem_allocator* proxy_allocator, diff --git a/src/morton.h b/src/morton.h @@ -94,7 +94,7 @@ morton_xyz_encode_u21(const uint32_t xyz[3]) static INLINE void morton_xyz_decode_u21(const uint64_t code, uint32_t xyz[3]) { - ASSERT(xyz && code < ((1ull << 63)-1)); + ASSERT(xyz && code < (((uint64_t)1 << 63)-1)); xyz[0] = (uint32_t)morton3D_decode_u21(code >> 2); xyz[1] = (uint32_t)morton3D_decode_u21(code >> 1); xyz[2] = (uint32_t)morton3D_decode_u21(code >> 0); diff --git a/src/test_time.c b/src/test_time.c @@ -53,7 +53,7 @@ main(int argc, char** argv) (void)argc, (void)argv; CHK(time_current(&start) == &start); - FOR_EACH(i, 0, INT32_MAX / 64) {}/* Active wait */ + FOR_EACH(i, 0, INT32_MAX / 64) {} /* Active wait */ CHK(time_current(&end) == &end); CHK(time_sub(&res, &end, &start) == &res);