0

在 Ubuntu 下安装软件包期间产生debian/rules(通常)可用的环境变量是什么?makeapt-get

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

我一直在疯狂地搜索!

4

2 回答 2

1

debian/rules在包构建时调用(源包或二进制包)它不会apt-get.

事实上,.deb 文件(==二进制包)不再包含 debian/rules 的副本。该文件仅在源包中。

此外,包通常不应尝试为特定用户做事,或利用用户的配置。Debian 软件包适用于在系统范围内安装的软件。

虽然理论上可以制作一个在 /home 中安装某些东西的个人包,但这样的包的价值非常有限。

于 2010-02-05T16:42:07.537 回答
1

您在寻找 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;
}
于 2010-02-05T21:40:01.637 回答