apt-get的产卵“的debian规则”时的环境变量文件
题
什么是提供给debian/rules
(通常make
)当由apt-get
Ubuntu的下安装的软件包的过程中产生了环境变量?
我的环境变量,将涉及到侏儒的配置目录后很特别。我想避免像~/.conf/apps/ ...
“硬编码”的事情,因为我已经告诉这些可能会改变像他们往往...
我一直在google搜索想疯了!
解决方案
您寻找XDG_CONFIG_HOME和相关?具体地,请注意,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;
}
其他提示
debian/rules
得到在编译的时候(源或二进制包)它的不获取apt-get
期间调用调用。
在实际上,的.deb文件(==二进制包),不包含于Debian /规则的副本了。该文件只在源包中。
此外,包通常不应试图为特定用户做的事情,或者利用用户的配置。 Debian包旨在用于已安装系统级软件。
虽然这是理论上的可能,使个人包安装的东西在/ home,这样的包装是非常有限的价值。
不隶属于 StackOverflow