opt: use sysconfigdir to get install path
This commit is contained in:
60
meson.build
60
meson.build
@@ -4,28 +4,18 @@ project('maomao', ['c', 'cpp'],
|
|||||||
|
|
||||||
subdir('protocols')
|
subdir('protocols')
|
||||||
|
|
||||||
# fs = import('fs')
|
# 获取 sysconfdir 并动态去掉前缀
|
||||||
#
|
prefix = get_option('prefix')
|
||||||
# # 获取用户的主目录
|
sysconfdir = get_option('sysconfdir')
|
||||||
# home_dir = run_command('sh', '-c', 'echo $HOME', check: true).stdout().strip()
|
|
||||||
# config_dir = join_paths(home_dir, '.config', 'maomao')
|
# 如果 sysconfdir 以 prefix 开头,去掉 prefix
|
||||||
#
|
if sysconfdir.startswith(prefix)
|
||||||
# # 如果目标目录不存在,则创建它
|
sysconfdir = sysconfdir.substring(prefix.length())
|
||||||
# if not fs.is_dir(config_dir)
|
endif
|
||||||
# run_command('mkdir', '-p', config_dir, check: true)
|
|
||||||
# endif
|
# 打印调试信息,确认 sysconfdir 的值
|
||||||
#
|
message('prefix: ' + prefix)
|
||||||
# # 拷贝 config.conf
|
message('sysconfdir: ' + sysconfdir)
|
||||||
# config_file = join_paths(config_dir, 'config.conf')
|
|
||||||
# if not fs.exists(config_file)
|
|
||||||
# run_command('cp', 'config.conf', config_file, check: true)
|
|
||||||
# endif
|
|
||||||
#
|
|
||||||
# # 拷贝 autostart.sh
|
|
||||||
# autostart_file = join_paths(config_dir, 'autostart.sh')
|
|
||||||
# if not fs.exists(autostart_file)
|
|
||||||
# run_command('cp', 'autostart.sh', autostart_file, check: true)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
cc = meson.get_compiler('c')
|
cc = meson.get_compiler('c')
|
||||||
libm = cc.find_library('m')
|
libm = cc.find_library('m')
|
||||||
@@ -37,18 +27,31 @@ xkbcommon_dep = dependency('xkbcommon')
|
|||||||
libinput_dep = dependency('libinput')
|
libinput_dep = dependency('libinput')
|
||||||
libwayland_client_dep = dependency('wayland-client')
|
libwayland_client_dep = dependency('wayland-client')
|
||||||
|
|
||||||
|
# 获取 Git Commit Hash
|
||||||
|
git = find_program('git', required : false)
|
||||||
|
if git.found()
|
||||||
|
commit_hash = run_command(git, 'rev-parse', '--short', 'HEAD', check : true).stdout().strip()
|
||||||
|
else
|
||||||
|
commit_hash = 'unknown'
|
||||||
|
endif
|
||||||
|
|
||||||
|
# 将 Commit Hash 添加到版本信息中
|
||||||
|
version_with_hash = '@0@(@1@)'.format(meson.project_version(), commit_hash)
|
||||||
|
|
||||||
|
# 定义编译参数
|
||||||
c_args = [
|
c_args = [
|
||||||
'-g',
|
'-g',
|
||||||
'-Wno-unused-function',
|
'-Wno-unused-function',
|
||||||
'-DWLR_USE_UNSTABLE',
|
'-DWLR_USE_UNSTABLE',
|
||||||
'-D_POSIX_C_SOURCE=200809L',
|
'-D_POSIX_C_SOURCE=200809L',
|
||||||
'-DVERSION="@0@"'.format(meson.project_version())
|
'-DVERSION="@0@"'.format(version_with_hash), # 版本信息包含 Commit Hash
|
||||||
|
'-DSYSCONFDIR="@0@"'.format(sysconfdir), # 添加 sysconfdir
|
||||||
]
|
]
|
||||||
|
|
||||||
if xcb.found() and xlibs.found()
|
if xcb.found() and xlibs.found()
|
||||||
c_args += '-DXWAYLAND'
|
c_args += '-DXWAYLAND'
|
||||||
c_args += '-DIM'
|
c_args += '-DIM'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
executable('maomao',
|
executable('maomao',
|
||||||
'maomao.c',
|
'maomao.c',
|
||||||
@@ -68,8 +71,13 @@ executable('maomao',
|
|||||||
c_args : c_args
|
c_args : c_args
|
||||||
)
|
)
|
||||||
|
|
||||||
prefix = get_option('prefix')
|
|
||||||
desktop_install_dir = join_paths(prefix, 'share/wayland-sessions')
|
desktop_install_dir = join_paths(prefix, 'share/wayland-sessions')
|
||||||
install_data('maomao.desktop', install_dir : desktop_install_dir)
|
install_data('maomao.desktop', install_dir : desktop_install_dir)
|
||||||
install_data('config.conf', install_dir : '/etc/maomao')
|
|
||||||
|
|
||||||
|
# 确保 sysconfdir 是绝对路径
|
||||||
|
if not sysconfdir.startswith('/')
|
||||||
|
sysconfdir = '/' + sysconfdir
|
||||||
|
endif
|
||||||
|
|
||||||
|
# 安装 config.conf
|
||||||
|
install_data('config.conf', install_dir : join_paths(sysconfdir, 'maomao'))
|
||||||
@@ -3,6 +3,10 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifndef SYSCONFDIR
|
||||||
|
#define SYSCONFDIR "/etc"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *id;
|
const char *id;
|
||||||
const char *title;
|
const char *title;
|
||||||
@@ -1024,7 +1028,7 @@ void parse_config(void) {
|
|||||||
// 检查文件是否存在
|
// 检查文件是否存在
|
||||||
if (access(filename, F_OK) != 0) {
|
if (access(filename, F_OK) != 0) {
|
||||||
// 如果文件不存在,则使用 /etc/maomao/config.conf
|
// 如果文件不存在,则使用 /etc/maomao/config.conf
|
||||||
snprintf(filename, sizeof(filename), "/etc/maomao/config.conf");
|
snprintf(filename, sizeof(filename), "%s/maomao/config.conf",SYSCONFDIR);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径
|
// 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径
|
||||||
|
|||||||
Reference in New Issue
Block a user