diff --git a/PKGBUILD b/PKGBUILD index 5501465..49fdf0b 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -18,9 +18,9 @@ depends=( optdepends=('xcb-util-errors: better X error messages') source=() -# pkgver() { -# git describe --tags --long | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' -# } +pkgver() { + git describe --tags --long | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' +} build() { meson --buildtype=minsize --prefix=/usr -Dbackend-x11=enabled -Dbackend-wayland=enabled ../ diff --git a/PKGBUILD.wayland-only b/PKGBUILD.wayland-only index f520f7c..b0fa853 100644 --- a/PKGBUILD.wayland-only +++ b/PKGBUILD.wayland-only @@ -18,9 +18,9 @@ depends=( 'libmpdclient') source=() -# pkgver() { -# git describe --tags --long | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' -# } +pkgver() { + git describe --tags --long | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' +} build() { meson --buildtype=minsize --prefix=/usr -Dbackend-x11=disabled -Dbackend-wayland=enabled ../ diff --git a/bar/meson.build b/bar/meson.build index c432817..30dfffc 100644 --- a/bar/meson.build +++ b/bar/meson.build @@ -1,14 +1,12 @@ bar_backends = [] -# TODO: X11 -if enable_x11 - bar_x11 = declare_dependency(sources: ['xcb.c', 'xcb.h'], - dependencies: [xcb_stuff, cairo, cairo_ft]) +if backend_x11 + bar_x11 = declare_dependency( + sources: ['xcb.c', 'xcb.h'], dependencies: [xcb_stuff, cairo, cairo_ft]) bar_backends += [bar_x11] endif -# TODO: conditional Wayland -if enable_wayland +if backend_wayland wayland_protocols = dependency('wayland-protocols') wayland_protocols_datadir = wayland_protocols.get_pkgconfig_variable('pkgdatadir') diff --git a/decorations/meson.build b/decorations/meson.build index 1e20a4b..1b6daee 100644 --- a/decorations/meson.build +++ b/decorations/meson.build @@ -2,7 +2,7 @@ deco_sdk = declare_dependency(dependencies: [cairo, cairo_ft]) decorations = [] foreach deco : ['background', 'stack', 'underline'] - if get_option('core-plugins-as-shared-libraries') + if plugs_as_libs shared_module('@0@'.format(deco), '@0@.c'.format(deco), dependencies: deco_sdk, name_prefix: 'decoration_', diff --git a/doc/f00bar.1.scd b/doc/f00bar.1.scd index 3afc856..6116021 100644 --- a/doc/f00bar.1.scd +++ b/doc/f00bar.1.scd @@ -4,7 +4,12 @@ f00bar(1) f00bar - modular status panel for X11 and Wayland # SYNOPSIS -*f00bar* +*f00bar* [ -v ] + +# OPTIONS + +*-v, --version* + Show the version number and quit # DESCRIPTION *f00bar* is a light-weight and configurable status panel (_bar_, for diff --git a/doc/meson.build b/doc/meson.build index f91e311..76967f8 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -1,4 +1,3 @@ -sh = find_program('sh', native: true) scdoc = dependency('scdoc', native: true) scdoc_prog = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true) diff --git a/main.c b/main.c index 927b586..46be1d9 100644 --- a/main.c +++ b/main.c @@ -122,6 +122,13 @@ main(int argc, const char *const *argv) { setlocale(LC_ALL, ""); + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { + printf("f00bar version %s\n", F00BAR_VERSION); + return 0; + } + } + const struct sigaction sa = {.sa_handler = &signal_handler}; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); diff --git a/meson.build b/meson.build index d7080ca..4c359e7 100644 --- a/meson.build +++ b/meson.build @@ -1,15 +1,34 @@ project('f00bar', 'c', + version: '1.0.1', license: 'MIT', - version: '1.0.0', + meson_version: '>=0.48.0', default_options: ['c_std=c11', 'warning_level=1', 'werror=true']) -add_project_arguments( - ['-D_GNU_SOURCE'] + - (get_option('core-plugins-as-shared-libraries') ? - ['-DCORE_PLUGINS_AS_SHARED_LIBRARIES'] : []), - language: 'c', -) +plugs_as_libs = get_option('core-plugins-as-shared-libraries') +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 + +# Common dependencies cc = meson.get_compiler('c') dl = cc.find_library('dl', required : false) threads = dependency('threads') @@ -18,6 +37,7 @@ cairo = dependency('cairo') cairo_ft = dependency('cairo-ft') yaml = dependency('yaml-0.1') +# X11/XCB dependencies xcb_aux = dependency('xcb-aux', required: get_option('backend-x11')) xcb_cursor = dependency('xcb-cursor', required: get_option('backend-x11')) xcb_event = dependency('xcb-event', required: get_option('backend-x11')) @@ -26,35 +46,33 @@ xcb_randr = dependency('xcb-randr', required: get_option('backend-x11')) xcb_render = dependency('xcb-render', required: get_option('backend-x11')) cairo_xcb = dependency('cairo-xcb', required: get_option('backend-x11')) xcb_errors = dependency('xcb-errors', required: false) +backend_x11 = xcb_aux.found() and xcb_cursor.found() and xcb_event.found() and \ + xcb_ewmh.found() and xcb_randr.found() and xcb_render.found() and \ + cairo_xcb.found() -if xcb_aux.found() and xcb_cursor.found() and xcb_event.found() and \ - xcb_ewmh.found() and xcb_randr.found() and xcb_render.found() and \ - cairo_xcb.found() - - enable_x11 = true - add_project_arguments('-DENABLE_X11', language: 'c') -else - enable_x11 = false -endif - +# Wayland dependencies wayland_client = dependency('wayland-client', required: get_option('backend-wayland')) wayland_cursor = dependency('wayland-cursor', required: get_option('backend-wayland')) wlroots = dependency('wlroots', required: get_option('backend-wayland')) +backend_wayland = wayland_client.found() and wayland_cursor.found() and wlroots.found() -if wayland_client.found() and wayland_cursor.found() and wlroots.found() - enable_wayland = true - add_project_arguments('-DENABLE_WAYLAND', language: 'c') -else - enable_wayland = false -endif +add_project_arguments( + ['-D_GNU_SOURCE', + '-DF00BAR_VERSION=@0@'.format(version)] + + (backend_x11 ? ['-DENABLE_X11'] : []) + + (backend_wayland ? ['-DENABLE_WAYLAND'] : []) + + (plugs_as_libs ? ['-DCORE_PLUGINS_AS_SHARED_LIBRARIES'] : []), + language: 'c', +) -if enable_x11 +if backend_x11 xcb_stuff_lib = static_library( 'xcb-stuff', 'xcb.c', 'xcb.h', dependencies: [xcb_aux, xcb_cursor, xcb_event, xcb_ewmh, xcb_randr, xcb_render, cairo_xcb, xcb_errors], c_args: xcb_errors.found() ? '-DHAVE_XCB_ERRORS' : [], - pic: get_option('core-plugins-as-shared-libraries')) + pic: plugs_as_libs) + xcb_stuff = declare_dependency(link_with: xcb_stuff_lib) install_headers('xcb.h', subdir: 'f00bar') endif @@ -100,3 +118,10 @@ install_headers( 'tllist.h', 'yml.h', subdir: 'f00bar') + +message('') +message('Build type: @0@'.format(get_option('buildtype'))) +message('XCB backend: @0@'.format(backend_x11)) +message('Wayland backend: @0@'.format(backend_wayland)) +message('Core modules as plugins: @0@'.format(plugs_as_libs)) +message('') diff --git a/modules/meson.build b/modules/meson.build index 0d899c9..dc6c67f 100644 --- a/modules/meson.build +++ b/modules/meson.build @@ -21,8 +21,8 @@ deps = { 'removables': [[], [dynlist, udev]], } -if enable_x11 - deps_x11_only = { +if backend_x11 + deps += { 'xkb': [[], [xcb_stuff, xcb_xkb]], 'xwindow': [[], [xcb_stuff]], } @@ -32,7 +32,7 @@ foreach mod, data : deps sources = data[0] dep = data[1] - if get_option('core-plugins-as-shared-libraries') + if plugs_as_libs shared_module(mod, '@0@.c'.format(mod), sources, dependencies: [module_sdk] + dep, name_prefix: 'module_', @@ -45,23 +45,3 @@ foreach mod, data : deps compile_args: '-DHAVE_PLUGIN_@0@'.format(mod))] endif endforeach - -if enable_x11 - foreach mod, data : deps_x11_only - sources = data[0] - dep = data[1] - - if get_option('core-plugins-as-shared-libraries') - shared_module(mod, '@0@.c'.format(mod), sources, - dependencies: [module_sdk] + dep, - name_prefix: 'module_', - install: true, - install_dir: join_paths(get_option('libdir'), 'f00bar')) - else - modules += [declare_dependency( - sources: ['@0@.c'.format(mod)] + sources, - dependencies: [module_sdk] + dep, - compile_args: '-DHAVE_PLUGIN_@0@'.format(mod))] - endif - endforeach -endif diff --git a/particles/meson.build b/particles/meson.build index f016496..2b867c8 100644 --- a/particles/meson.build +++ b/particles/meson.build @@ -2,7 +2,7 @@ particle_sdk = declare_dependency(dependencies: [cairo, cairo_ft]) particles = [] foreach particle : ['empty', 'list', 'map', 'progress-bar', 'ramp', 'string'] - if get_option('core-plugins-as-shared-libraries') + if plugs_as_libs shared_module('@0@'.format(particle), '@0@.c'.format(particle), dependencies: particle_sdk, name_prefix: 'particle_', @@ -18,10 +18,9 @@ endforeach dynlist_lib = build_target( 'dynlist', 'dynlist.c', 'dynlist.h', dependencies: particle_sdk, - target_type: (get_option('core-plugins-as-shared-libraries') - ? 'shared_library' : 'static_library'), + target_type: plugs_as_libs ? 'shared_library' : 'static_library', override_options : ['b_lundef=false'], - install: get_option('core-plugins-as-shared-libraries'), + install: plugs_as_libs, install_dir: get_option('libdir') + '/f00bar', )