gpt4 book ai didi

linux - 生成 "debian rules"文件时 apt-get 环境变量

转载 作者:太空宇宙 更新时间:2023-11-04 09:57:09 25 4
gpt4 key购买 nike

debian/rules 在安装软件包期间由 apt-get 生成时,哪些环境变量可用于 debian/rules(通常是 make)在 Ubuntu 下?

我特别关注与 Gnome 配置目录相关的环境变量。我想避免像 ~/.conf/apps/... 这样的“硬编码”,因为有人告诉我这些可能会改变,就像它们倾向于...

我一直在疯狂地使用谷歌搜索!

最佳答案

您是否正在寻找 XDG_CONFIG_HOME 和 related ?特别要注意,XDG_CONFIG_HOME 不必存在,在这种情况下假定值为 ~/.config。

Python 示例

import os
from os import path

app_name = "my_app"
home_config = path.join(
os.environ.get("XDG_CONFIG_HOME") or path.expanduser("~/.config"),
app_name,
)

print "User-specific config:", home_config

C++ 示例

#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>

std::string get_home_config(std::string const& app_name) {
// also look at boost's filesystem library
using namespace std;
string home_config;
char const* xdg_config_home = getenv("XDG_CONFIG_HOME");
if (xdg_config_home && xdg_config_home[0] != '\0') {
home_config = xdg_config_home;
}
else {
if (char const* home = getenv("HOME")) {
home_config = home;
home_config += "/.config";
}
else throw std::runtime_error("HOME not set");
}
home_config += "/";
home_config += app_name;
return home_config;
}

int main() try {
std::cout << "User-specific config: " << get_home_config("my_app") << '\n';
return 0;
}
catch (std::exception& e) {
std::clog << e.what() << std::endl;
return 1;
}

关于linux - 生成 "debian rules"文件时 apt-get 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2208400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com