diff --git a/.gitignore b/.gitignore index 3466e5e..8cc0943 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ *.su build/ +.cache/ \ No newline at end of file diff --git a/dists/flipclock.desktop b/dists/flipclock.desktop.in similarity index 83% rename from dists/flipclock.desktop rename to dists/flipclock.desktop.in index 589b45d..07122ce 100644 --- a/dists/flipclock.desktop +++ b/dists/flipclock.desktop.in @@ -4,7 +4,7 @@ Name=FlipClock Comment=A flip clock screensaver supported by SDL2. Icon=flipclock Exec=flipclock -TryExec=/usr/bin/flipclock +TryExec=@package_bindir@/flipclock StartupNotify=false Terminal=false Categories=Game diff --git a/meson.build b/meson.build index 69f5fe5..83d5344 100644 --- a/meson.build +++ b/meson.build @@ -22,8 +22,9 @@ if get_option('debug') == true endif conf_data = configuration_data() -conf_data.set('install_prefix', get_option('prefix')) conf_data.set('project_version', meson.project_version()) +conf_data.set('package_bindir', get_option('prefix') / get_option('bindir')) +conf_data.set('package_datadir', get_option('prefix') / get_option('datadir')) configure_file( input: 'srcs/config-meson.h.in', @@ -31,6 +32,18 @@ configure_file( configuration: conf_data ) +# Don't install desktop entry for Windows. +if host_machine.system() == 'linux' + configure_file( + input: 'dists/flipclock.desktop.in', + output: 'flipclock.desktop', + configuration: conf_data, + install: true, + # If a relative path is given, meson will put it under prefix so we don't need to put `get_option('prefix')` manually here. + install_dir: get_option('datadir') / 'applications' + ) +endif + sources = files( 'srcs/main.c', 'srcs/getarg.c', @@ -51,8 +64,8 @@ if host_machine.system() == 'linux' c_args: c_args, dependencies: dependencies, include_directories: include_directories, - install: true, - install_dir: get_option('prefix') / 'bin' + install: true + # By default, meson install binary to `get_option('prefix') / get_option('bindir')`, so we can omit `install_dir` here. ) install_data( @@ -67,10 +80,6 @@ if host_machine.system() == 'linux' 'dists' / 'flipclock.png', install_dir: get_option('datadir') / 'pixmaps' ) - install_data( - 'dists' / 'flipclock.desktop', - install_dir: get_option('datadir') / 'applications' - ) elif host_machine.system() == 'windows' if get_option('debug') == true executable( @@ -80,7 +89,7 @@ elif host_machine.system() == 'windows' dependencies: dependencies, include_directories: include_directories, install: true, - install_dir: get_option('prefix') / meson.project_name(), + install_dir: meson.project_name(), name_suffix: 'scr', win_subsystem: 'console' ) @@ -92,7 +101,7 @@ elif host_machine.system() == 'windows' dependencies: dependencies, include_directories: include_directories, install: true, - install_dir: get_option('prefix') / meson.project_name(), + install_dir: meson.project_name(), name_suffix: 'scr', win_subsystem: 'windows' ) @@ -100,18 +109,18 @@ elif host_machine.system() == 'windows' install_data( 'LICENSE', - install_dir: get_option('prefix') / meson.project_name() + install_dir: meson.project_name() ) install_data( 'dists' / 'flipclock.ttf', - install_dir: get_option('prefix') / meson.project_name() + install_dir: meson.project_name() ) install_data( 'dists' / 'COPYING', - install_dir: get_option('prefix') / meson.project_name() + install_dir: meson.project_name() ) install_data( 'dists' / '请先读我.txt', - install_dir: get_option('prefix') / meson.project_name() + install_dir: meson.project_name() ) endif diff --git a/srcs/config-meson.h.in b/srcs/config-meson.h.in index 011d2dd..dfde1bb 100644 --- a/srcs/config-meson.h.in +++ b/srcs/config-meson.h.in @@ -1,6 +1,7 @@ #ifndef __CONFIG_H__ -#define INSTALL_PREFIX "@install_prefix@" #define PROJECT_VERSION "@project_version@" +#define PACKAGE_BINDIR "@package_bindir@" +#define PACKAGE_DATADIR "@package_datadir@" #endif diff --git a/srcs/flipclock.c b/srcs/flipclock.c index 1058e07..f8ca2fa 100644 --- a/srcs/flipclock.c +++ b/srcs/flipclock.c @@ -710,7 +710,7 @@ void flipclock_open_fonts(struct flipclock *app, int clock_index) // Directly under `app/src/main/assets` for Android APP. char *font_path = "flipclock.ttf"; #elif defined(__linux__) - char *font_path = INSTALL_PREFIX "/share/fonts/flipclock.ttf"; + char *font_path = PACKAGE_DATADIR "/fonts/flipclock.ttf"; #endif LOG_DEBUG("Using font_path `%s`.\n", font_path); app->clocks[clock_index].fonts.time = TTF_OpenFont(