forked from carp-lang/Carp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Platform.carp
72 lines (54 loc) · 2.17 KB
/
Platform.carp
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
(doc native-triple "triple describing the native platform.")
(defdynamic native-triple [(host-arch) (host-os) "unknown"])
(doc target-triple "triple describing the target platform.")
(defndynamic target-triple []
(let [t (Project.get-config "target")]
(case t
"native" native-triple
(Dynamic.String.split-on "-" t))))
(doc target-arch "target architecture.")
(defdynamic target-arch (car (target-triple)))
(doc target-os "target operating system.")
(defdynamic target-os (cadr (target-triple)))
(doc target-abi "target ABI.")
(defdynamic target-abi (caddr (target-triple)))
(doc target-os? "are we targeting a certain OS?")
(defndynamic target-os? [t]
(= target-os t))
(doc windows-target? "are we targeting Windows?")
(defdynamic windows-target?
(if (target-os? "windows")
true
(target-os? "mingw32")))
(doc linux-target? "are we targeting Linux?")
(defdynamic linux-target? (target-os? "linux"))
(doc mac-target? "are we targeting Mac?")
(defdynamic mac-target? (target-os? "darwin"))
(doc freebsd-target? "are we targeting FreeBSD?")
(defdynamic freebsd-target? (target-os? "freebsd"))
(doc netbsd-target? "are we targeting NetBSD?")
(defdynamic netbsd-target? (target-os? "netbsd"))
(doc posix-target? "are we targeting a POSIX platform?")
(defdynamic posix-target? (= false windows-target?))
(doc target-only "conditionally compile forms when b is true.")
(defndynamic target-only [b forms]
(when b
(eval (cons 'do forms))))
(doc mac-only "compile forms only on Mac.")
(defmacro mac-only [:rest forms]
(target-only mac-target? forms))
(doc linux-only "compile forms only on Linux.")
(defmacro linux-only [:rest forms]
(target-only linux-target? forms))
(doc freebsd-only "compile forms only on FreeBSD.")
(defmacro freebsd-only [:rest forms]
(target-only freebsd-target? forms))
(doc netbsd-only "compile forms only on NetBSD.")
(defmacro netbsd-only [:rest forms]
(target-only netbsd-target? forms))
(doc windows-only "compile forms only on Windows.")
(defmacro windows-only [:rest forms]
(target-only windows-target? forms))
(doc posix-only "compile forms only on POSIX targets.")
(defmacro posix-only [:rest forms]
(target-only posix-target? forms))