aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-08-11 14:03:29 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-08-11 14:03:29 +0000
commit1060c8e8924a16675aa999855e5f3099ce076a9a (patch)
tree2db770e4a6b588ceb9b689c21f5978866fb85733
parentREADME: add description of mouse middle click (diff)
main: add -h,--help and -v,--version command line options
-rw-r--r--main.c31
-rw-r--r--meson.build25
2 files changed, 49 insertions, 7 deletions
diff --git a/main.c b/main.c
index 3b82f0c7..256d28f4 100644
--- a/main.c
+++ b/main.c
@@ -192,6 +192,18 @@ static const struct wl_registry_listener registry_listener = {
.global_remove = &handle_global_remove,
};
+static void
+print_usage(const char *prog_name)
+{
+ printf("Usage: %s [OPTION]...\n", prog_name);
+ printf("\n");
+ printf("Options:\n");
+ printf(" -f,--font=FONT font name and style in fontconfig format (monospace)\n"
+ " -t,--term=TERM value to set the environment variable TERM to (foot)\n"
+ " -v,--version show the version number and quit\n");
+ printf("\n");
+}
+
int
main(int argc, char *const *argv)
{
@@ -201,14 +213,18 @@ main(int argc, char *const *argv)
if (!config_load(&conf))
return ret;
+ const char *const prog_name = argv[0];
+
static const struct option longopts[] = {
- {"term", required_argument, 0, 't'},
- {"font", required_argument, 0, 'f'},
- {NULL, no_argument, 0, 0},
+ {"term", required_argument, 0, 't'},
+ {"font", required_argument, 0, 'f'},
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {NULL, no_argument, 0, 0},
};
while (true) {
- int c = getopt_long(argc, argv, ":t:f:h", longopts, NULL);
+ int c = getopt_long(argc, argv, ":t:f:vh", longopts, NULL);
if (c == -1)
break;
@@ -223,8 +239,13 @@ main(int argc, char *const *argv)
tll_push_back(conf.fonts, strdup(optarg));
break;
+ case 'v':
+ printf("foot version %s\n", FOOT_VERSION);
+ return EXIT_SUCCESS;
+
case 'h':
- break;
+ print_usage(prog_name);
+ return EXIT_SUCCESS;
case ':':
fprintf(stderr, "error: -%c: missing required argument\n", optopt);
diff --git a/meson.build b/meson.build
index 84fb288d..bb76adc8 100644
--- a/meson.build
+++ b/meson.build
@@ -9,10 +9,31 @@ project('foot', 'c',
is_debug_build = get_option('buildtype').startswith('debug')
+version = '"@0@"'.format(meson.project_version())
+
+sh = find_program('sh', native: true)
+git = find_program('git', required: false, native: true)
+
+if git.found()
+ commit_hash = run_command(
+ [sh.path(), '-c',
+ '@0@ --git-dir="$MESON_SOURCE_ROOT/.git" describe --always --tags'.format(
+ git.path())])
+
+ branch = run_command(
+ [sh.path(), '-c',
+ '@0@ --git-dir="$MESON_SOURCE_ROOT/.git" rev-parse --abbrev-ref HEAD'.format(
+ git.path())])
+
+ if commit_hash.returncode() == 0 and branch.returncode() == 0
+ version = '"@0@ (" __DATE__ ", branch \'@1@\')"'.format(
+ commit_hash.stdout().strip(), branch.stdout().strip())
+ endif
+endif
+
add_project_arguments(
['-D_GNU_SOURCE=200809L',
- #'-DF00SEL_VERSION=@0@'.format(version)] +
- ] +
+ '-DFOOT_VERSION=@0@'.format(version)] +
(is_debug_build ? ['-D_DEBUG'] : []),
language: 'c',
)