about summary refs log tree commit diff
path: root/hello-world-with-multiple-source-files/make.scm
diff options
context:
space:
mode:
authorArun Isaac2025-04-07 15:57:53 +0100
committerArun Isaac2025-04-07 15:57:53 +0100
commita760bff3efa44c282ed119032a6831bdaac79e7b (patch)
tree44a74e8d59b44065ab5b3a3270ba57827ec5fc1a /hello-world-with-multiple-source-files/make.scm
downloadgexp-make-a760bff3efa44c282ed119032a6831bdaac79e7b.tar.gz
gexp-make-a760bff3efa44c282ed119032a6831bdaac79e7b.tar.lz
gexp-make-a760bff3efa44c282ed119032a6831bdaac79e7b.zip
Initial commit
Diffstat (limited to 'hello-world-with-multiple-source-files/make.scm')
-rw-r--r--hello-world-with-multiple-source-files/make.scm42
1 files changed, 42 insertions, 0 deletions
diff --git a/hello-world-with-multiple-source-files/make.scm b/hello-world-with-multiple-source-files/make.scm
new file mode 100644
index 0000000..a078c07
--- /dev/null
+++ b/hello-world-with-multiple-source-files/make.scm
@@ -0,0 +1,42 @@
+(use-modules (gnu packages commencement)
+             (guix gexp))
+
+(define set-up-gcc-gexp
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils))
+
+        (set-path-environment-variable "PATH"
+                                       '("bin")
+                                       (list #$gcc-toolchain))
+        (set-path-environment-variable "C_INCLUDE_PATH"
+                                       '("include")
+                                       (list #$gcc-toolchain))
+        (set-path-environment-variable "LIBRARY_PATH"
+                                       '("lib")
+                                       (list #$gcc-toolchain)))))
+
+(define* (compile source-filename #:key (flags '()))
+  (computed-file (string-append (basename source-filename ".c")
+                                ".o")
+                 #~(begin
+                     #$set-up-gcc-gexp
+                     (invoke "gcc" "-c" #$(local-file source-filename)
+                             "-o" #$output
+                             #$@flags))))
+
+(define* (link output-filename object-files #:key (flags '()))
+  (computed-file output-filename
+                 #~(begin
+                     #$set-up-gcc-gexp
+                     (invoke "gcc" "-o" #$output
+                             #$@object-files
+                             #$@flags))))
+
+(let ((include (list "-I" (file-union "include"
+                                      `(("print.h" ,(local-file "print.h")))))))
+  (link "hello"
+        (list (compile "hello.c"
+                       #:flags include)
+              (compile "print.c"
+                       #:flags include))))