Commit d8803390 authored by Swann Perarnau's avatar Swann Perarnau

[refactor] use autoconf + m4 for version mngmt

Use m4 to define autoconf-level version variables, following the naming
scheme of semver.org

To make use of these variables in the headers and sources, a
generated-header is added in aml/utils/version.h

Also add a simple test for that part of the lib.
parent 42528fdd
Pipeline #6718 passed with stage
in 18 minutes and 48 seconds
......@@ -50,6 +50,7 @@ stamp-h1
/install-sh
/missing
/stamp-h1
version.h
# autotest
tests/**/*.trs
......
......@@ -4,7 +4,7 @@ libdir=@libdir@
includedir=@includedir@
Name: libaml
Description: Argonne's Memory Library
Version: 0.0.1
Description: AML: Building Blocks for Memory Management
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -laml
Cflags: -I${includedir}
# see semver.org for version info
AC_INIT([aml],[0.0.2],[swann@anl.gov])
m4_define([VERSION_MAJOR], [0])
m4_define([VERSION_MINOR], [1])
m4_define([VERSION_PATCH], [0])
m4_define([VERSION_STRING], VERSION_MAJOR.VERSION_MINOR.VERSION_PATCH)
AC_INIT([aml],[VERSION_STRING],[swann@anl.gov])
AC_SUBST([PACKAGE_VERSION_MAJOR],[VERSION_MAJOR])
AC_SUBST([PACKAGE_VERSION_MINOR],[VERSION_MINOR])
AC_SUBST([PACKAGE_VERSION_PATCH],[VERSION_PATCH])
# are we in the right source dir ?
AC_CONFIG_SRCDIR([include/aml.h])
......@@ -81,5 +90,6 @@ AC_CONFIG_FILES([Makefile
include/Makefile
tests/Makefile
benchmarks/Makefile
aml.pc])
aml.pc
include/aml/utils/version.h])
AC_OUTPUT
......@@ -14,5 +14,6 @@ include_aml_scratch_HEADERS = \
include_amlutilsdir=$(includedir)/aml/utils
include_amlutils_HEADERS = \
aml/utils/vector.h \
aml/utils/bitmap.h
aml/utils/bitmap.h \
aml/utils/version.h
......@@ -29,19 +29,10 @@
#define PAGE_SIZE 4096
#endif
#include <aml/utils/version.h>
#include <aml/utils/bitmap.h>
#include <aml/utils/vector.h>
/*
* If AML_ABI_VERSION != aml_get_major_version(),
* the header is not the same version as linked library.
*/
#define AML_ABI_VERSION (0)
extern const char* aml_version_string;
int aml_get_major_version();
int aml_get_minor_version();
int aml_get_patch_version();
/*******************************************************************************
* General functions:
* Initialize internal structures, cleanup everything at the end.
......
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#ifndef AML_VERSION_H
#define AML_VERSION_H 1
#define AML_VERSION_MAJOR @PACKAGE_VERSION_MAJOR@
#define AML_VERSION_MINOR @PACKAGE_VERSION_MINOR@
#define AML_VERSION_PATCH @PACKAGE_VERSION_PATCH@
#define AML_VERSION_STRING "@PACKAGE_VERSION@"
extern const int aml_version_major;
extern const int aml_version_minor;
extern const int aml_version_patch;
extern const char* aml_version_string;
#endif /* AML_VERSION_H */
......@@ -8,54 +8,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "config.h"
#include "aml.h"
#include "config.h"
#include <string.h>
const char* aml_version_string = VERSION;
int aml_major_version = -1;
int aml_minor_version = -1;
int aml_patch_version = -1;
int aml_get_major_version(){
if(aml_major_version < 0){
char version[strlen(VERSION)+1];
strcpy(version, VERSION);
return atoi(strtok(version, "."));
}
return aml_major_version;
}
int aml_get_minor_version(){
if(aml_major_version < 0){
char version[strlen(VERSION)+1];
strcpy(version, VERSION);
strtok(version, ".");
return atoi(strtok(version, "."));
}
return aml_minor_version;
}
int aml_get_patch_version(){
if(aml_major_version < 0){
char version[strlen(VERSION)+1];
strcpy(version, VERSION);
strtok(version, ".");
strtok(version, ".");
return atoi(strtok(version, "."));
}
return aml_minor_version;
}
const int aml_version_major = AML_VERSION_MAJOR;
const int aml_version_minor = AML_VERSION_MINOR;
const int aml_version_patch = AML_VERSION_PATCH;
const char* aml_version_string = AML_VERSION_STRING;
int aml_init(int *argc, char **argv[])
{
char version[strlen(VERSION)+1];
strcpy(version, VERSION);
aml_major_version = atoi(strtok(version, "."));
if(aml_major_version != AML_ABI_VERSION)
return -1;
aml_minor_version = atoi(strtok(NULL, "."));
aml_patch_version = atoi(strtok(NULL, "."));
return 0;
}
......
......@@ -10,7 +10,8 @@ TESTS_ENVIRONMENT= @LIBTOOL@ --mode=execute @VALGRIND@ --tool=memcheck -q --leak
endif
UTILS_TESTS = utils/test_vector \
utils/test_bitmap
utils/test_bitmap \
utils/test_version
ARENA_JEMALLOC_TESTS = arena/test_jemalloc
......
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml.h"
#include <assert.h>
int main(int argc, char *argv[])
{
assert(aml_version_major == AML_VERSION_MAJOR);
assert(aml_version_minor == AML_VERSION_MINOR);
assert(aml_version_patch == AML_VERSION_PATCH);
assert(!strcmp(aml_version_string, AML_VERSION_STRING));
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment