commit be9f53a1ee5be6930b0f6da513a4be3783fb8966
parent cb9d077919f402c6da6c4c99caafb0ac5fdc1c79
Author: vaplv <vaplv@free.fr>
Date: Sun, 30 Jan 2022 18:17:49 +0100
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| A | Makefile | | | 321 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 10 | ++++++++++ |
2 files changed, 331 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,321 @@
+# Copyright (C) 2013-2021 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/>.
+
+.POSIX:
+.SUFFIXES: # Clean up default inference rules
+
+include config.mk
+
+################################################################################
+# 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) librsys.so
+
+$(OBJ): config.mk
+
+librsys.so: $(OBJ)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ)
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @echo "Computing dependencies for $<"
+ @$(CC) $(CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ $(CC) $(CFLAGS) -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
+
+install: build_library
+ mkdir -p $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include/rsys
+ cp librsys.so $(DESTDIR)$(PREFIX)/lib
+ cp $(API) $(DESTDIR)$(PREFIX)/include/rsys
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/librsys.so
+ rm -f $$(echo $(API) | sed 's,src\/,$(DESTDIR)$(PREFIX)\/include\/rsys\/,g')
+
+################################################################################
+# 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)
+
+build_tests: build_library $(TEST_DEP) .test
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
+
+$(TEST_OBJ): config.mk
+
+test: build_tests
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_run
+
+.test: Makefile
+ @echo "Setup tests"
+ @{ for i in $(TEST_SRC); do \
+ test=$$(echo "$${i}" | sed 's/src\/\(.\{1,\}\).c$$/\1/'); \
+ printf "test_bin: %s\n" "$${test}"; \
+ printf "%s: %s\n" "$${test}" "src/$${test}.o"; \
+ done; } > .test
+
+test_run: test_bin
+ @n=0; \
+ for i in $(TEST_SRC); do \
+ test=$$(echo $${i} | sed 's/src\/\(.\{1,\}\).c$$/\1/'); \
+ printf "%s" $${test}; \
+ ./"$${test}" > /dev/null 2>&1 \
+ && printf "\n" "$${test}" \
+ || { printf " [Error]\n"; n=$$((n+1)); }; \
+ done; \
+ [ "$${n}" -ne 0 ] && { echo "$${n} errors" && exit 1; }
+
+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 \
+:
+ $(CC) $(CFLAGS) -c $(@:.o=.c) -o $@
+
+src/test_cstr.o \
+:
+ $(CC) $(CFLAGS) -Wno-long-long -c $(@:.o=.c) -o $@
+
+src/test_condition.o \
+src/test_mutex.o \
+:
+ $(CC) $(CFLAGS) -fopenmp -c $(@:.o=.c) -o $@
+
+test_algorithm \
+test_atomic \
+test_endianness \
+test_func_name \
+test_misc \
+test_morton \
+test_ref \
+test_vmacros \
+:
+ $(CC) $(CFLAGS) -o $@ src/$@.o
+
+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 \
+:
+ $(CC) $(CFLAGS) -o $@ src/$@.o -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 \
+: librsys.so
+ $(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -lrsys
+
+test_quaternion \
+: librsys.so
+ $(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -lrsys -lm
+
+
+test_condition \
+test_mutex \
+: librsys.so
+ $(CC) $(CFLAGS) -o $@ src/$@.o -fopenmp -L$$(pwd) -lrsys -lm
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean:
+ @rm -f $(OBJ) $(TEST_OBJ) librsys.so .test
+ @rm -f $$(for i in $(TEST_SRC); do echo $${i} | sed 's/src\/\(.\{1,\}\).c$$/\1/'; done)
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
diff --git a/config.mk b/config.mk
@@ -0,0 +1,10 @@
+VERSION = 0.12.0
+
+PREFIX = /usr/local
+
+CPPFLAGS = -DNDEBUG
+WFLAGS = -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wconversion -Wshadow
+CFLAGS = -O2 -std=c89 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS)
+LDFLAGS = -shared -ldl -lpthread -lm
+
+CC = cc