rsys

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

commit dfea845873e77743c9fe85ef9d23b7273f67ff84
parent da4fa54ef1e49351f2ac6930b4f637fde5e40daa
Author: vaplv <vaplv@free.fr>
Date:   Wed, 30 Mar 2022 17:24:45 +0200

Refactoring of the Makefile

Diffstat:
MMakefile | 23+++++++----------------
Amake.sh | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile @@ -198,22 +198,10 @@ test: build_tests .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 + @$(SHELL) make.sh config_test $(TEST_SRC) > .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 " \e[1;32mOK\e[m\n" \ - || { printf " \e[1;31mErreur\e[m\n"; n=$$((n+1)); }; \ - done; \ - if [ "$${n}" -ne 0 ]; then printf "%d errors\n" "$${n}"; exit 1; fi + @$(SHELL) make.sh run_test $(TEST_SRC) src/test_algorithm.o \ src/test_atomic.o \ @@ -325,6 +313,10 @@ test_lib.o: src/test_library.c src/rsys.h libtest_lib.so: test_lib.o $(CC) $(CFLAGS) -shared -o $@ test_lib.o +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) + test_library: libtest_lib.so ################################################################################ @@ -332,10 +324,9 @@ test_library: libtest_lib.so ################################################################################ all: build_library build_tests -clean: +clean: clean_test @rm -f $(OBJ) $(TEST_OBJ) librsys.so libtest_lib.so test_lib.o .test \ rsys.pc .test.ppm test_text_reader.txt test.ppm - @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/make.sh b/make.sh @@ -0,0 +1,63 @@ +#!/bin/sh -e + +# 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/>. + +config_test() +{ + if [ $# -lt 1 ]; then + echo "usage: config_test [src ...]" >&2 + exit 1 + fi + + for i in "$@"; do + test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/') + test_list="${test_list} ${test}" + printf "%s: %s\n" "${test}" "src/${test}.o" + done + printf "test_bin: %s\n" "${test_list}" +} + +run_test() +{ + n=0 + + for i in "$@"; do + test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/') + + printf "%s " "${test}" + if ./"${test}" > /dev/null 2>&1; then + printf "\e[1;32mOK\e[m\n" + else + printf "\e[1;31mErreur\e[m\n" + n=$((n+1)) + fi + done + + if [ "${n}" -ne 0 ]; then + printf "%d errors\n" "${n}" + exit 1 + fi +} + +clean_test() +{ + for i in "$@"; do + test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/') + rm -f "${test}" + done +} + +"$@"