Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 82 lines (69 sloc) 2.192 kB
fbf1348 @Keno Add OS Detection capabilities
Keno authored
1 #ifndef OS_DETECT_H
2 #define OS_DETECT_H
3
418f0ef @Keno OS detect refactor
Keno authored
4 /* This file uses is used by both Julia and C
5 After a major refactor, the C parts are now no longer necessary
6 and have thus been removed. Should you want to add them again, they
7 are avaiable as src/os_detect.h in git commit fbf1348369cb5c79810ff3015ac711c9dcdef2ca */
fbf1348 @Keno Add OS Detection capabilities
Keno authored
8
9 /* LOGIC PRIMITIVES */
418f0ef @Keno OS detect refactor
Keno authored
10
11 /* These logic primitives may be used to do basic if/else in the C preprocessor
12 This can be useful for creating if/else type structures in C and Julia.
13 Currently there's support for up to 10 OSs. If you need more add a correspondig JL_BOOL_# */
14
fbf1348 @Keno Add OS Detection capabilities
Keno authored
15 #define JL_BOOL_0 0
16 #define JL_BOOL_1 1
17 #define JL_BOOL_2 1
18 #define JL_BOOL_3 1
19 #define JL_BOOL_4 1
20 #define JL_BOOL_5 1
21 #define JL_BOOL_6 1
22 #define JL_BOOL_7 1
23 #define JL_BOOL_8 1
24 #define JL_BOOL_9 1
418f0ef @Keno OS detect refactor
Keno authored
25 #define JL_TF_0 false
26 #define JL_TF_1 true
27 #define JL_TF(x) JL_TF2(x)
28 #define JL_TF2(x) JL_TF_##x
fbf1348 @Keno Add OS Detection capabilities
Keno authored
29 #define JL_BOOL(x) JL_BOOL_##x
30 #define I(x) x
31
32 #define JL_IF_0(T,F) F
33 #define JL_IF_1(T,F) T
34 #define JL_IF2(C,T,F) JL_IF_##C(T,F)
35 #define JL_IF(C,T,F) JL_IF2(C,T,F)
36
418f0ef @Keno OS detect refactor
Keno authored
37
fbf1348 @Keno Add OS Detection capabilities
Keno authored
38 /* OS MAP - to add an OS just append entry to map.
39 All other functions will be updated automagically, but detection by variables must be added to jl_current_os
40 X(NUM,C-Var,Julia name) - General INFO
41 XX(ISUNIX) - OS Traits
42 */
43 #define NUM_OS = 4
44 #define NOP(x)
45 #define JL_OS_MAP2(X,XX) \
46 X(0,Windows) XX(0) \
47 X(1,Linux) XX(1) \
48 X(2,FreeBSD) XX(1) \
49 X(3,OSX) XX(1)
50 #define JL_OS_MAP(X) JL_OS_MAP2(X,NOP)
51 #define OS_INDEX_MAP(x) x
52
53 #if defined(__WIN32__)
54 #define OS_CURRENT Windows
877d8f5 @nolta replace __linux -> __linux__
nolta authored
55 #elif defined(__linux__)
fbf1348 @Keno Add OS Detection capabilities
Keno authored
56 #define OS_CURRENT Linux
57 #elif defined(__FreeBSD__)
58 #define OS_CURRENT FreeBSD
59 #elif defined(__APPLE__)
60 #define OS_CURRENT OSX
61 #else
62 #define OS_CURRENT Unknown
63 #endif
64
65 #ifndef JULIA
418f0ef @Keno OS detect refactor
Keno authored
66 /** REMOVED - SEE ABOVE COMMENT */
fbf1348 @Keno Add OS Detection capabilities
Keno authored
67 #else
68
418f0ef @Keno OS detect refactor
Keno authored
69 const CURRENT_OS = :OS_CURRENT
70
71 #define OS_NAME_IFELSE(NUM,NAME) JL_IF(JL_BOOL(NUM),elseif,if) (os==:NAME) return
72 #define ATTR(IS_UNIX) JL_TF(JL_BOOL(IS_UNIX)); \n
73 function _jl_is_unix(os::Symbol)
74 JL_OS_MAP2(OS_NAME_IFELSE,ATTR)
fbf1348 @Keno Add OS Detection capabilities
Keno authored
75 else
418f0ef @Keno OS detect refactor
Keno authored
76 error("Unknown Operating System")
fbf1348 @Keno Add OS Detection capabilities
Keno authored
77 end
78 end
418f0ef @Keno OS detect refactor
Keno authored
79
fbf1348 @Keno Add OS Detection capabilities
Keno authored
80 #endif
81 #endif // OS_DETECT_H
Something went wrong with that request. Please try again.