aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/default.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2018-09-06 21:39:01 +0200
committertv <tv@krebsco.de>2018-09-06 21:39:01 +0200
commit7cde80bc468b05c45e8a18a97ae67028d0de4af0 (patch)
tree5bc9e8324ec079202e857d42d42e11a44dacef79 /pkgs/default.nix
parenta5dd57dd48d610c11f08c7fd99b3fbd2e8151ff8 (diff)
pkgs.writeC: add support for libraries
Diffstat (limited to 'pkgs/default.nix')
-rw-r--r--pkgs/default.nix19
1 files changed, 17 insertions, 2 deletions
diff --git a/pkgs/default.nix b/pkgs/default.nix
index df32f59..6224caa 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -121,18 +121,33 @@ pkgs: oldpkgs: {
assert types.filename.check name;
pkgs.writeBash "/bin/${name}";
- writeC = name: { destination ? "" }: text: pkgs.runCommand name {
+ writeC = name: {
+ destination ? "",
+ libraries ? {}
+ }: text: pkgs.runCommand name {
inherit text;
+ buildInputs = [ pkgs.pkgconfig ] ++ attrValues libraries;
passAsFile = [ "text" ];
} /* sh */ ''
PATH=${makeBinPath [
pkgs.binutils-unwrapped
pkgs.coreutils
pkgs.gcc
+ pkgs.pkgconfig
]}
exe=$out${destination}
mkdir -p "$(dirname "$exe")"
- gcc -O -Wall -o "$exe" -x c "$textPath"
+ gcc \
+ ${optionalString (libraries != [])
+ /* sh */ "$(pkg-config --cflags --libs ${
+ concatMapStringsSep " " escapeShellArg (attrNames libraries)
+ })"
+ } \
+ -O \
+ -o "$exe" \
+ -Wall \
+ -x c \
+ "$textPath"
strip --strip-unneeded "$exe"
'';