diff --git a/.gitignore b/.gitignore index f7590b7..1cff3fc 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ valgrind.log # Simple test input for README demo my_input + +# Generated sources and headers +include/version.h diff --git a/Makefile b/Makefile index a886cce..9c1a54a 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,9 @@ DEP = $(SRC:.c=.d) MANP = docs/metang.1 -.PHONY: default all debug release install clean +VERSION_H = include/version.h + +.PHONY: default all debug release install clean version default: all @@ -48,11 +50,16 @@ install: release uninstall: rm -rf $(BINDEST)/$(TARGET) $(MANDEST)/$(MANP) -$(TARGET): $(OBJ) +version: $(VERSION_H) + +$(VERSION_H): VERSION + ./tools/version.sh $< $@ + +$(TARGET): $(VERSION_H) $(OBJ) $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(OBJ) clean: - $(RM) $(TARGET) $(OBJ) $(DEP) + $(RM) $(TARGET) $(OBJ) $(DEP) $(VERSION_H) include Makefile.dev-tools diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..17e51c3 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.1 diff --git a/include/meson.build b/include/meson.build index 3364ad6..6f38e7a 100644 --- a/include/meson.build +++ b/include/meson.build @@ -1 +1,11 @@ public_includes = include_directories('.') + +gen_version_h = custom_target( + 'version.h', + output: 'version.h', + command: [ + metang_version, + version, + '@OUTPUT@', + ], +) diff --git a/meson.build b/meson.build index 0be0feb..2d49b81 100644 --- a/meson.build +++ b/meson.build @@ -18,7 +18,7 @@ project( license: 'Apache-2.0', license_files: 'LICENSE', meson_version: '>=1.5.0', - version: '0.1.0', + version: run_command(['./tools/version.sh', 'VERSION'], check: true).stdout().strip(), default_options: { 'buildtype': 'release', # O3 'warning_level': '3', # all, extra, pedantic @@ -28,6 +28,7 @@ project( native = get_option('native') install = native and meson.is_cross_build() ? false : true +version = files('VERSION') # This must come before `tests`! subdir('tools') @@ -38,7 +39,10 @@ subdir('tests') metang_exe = executable( 'metang', - c_sources, + sources: [ + static_sources, + gen_version_h, + ], include_directories: public_includes, install: install, install_mode: 'rwxr-xr-x', diff --git a/src/meson.build b/src/meson.build index defcb95..8092304 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,4 +1,4 @@ -c_sources = files( +static_sources = files( 'deque.c', 'generate.c', 'metang.c', diff --git a/src/metang.c b/src/metang.c index 50d23c2..630bfdb 100644 --- a/src/metang.c +++ b/src/metang.c @@ -28,9 +28,10 @@ #include "deque.h" #include "generate.h" #include "strlib.h" +#include "version.h" // clang-format off -static const char *version = "0.1.0"; +static const char *version = METANG_VERSION; static const char *tag_line = "metang - Generate multi-purpose C headers for enumerators"; diff --git a/tools/meson.build b/tools/meson.build index 4802901..d3c59bc 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -1 +1,2 @@ metang_runtests = find_program('runtests.py', native: true) +metang_version = find_program('version.sh', native: true) diff --git a/tools/version.sh b/tools/version.sh new file mode 100755 index 0000000..3b9561b --- /dev/null +++ b/tools/version.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +if [[ "$#" -eq 0 ]]; then + echo "Usage: ./version.sh VERSION_FILE [INCLUDE_DEST]" + echo "" + echo "If INCLUDE_DEST is not given, then the contents of VERSION_FILE" + echo "will be written to standard output." + exit 1 +fi + +VERSION_FILE=$1 +INCLUDE_DEST=$2 + +VERSION=$(cat "${VERSION_FILE}") + +if [[ -n "$INCLUDE_DEST" ]]; then + { + echo "/* THIS FILE IS GENERATED; DO NOT MODIFY!!! */" + echo + echo "#ifndef METANG_VERSION_H" + echo "#define METANG_VERSION_H" + echo + echo "#define METANG_VERSION \"${VERSION}\"" + echo + echo "#endif /* METANG_VERSION_H */" + } >"${INCLUDE_DEST}" +else + echo "${VERSION}" +fi