summary refs log tree commit diff
path: root/pkgs/development/ocaml-modules/ocaml-freestanding/no-opam.patch
blob: 43141b1472a956324478dfdbdae9adb45b6410f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
commit 637b7ce639d54e617170433aa9596176b167d085
Author: sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>
Date:   Thu Mar 18 01:07:49 2021 +0100

    Allow building without ocamlfind and opam
    
    This change is the result of my first go at packaging ocaml-freestanding
    for NixOS. Our build infrastructure for ocaml there is completely
    independent of opam at the moment, so depending on opam for the build
    time is not an option, especially in this case where the information it
    would give us would be garbage.
    
    Fortunately the build environment plays nicely with pkg-config which is
    already heavily used by ocaml-freestanding. This patch leaves pkg-config
    to its own devices if opam is not present (it can be assisted by a
    manually set PKG_CONFIG_PATH environment variable).
    
    Additionally, in configure.sh we check if the target ocaml source
    directory already exists. This allows for building ocaml-freestanding
    without the ocaml-src package (which would be unnecessarily cumbersome
    to package for NixOS) and ocamlfind (one less dependency is always a
    nice bonus). The Makefile needs no fix since the target ocaml/Makefile
    won't be built if it's already present.

diff --git a/Makefile b/Makefile
index b07b8c6..a68b31d 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,12 @@
 
 include Makeconf
 
+ifneq ($(shell command -v opam),)
+	# only set if opam is available and PKG_CONFIG_PATH isn't
+	# already set in the environment or on the command line
+	PKG_CONFIG_PATH ?= $(shell opam config var prefix)/lib/pkgconfig
+endif
+
 FREESTANDING_LIBS=openlibm/libopenlibm.a \
 		  ocaml/runtime/libasmrun.a \
 		  nolibc/libnolibc.a
@@ -73,8 +79,7 @@ flags/libs.tmp: flags/libs.tmp.in
 	opam config subst $@
 
 flags/libs: flags/libs.tmp Makeconf
-	env PKG_CONFIG_PATH="$(shell opam config var prefix)/lib/pkgconfig" \
-	    pkg-config $(PKG_CONFIG_DEPS) --libs >> $<
+	pkg-config $(PKG_CONFIG_DEPS) --libs >> $<
 	awk -v RS= -- '{ \
 	    sub("@@PKG_CONFIG_EXTRA_LIBS@@", "$(PKG_CONFIG_EXTRA_LIBS)", $$0); \
 	    print "(", $$0, ")" \
@@ -84,8 +89,7 @@ flags/cflags.tmp: flags/cflags.tmp.in
 	opam config subst $@
 
 flags/cflags: flags/cflags.tmp Makeconf
-	env PKG_CONFIG_PATH="$(shell opam config var prefix)/lib/pkgconfig" \
-	    pkg-config $(PKG_CONFIG_DEPS) --cflags >> $<
+	pkg-config $(PKG_CONFIG_DEPS) --cflags >> $<
 	awk -v RS= -- '{ \
 	    print "(", $$0, ")" \
 	    }' $< >$@
diff --git a/configure.sh b/configure.sh
index 4d154ed..c254f7b 100755
--- a/configure.sh
+++ b/configure.sh
@@ -1,6 +1,8 @@
 #!/bin/sh
 
-export PKG_CONFIG_PATH=$(opam config var prefix)/lib/pkgconfig
+if command -v opam &> /dev/null; then
+    export PKG_CONFIG_PATH=$(opam config var prefix)/lib/pkgconfig
+fi
 pkg_exists() {
     pkg-config --exists "$@"
 }
@@ -21,7 +23,7 @@ if [ -z "${PKG_CONFIG_DEPS}" ]; then
     echo "ERROR: solo5-bindings-hvt, solo5-bindings-spt, solo5-bindings-virtio, solo5-bindings-muen, solo5-bindings-genode or solo5-bindings-xen must be installed." 1>&2
     exit 1
 fi
-ocamlfind query ocaml-src >/dev/null || exit 1
+[ -e "$(dirname "$0")/ocaml" ] || ocamlfind query ocaml-src >/dev/null || exit 1
 
 FREESTANDING_CFLAGS="$(pkg-config --cflags ${PKG_CONFIG_DEPS})"
 BUILD_ARCH="$(uname -m)"