From a88ad680422949dfe2d16a544a529649c6d07109 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Mon, 31 May 2021 17:08:09 +0100 Subject: Update build system to the latest luiml version --- .compile.do | 13 ++++++++ .gitignore | 9 ++++-- .licignore | 4 +-- .link-executable.do | 12 ++++++++ .link-library.do | 12 ++++++++ .parse-depfile | 15 ++++++++++ README.md | 20 +++++-------- all.do | 2 +- clean | 3 ++ configure | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++-- default.o.do | 9 +++--- libpack.so.do | 4 +++ link | 4 --- loadargs | 8 ----- scripts/clean | 2 -- test.do | 7 +++-- test.inc.do | 4 +-- test_gen.do | 7 +++-- trace.h | 6 +--- 19 files changed, 174 insertions(+), 53 deletions(-) create mode 100755 .compile.do create mode 100755 .link-executable.do create mode 100755 .link-library.do create mode 100755 .parse-depfile create mode 100755 clean create mode 100644 libpack.so.do delete mode 100644 link delete mode 100644 loadargs delete mode 100755 scripts/clean diff --git a/.compile.do b/.compile.do new file mode 100755 index 0000000..310ddd5 --- /dev/null +++ b/.compile.do @@ -0,0 +1,13 @@ +#!/bin/bash -e +redo-ifchange .config.rc +. ./.config.rc +exec >"$3" +echo "# generated by $0" +echo "CC=$CC" +echo "CFLAGS=(${CFLAGS[@]@Q})" +echo "CPPFLAGS=(${CPPFLAGS[@]@Q})" +echo '"$CC" -MMD -MF "${1%.o}.d" "${CFLAGS[@]}" "${CPPFLAGS[@]}" -c -o "$3" "${1%.o}.c"' +command -v redo-stamp >/dev/null 2>&1 && redo-stamp <"$3" +if command -v redo-stamp >/dev/null 2>&1; then + redo-stamp <"$3" +fi diff --git a/.gitignore b/.gitignore index 4dc4c13..c25a647 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,11 @@ *.d -*.o *.inc -*.args +*.o +*.so +.compile +.config.rc +.link-executable +.link-library +.redo/ test test_gen diff --git a/.licignore b/.licignore index 65dca50..29d1e7b 100644 --- a/.licignore +++ b/.licignore @@ -1,9 +1,9 @@ *.do .gitignore .licignore +.parse-depfile LICENSE README.md +clean configure -link -loadargs scripts/ diff --git a/.link-executable.do b/.link-executable.do new file mode 100755 index 0000000..4d7abdd --- /dev/null +++ b/.link-executable.do @@ -0,0 +1,12 @@ +#!/bin/bash -e +redo-ifchange .config.rc +. ./.config.rc +exec >"$3" +echo "# generated by $0" +echo "CC=$CC" +echo "LDFLAGS=(${LDFLAGS[@]@Q})" +echo "LDLIBS=(${LDLIBS[@]@Q})" +echo '"$CC" "${LDFLAGS[@]}" "${objects[@]}" "${LDLIBS[@]}" -o "$3"' +if command -v redo-stamp >/dev/null 2>&1; then + redo-stamp <"$3" +fi diff --git a/.link-library.do b/.link-library.do new file mode 100755 index 0000000..09aaf90 --- /dev/null +++ b/.link-library.do @@ -0,0 +1,12 @@ +#!/bin/bash -e +redo-ifchange .config.rc +. ./.config.rc +exec >"$3" +echo "# generated by $0" +echo "CC=$CC" +echo "LDFLAGS=(${LDFLAGS[@]@Q} -shared)" +echo "LDLIBS=(${LDLIBS[@]@Q})" +echo '"$CC" "${LDFLAGS[@]}" "${objects[@]}" "${LDLIBS[@]}" -o "$3"' +if command -v redo-stamp >/dev/null 2>&1; then + redo-stamp <"$3" +fi diff --git a/.parse-depfile b/.parse-depfile new file mode 100755 index 0000000..cad20d9 --- /dev/null +++ b/.parse-depfile @@ -0,0 +1,15 @@ +#!/usr/bin/sed -f +# remove target +1s/^[^:]*: // +# collapse lines +:loop +/\\$/ { + N + s/ \\\n// + b loop +} +# split on unescaped spaces +s/\([^\]\) /\1\ +/g +# unescape spaces +s/\\ / /g diff --git a/README.md b/README.md index a6a337c..ddfec17 100644 --- a/README.md +++ b/README.md @@ -6,32 +6,26 @@ Pack is a simple serialisation and deserialisation library for C. Dependencies ------------ -- A DJB redo compatible redo implementation +- A apenwarr redo compatible redo implementation - A relatively recent copy of bash -- gcc with C11 support (To use clang, edit `link` and `default.o.do`) +- A c compiler with C11 support Compilation ----------- -Optionally run `./configure release` to enable good additional default flags. -Alternatively, copy the files in `args/release/` to the project root and add -additional linker or compiler arguments necessary to build on your machine into -link.args and compile.args respectively. Please report flags necessary to build -on your platform so that they can be documented and potentially even -auto-detected. - -Run `redo` to build the code and tests. +Run `./configure` (see `./configure -h` for additional options). +Run `redo all` to build the code and tests. Testing ------- -Run `test` to run all the tests. +Run `./test` to run all the tests. Development ----------- -Development args for the compiler and linker are stored in `args/devel/` and can -be copied from there manually or symlinked with `./configure devel`. +Please configure with `-w` and ensure code compiles cleanly. Although compiler +versions can enable different warnings. Contributing ------------ diff --git a/all.do b/all.do index 0c001aa..749f446 100644 --- a/all.do +++ b/all.do @@ -1,2 +1,2 @@ #!/bin/sh -redo-ifchange "$0" "test" +redo-ifchange libpack.so test diff --git a/clean b/clean new file mode 100755 index 0000000..5b42c43 --- /dev/null +++ b/clean @@ -0,0 +1,3 @@ +#!/bin/sh +find . -type f \( -name '*.d' -o -name '*.o' -o -name '*.inc' \) -exec rm -f {} + +rm -f .compile .link-library .link-executable test_gen test diff --git a/configure b/configure index 70a0698..d3ea49e 100755 --- a/configure +++ b/configure @@ -1,5 +1,85 @@ -#!/bin/sh +#!/bin/bash -for f in args/"$1"/*; do - ln -sf "$f" +warnings=( + -Wall -Wcast-align -Wcast-qual -Wextra -Wpedantic -Wformat=2 + -Winit-self -Wmissing-prototypes -Wpointer-arith -Wshadow + -Wstrict-prototypes -Wsuggest-attribute=format + -Wsuggest-attribute=noreturn +) + +CFLAGS+=(-std=c11 -fPIC) + +usage () { echo "Usage: $0 [-h|options...]"; } + +help () { + cat </dev/null 2>&1; then + echo "$p" + return + fi + done + echo "$what not set or found" >&2 + return 1 +} + + +CC=$(check '$CC, cc, gcc or clang' "$CC" cc gcc clang) || exit + +colour=auto +while getopts B:C:L:P:c:defhovw opt; do + case $opt in + B) LDLIBS+=("$OPTARG");; + C) CFLAGS+=("$OPTARG");; + L) LDFLAGS+=("$OPTARG");; + P) CPPFLAGS+=("$OPTARG");; + c) colour="$OPTARG";; + d) CFLAGS+=(-Og -g); LDFLAGS+=(-Og -g);; + e) CFLAGS+=(-Werror);; + f) gen_flags=1;; + h) usage; help; exit;; + o) CFLAGS+=(-O2 -flto); LDFLAGS+=(-O2 -flto);; + v) verbose=1;; + w) CFLAGS+=("${warnings[@]}");; + ?) usage >&2; exit 1;; + esac done +if [[ $colour == auto && -t 1 ]]; then + colour=always +fi +if [[ $colour == always ]]; then + CFLAGS+=(-fdiagnostics-color) +fi + +{ + echo "# generated using $0 $@" + echo "CC=$CC" + echo "CFLAGS=(${CFLAGS[@]@Q})" + echo "CPPFLAGS=(${CPPFLAGS[@]@Q})" + echo "LDFLAGS=(${LDFLAGS[@]@Q})" + echo "LDLIBS=(${LDLIBS[@]@Q})" +} >.config.rc +[[ $verbose ]] && cat .config.rc +[[ $gen_flags ]] && printf '%s\n' "${CFLAGS[@]}" "${CPPFLAGS[@]}" >compile_flags.txt diff --git a/default.o.do b/default.o.do index adab49b..121c3c0 100644 --- a/default.o.do +++ b/default.o.do @@ -1,5 +1,4 @@ -#!/bin/bash -redo-ifchange "$0" "default.o.do" "$2.c" -. loadargs "compile" -gcc -std=c11 -MD -MF "$2.d" -c "${args[@]}" -o "$3" "$2.c" || exit 1 -redo-ifchange "$2.d" $(sed ':a;/\\$/{s/[^:]*: //;N;s/ \\\n//;ba}' <"$2.d") +#!/bin/bash -e +redo-ifchange .compile .parse-depfile "${1%.o}.c" +. ./.compile +./.parse-depfile "${1%.o}.d" | tr '\n' '\0' | xargs -0 redo-ifchange diff --git a/libpack.so.do b/libpack.so.do new file mode 100644 index 0000000..d656dbc --- /dev/null +++ b/libpack.so.do @@ -0,0 +1,4 @@ +#!/bin/bash -e +objects=(common.o pack.o trace.o unpack.o) +redo-ifchange .link-library "${objects[@]}" +. ./.link-library diff --git a/link b/link deleted file mode 100644 index 08006ad..0000000 --- a/link +++ /dev/null @@ -1,4 +0,0 @@ -#/fake/bash -redo-ifchange "$0" "link" "${deps[@]}" -. loadargs "link" -gcc "${args[@]}" -o "$3" "${deps[@]}" diff --git a/loadargs b/loadargs deleted file mode 100644 index 3ec8b0d..0000000 --- a/loadargs +++ /dev/null @@ -1,8 +0,0 @@ -#/fake/bash -if [ -r "$1.args" ]; then - redo-ifchange "$1.args" - mapfile -t args <"$1.args" -else - redo-ifcreate "$1.args" - args=() -fi diff --git a/scripts/clean b/scripts/clean deleted file mode 100755 index 42574c9..0000000 --- a/scripts/clean +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -find . \( -name '*.d' -o -name '*.o' -o -name '*.inc' -o -name 'test_gen' -o -name 'test' \) -delete diff --git a/test.do b/test.do index 158390a..f878369 100644 --- a/test.do +++ b/test.do @@ -1,3 +1,4 @@ -#!/bin/bash -deps=(common.o pack.o test.o trace.o unpack.o) -. ./link +#!/bin/bash -e +objects=(common.o pack.o test.o trace.o unpack.o) +redo-ifchange .link-executable "${objects[@]}" +. ./.link-executable diff --git a/test.inc.do b/test.inc.do index c6d5c1b..1fcd448 100644 --- a/test.inc.do +++ b/test.inc.do @@ -1,3 +1,3 @@ #!/bin/sh -redo-ifchange "$0" "test_gen" -./test_gen +redo-ifchange test_gen +./test_gen >$3 diff --git a/test_gen.do b/test_gen.do index ed0f2e4..c1b6dc6 100644 --- a/test_gen.do +++ b/test_gen.do @@ -1,3 +1,4 @@ -#!/bin/bash -deps=(test_gen.o) -. ./link +#!/bin/bash -e +objects=(test_gen.o) +redo-ifchange .link-executable "${objects[@]}" +. ./.link-executable diff --git a/trace.h b/trace.h index 8dee696..3b3cfa1 100644 --- a/trace.h +++ b/trace.h @@ -1,15 +1,11 @@ /* - * Copyright (C) 2020 Tomasz Kramkowski + * Copyright (C) 2020-2021 Tomasz Kramkowski * SPDX-License-Identifier: MIT */ #ifndef PACK_TRACE_H #define PACK_TRACE_H -#ifdef DEVEL #define ATTRIBUTE_FORMAT(type, fmt, args) __attribute__((format(type, fmt, args))) -#else -#define ATTRIBUTE_FORMAT(type, fmt, args) -#endif ATTRIBUTE_FORMAT(printf, 1, 2) void tr_call(const char *fmt, ...); -- cgit v1.2.3-54-g00ecf