opt: use sysconfigdir to get install path

This commit is contained in:
DreamMaoMao 2025-02-25 13:04:54 +08:00
parent 98413aa01b
commit 28d19fdbc8
2 changed files with 39 additions and 27 deletions

View file

@ -4,28 +4,18 @@ project('maomao', ['c', 'cpp'],
subdir('protocols')
# fs = import('fs')
#
# # 获取用户的主目录
# home_dir = run_command('sh', '-c', 'echo $HOME', check: true).stdout().strip()
# config_dir = join_paths(home_dir, '.config', 'maomao')
#
# # 如果目标目录不存在,则创建它
# if not fs.is_dir(config_dir)
# run_command('mkdir', '-p', config_dir, check: true)
# endif
#
# # 拷贝 config.conf
# 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
# 获取 sysconfdir 并动态去掉前缀
prefix = get_option('prefix')
sysconfdir = get_option('sysconfdir')
# 如果 sysconfdir 以 prefix 开头,去掉 prefix
if sysconfdir.startswith(prefix)
sysconfdir = sysconfdir.substring(prefix.length())
endif
# 打印调试信息,确认 sysconfdir 的值
message('prefix: ' + prefix)
message('sysconfdir: ' + sysconfdir)
cc = meson.get_compiler('c')
libm = cc.find_library('m')
@ -37,18 +27,31 @@ xkbcommon_dep = dependency('xkbcommon')
libinput_dep = dependency('libinput')
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 = [
'-g',
'-Wno-unused-function',
'-DWLR_USE_UNSTABLE',
'-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()
c_args += '-DXWAYLAND'
c_args += '-DIM'
endif
endif
executable('maomao',
'maomao.c',
@ -68,8 +71,13 @@ executable('maomao',
c_args : c_args
)
prefix = get_option('prefix')
desktop_install_dir = join_paths(prefix, 'share/wayland-sessions')
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'))

View file

@ -3,6 +3,10 @@
#include <stdint.h>
#include <string.h>
#ifndef SYSCONFDIR
#define SYSCONFDIR "/etc"
#endif
typedef struct {
const char *id;
const char *title;
@ -1024,7 +1028,7 @@ void parse_config(void) {
// 检查文件是否存在
if (access(filename, F_OK) != 0) {
// 如果文件不存在,则使用 /etc/maomao/config.conf
snprintf(filename, sizeof(filename), "/etc/maomao/config.conf");
snprintf(filename, sizeof(filename), "%s/maomao/config.conf",SYSCONFDIR);
}
} else {
// 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径