我知道 Makefile 不应该要求用户是 root。所以我/usr/local
这样使用:
PREFIX=/usr/local
install:
install -D example $(PREFIX)/bin/example
Run Code Online (Sandbox Code Playgroud)
效果很好。但我还需要为 polkit 安装一个策略文件。唯一有效的路径是/usr/share/polkit-1/actions/
. 如果我尝试使用install
,我会收到以下错误:
install: cannot create regular file '/usr/share/polkit-1/actions/com.example.policy': Permission denied
Run Code Online (Sandbox Code Playgroud)
如果我无法要求用户以make
root 身份运行,我该如何安装我的策略文件?
通常,构建程序不需要 root 访问权限,但安装程序通常需要 root 访问权限。所以跑起来很正常
make
sudo make install
Run Code Online (Sandbox Code Playgroud)
或者,在构建要包含在包中的软件时,例如:
make
mkdir install-root
fakeroot -- sh -c 'make PREFIX="$PWD/install-root/usr/local" install && cd install-root && tar -czf ../package.tgz .'
Run Code Online (Sandbox Code Playgroud)