mirror of
https://github.com/lhearachel/narc.git
synced 2025-06-18 13:35:32 -04:00
feat: Generate version at compilation time
This commit is contained in:
parent
6ea239eeca
commit
2109b614e5
3
.gitignore
vendored
3
.gitignore
vendored
@ -17,3 +17,6 @@ valgrind.log
|
||||
|
||||
# Testing files
|
||||
*.narc
|
||||
|
||||
# Generated files
|
||||
cli/include/version.h
|
||||
|
13
Makefile
13
Makefile
@ -41,11 +41,14 @@ CLIINC = $(wildcard cli/include/*.h)
|
||||
CLISRC = $(wildcard cli/src/*.c)
|
||||
CLIOBJ = $(CLISRC:.c=.o)
|
||||
CLIDEP = $(CLISRC:.c=.d)
|
||||
CLIVER = cli/include/version.h
|
||||
|
||||
ALLSRC = $(CLISRC) $(LIBSRC)
|
||||
ALLINC = $(CLIINC) $(LIBINC)
|
||||
|
||||
.PHONY: all cli lib debug release clean install
|
||||
VERSION = VERSION
|
||||
|
||||
.PHONY: all cli lib debug release clean install version
|
||||
|
||||
all: lib cli
|
||||
|
||||
@ -60,14 +63,18 @@ release: CFLAGS += -DNDEBUG -O3
|
||||
release: clean all
|
||||
|
||||
clean:
|
||||
$(RM) $(LIBTARGET) $(LIBOBJ) $(LIBDEP) $(CLITARGET) $(CLIOBJ) $(CLIDEP)
|
||||
$(RM) $(LIBTARGET) $(LIBOBJ) $(LIBDEP) $(CLITARGET) $(CLIOBJ) $(CLIDEP) $(CLIVER)
|
||||
|
||||
-include $(LIBDEP)
|
||||
-include $(CLIDEP)
|
||||
|
||||
version:
|
||||
$(CLIVER): tools/version.sh $(VERSION)
|
||||
$< $(VERSION) $@
|
||||
|
||||
# Statically link the CLI
|
||||
$(CLITARGET): CFLAGS += -I./cli/include
|
||||
$(CLITARGET): $(CLIOBJ) $(LIBOBJ)
|
||||
$(CLITARGET): $(CLIVER) $(CLIOBJ) $(LIBOBJ)
|
||||
$(CC) $(LDFLAGS) -o $@ $^
|
||||
|
||||
$(LIBTARGET): LDFLAGS += -shared
|
||||
|
7
cli/include/meson.build
Normal file
7
cli/include/meson.build
Normal file
@ -0,0 +1,7 @@
|
||||
cli_version_h = custom_target(
|
||||
'cli_version_h',
|
||||
output: 'version.h',
|
||||
command: [version_sh, version, '@OUTPUT@'],
|
||||
)
|
||||
|
||||
cli_includes = include_directories('.')
|
@ -24,4 +24,4 @@ cli_sources = files(
|
||||
'src/strvec.c',
|
||||
)
|
||||
|
||||
cli_includes = include_directories('include')
|
||||
subdir('include')
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "command.h"
|
||||
#include "strutil.h"
|
||||
#include "version.h"
|
||||
|
||||
// clang-format off
|
||||
const struct command handlers[] = {
|
||||
@ -34,7 +35,7 @@ const struct command handlers[] = {
|
||||
{ 0 },
|
||||
};
|
||||
|
||||
static const char *version = "0.1.0";
|
||||
static const char *version = NARC_VERSION;
|
||||
// clang-format on
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
|
@ -18,7 +18,9 @@ project(
|
||||
license: 'Apache-2.0',
|
||||
license_files: 'LICENSE',
|
||||
meson_version: '>=1.5.0',
|
||||
version: '0.1.0',
|
||||
|
||||
# This is a little ugly, but it works... I guess...
|
||||
version: run_command('./tools/version.sh', 'VERSION', check: false).stdout().strip(),
|
||||
default_options: {
|
||||
'buildtype': 'release', # O3
|
||||
'warning_level': '3', # all, extra, pedantic
|
||||
@ -28,7 +30,9 @@ project(
|
||||
|
||||
native = get_option('native')
|
||||
install = native and meson.is_cross_build() ? false : true
|
||||
version = files('VERSION')
|
||||
|
||||
subdir('tools')
|
||||
subdir('lib')
|
||||
subdir('cli')
|
||||
|
||||
@ -50,6 +54,7 @@ libnarc_dep = declare_dependency(
|
||||
narc_exe = executable(
|
||||
'narc',
|
||||
sources: [
|
||||
cli_version_h,
|
||||
cli_sources,
|
||||
lib_sources,
|
||||
],
|
||||
|
1
tools/meson.build
Normal file
1
tools/meson.build
Normal file
@ -0,0 +1 @@
|
||||
version_sh = find_program('version.sh', native: true)
|
21
tools/version.sh
Executable file
21
tools/version.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION_FILE=$1
|
||||
TARGET_FILE=$2
|
||||
|
||||
VERSION=$(cat "${VERSION_FILE}")
|
||||
|
||||
if test -z "${TARGET_FILE}"; then
|
||||
echo "${VERSION}"
|
||||
else
|
||||
{
|
||||
echo "/* THIS HEADER IS AUTOMATICALLY GENERATED */"
|
||||
echo "/* DO NOT MODIFY IT!!! */"
|
||||
echo "#ifndef NARC_VERSION_H"
|
||||
echo "#define NARC_VERSION_H"
|
||||
echo ""
|
||||
echo "#define NARC_VERSION \"${VERSION}\""
|
||||
echo ""
|
||||
echo "#endif /* NARC_VERSION_H */"
|
||||
} >"${TARGET_FILE}"
|
||||
fi
|
Loading…
Reference in New Issue
Block a user