Add Makefile for building stdlib
authorLuke Lau <luke_lau@icloud.com>
Sat, 9 Nov 2019 17:57:19 +0000 (17:57 +0000)
committerLuke Lau <luke_lau@icloud.com>
Sat, 9 Nov 2019 18:28:22 +0000 (18:28 +0000)
There are two ways we can go about including our standard library in our
language.
The first method is via statically linking it into our final executable,
by compiling our Haskell code and standard library object file with it.
The second method is to compile the standard library into a shared
library and dynamically load it at runtime.

Here we are going to do the latter, since it means we can still run our
code with runghc, at the cost of needing to locate the path to the
library inside Main.hs. (I'll include an example later on of how to
include it the static way)

macOS produces dylibs - Linux typically uses .so files. You may want to
rename the rule to align with whatever operating system you are
targeting.

.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..699f4dd
--- /dev/null
@@ -0,0 +1 @@
+stdlib.dylib
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..4e533dc
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+stdlib.dylib: stdlib.c
+       clang -shared $< -o $@