forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
julia-config.jl
executable file
·78 lines (65 loc) · 1.8 KB
/
julia-config.jl
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
#!/usr/bin/env julia
# This file is a part of Julia. License is MIT: http:https://julialang.org/license
const options =
[
"--cflags",
"--ldflags",
"--ldlibs"
];
function imagePath()
opts = Base.JLOptions();
bytestring(opts.image_file);
end
function libDir()
abspath(dirname(Libdl.dlpath("libjulia")));
end
function includeDir()
joinpath(match(r"(.*)(bin)",JULIA_HOME).captures[1],"include","julia");
end
function unixInitDir()
filePart = split(imagePath(),"/")[end]
return match(Regex("(.*)(/julia/$filePart)"),imagePath()).captures[1];
end
function windowsInitDir()
if imagePath()[end-1:end] == "ji"
return match(r"(.*)(\\julia\\sys.ji)",imagePath()).captures[1];
else
return match(r"(.*)(\\julia\\sys.dll)",imagePath()).captures[1];
end
end
function initDir()
@unix_only return unixInitDir();
@windows_only return windowInitDir();
end
function ldflags()
replace("""-L$(libDir())""","\\","\\\\");
end
function ldlibs()
@unix_only return replace("""-Wl,-rpath,$(libDir()) -ljulia""","\\","\\\\");
@windows_only return replace("""-ljulia""","\\","\\\\");
end
function cflags()
arg1 = replace(initDir(),"\\","\\\\\\\\");
arg2 = replace(includeDir(),"\\","\\\\");
return """-DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2""";
end
function check_args(args)
checked = intersect(args,options);
if length(checked) == 0 || length(checked) != length(args)
println(STDERR,"Usage: julia-config [",reduce((x,y)->"$x|$y",options),"]");
exit(1);
end
end
function main()
check_args(ARGS);
for args in ARGS
if args == "--ldflags"
println(ldflags());
elseif args == "--cflags"
println(cflags());
elseif args == "--ldlibs"
println(ldlibs());
end
end
end
main();