Skip to content

Commit

Permalink
libmikey: better nix integration
Browse files Browse the repository at this point in the history
this sets up libmikey on LIBRARY_PATH and C_INCLUDE_PATH, and uses
these environment variables for e.g. -lmikey instead of figuring out
the hard-coded paths.

(still learning all these c standards: naming the archive `libX`,
linking with `-lX`, includes go in `include/X/*.h` etc. -- I think!)

this means that in my standard bash environment I can just compile
code with -lmikey and #include <libmikey/common.h> etc and it will
work, in addition to compiling nicely within the nix builder.
  • Loading branch information
mjhoy committed Apr 10, 2018
1 parent 6ed7e2f commit 20ec523
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
4 changes: 4 additions & 0 deletions bash/nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if [ -e $HOME/.nix-profile/include ]; then
export C_INCLUDE_PATH=$HOME/.nix-profile/include:$C_INCLUDE_PATH;
fi

if [ -e $HOME/.nix-profile/lib ]; then
export LIBRARY_PATH=$HOME/.nix-profile/lib:$LIBRARY_PATH;
fi

# i'm not sure but i dont think i should do this:
# if [ -e $HOME/.nix-profile/lib ]; then
# export LD_LIBRARY_PATH=$HOME/.nix-profile/lib:$LD_LIBRARY_PATH;
Expand Down
7 changes: 4 additions & 3 deletions nix/nixpkgs/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
hello_world = stdenv.mkDerivation {
name = "hello_world";
src = ~/.dotfiles/src/hello_world;
libmikey = libmikey;
buildInputs = [ libmikey ];
installPhase = ''
mkdir -p $out/bin
cp hello_world $out/bin/hello_world
mkdir -p $out/bin
cp hello_world $out/bin/hello_world
'';
};

Expand Down Expand Up @@ -187,6 +187,7 @@
devEnv = buildEnv {
name = "devEnv";
paths = [
libmikey
myHaskellEnv
cabal2nix

Expand Down
4 changes: 2 additions & 2 deletions nix/pkgs/libmikey/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ stdenv.mkDerivation {
src = ~/.dotfiles/src/libmikey;
installPhase = ''
mkdir -p $out/lib
mkdir -p $out/include
cp build/include/* $out/include
mkdir -p $out/include/mikey
cp build/include/* $out/include/mikey
cp build/lib/* $out/lib
'';
}
2 changes: 2 additions & 0 deletions src/hello_world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
hello_world
7 changes: 3 additions & 4 deletions src/hello_world/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
.PHONY: clean

LIBS = -static -lmikey
CFLAGS = ${include_dirs} -O
include_dirs = -I${libmikey}/include
LIBS = -lmikey
CFLAGS = -O

hello_world: hello_world.o
$(CC) -o $@ $^ $(CFLAGS) $(libmikey)/lib/libmikey.a
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

clean:
rm -f *.o
Expand Down
4 changes: 2 additions & 2 deletions src/hello_world/hello_world.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>
#include "common.h"
#include "error_functions.h"
#include <mikey/common.h>
#include <mikey/error_functions.h>

/**
* Example program.
Expand Down
4 changes: 4 additions & 0 deletions src/libmikey/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/
ename.c.inc
*.o
*.a

0 comments on commit 20ec523

Please sign in to comment.