Add version handling
This commit is contained in:
parent
9107a2797c
commit
199b48d963
@ -7,13 +7,27 @@ pkg_check_modules(ELF REQUIRED libelf)
|
|||||||
|
|
||||||
set (CFILES
|
set (CFILES
|
||||||
main.c
|
main.c
|
||||||
|
version.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(GEN_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/include/generated")
|
||||||
|
|
||||||
|
add_custom_target(
|
||||||
|
version-header
|
||||||
|
COMMAND
|
||||||
|
mkdir -p ${GEN_HEADER_PATH} && bash "${CMAKE_CURRENT_SOURCE_DIR}/gen_version_header.sh" "${GEN_HEADER_PATH}/version.h"
|
||||||
|
WORKING_DIRECTORY
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${CFILES})
|
add_executable(${PROJECT_NAME} ${CFILES})
|
||||||
target_link_libraries(${PROJECT_NAME} ${ELF_LIBRARIES})
|
target_link_libraries(${PROJECT_NAME} ${ELF_LIBRARIES})
|
||||||
target_link_directories(${PROJECT_NAME} PRIVATE ${ELF_LIBRARY_DIRS})
|
target_link_directories(${PROJECT_NAME} PRIVATE ${ELF_LIBRARY_DIRS})
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${ELF_INCLUDE_DIRS})
|
target_include_directories(${PROJECT_NAME} PRIVATE ${ELF_INCLUDE_DIRS})
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include")
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE "include")
|
||||||
|
add_dependencies(${PROJECT_NAME} version-header)
|
||||||
|
|
||||||
|
|
||||||
|
11
gen_version_header.sh
Executable file
11
gen_version_header.sh
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
exit -1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
ver=`git describe --tags --always --dirty`
|
||||||
|
echo "#ifndef _VERSION_GENERATED_H_" > $1
|
||||||
|
echo "#define _VERSION_GENERATED_H_" >> $1
|
||||||
|
echo "#define GIT_VERSION_STRING \"$ver\"" >> $1
|
||||||
|
echo "#endif /* _VERSION_GENERATED_H_ */" >> $1
|
7
include/patchelfcrc/version.h
Normal file
7
include/patchelfcrc/version.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef _VERSION_H_
|
||||||
|
#define _VERSION_H_
|
||||||
|
|
||||||
|
extern const char *version_string;
|
||||||
|
extern const char *argp_program_version;
|
||||||
|
|
||||||
|
#endif /* _VERSION_H_ */
|
15
main.c
15
main.c
@ -2,6 +2,7 @@
|
|||||||
#include <libelf.h>
|
#include <libelf.h>
|
||||||
#include <argp.h>
|
#include <argp.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <patchelfcrc/version.h>
|
||||||
|
|
||||||
#define print_err(fmt, ...) fprintf(stderr, (fmt), ## __VA_ARGS__);
|
#define print_err(fmt, ...) fprintf(stderr, (fmt), ## __VA_ARGS__);
|
||||||
#define print_debug(fmt, ...) do { \
|
#define print_debug(fmt, ...) do { \
|
||||||
@ -10,6 +11,8 @@
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
const char *argp_program_bug_address = "<mario.huettel@linux.com>";
|
||||||
|
|
||||||
enum granularity {
|
enum granularity {
|
||||||
GRANULARITY_BYTE = 1,
|
GRANULARITY_BYTE = 1,
|
||||||
GRANULARITY_16BIT,
|
GRANULARITY_16BIT,
|
||||||
@ -31,17 +34,22 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
|||||||
default:
|
default:
|
||||||
return ARGP_ERR_UNKNOWN;
|
return ARGP_ERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_cmdline_options(int *argc, char ***argv, struct command_line_options *cmd_opts)
|
static int parse_cmdline_options(int *argc, char ***argv, struct command_line_options *cmd_opts)
|
||||||
{
|
{
|
||||||
|
error_t err;
|
||||||
|
|
||||||
if (!argc || !argv)
|
if (!argc || !argv)
|
||||||
return -1000;
|
return -1000;
|
||||||
|
|
||||||
static struct argp_option options[] = {
|
static struct argp_option options[] = {
|
||||||
{"little-endian", 'l', 0, 0, "Memory image is little endian. Only relevant if granularity is greater than a single byte"},
|
{"little-endian", 'l', 0, 0, "Memory image is little endian. Only relevant if granularity is greater than a single byte", 0},
|
||||||
/* Sentinel */
|
/* Sentinel */
|
||||||
{NULL, 0, 0, 0, NULL}
|
{NULL, 0, 0, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct argp arg_parser = {
|
static struct argp arg_parser = {
|
||||||
@ -52,8 +60,9 @@ static int parse_cmdline_options(int *argc, char ***argv, struct command_line_op
|
|||||||
0, 0, 0
|
0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
argp_parse(&arg_parser, *argc, *argv, 0, 0, cmd_opts);
|
err = argp_parse(&arg_parser, *argc, *argv, 0, 0, cmd_opts);
|
||||||
|
|
||||||
|
return err ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
Loading…
Reference in New Issue
Block a user