@@ -38,6 +38,12 @@ function main(args)
3838 default = nothing
3939 metavar = " <file>"
4040 help = " start up with the given system image file"
41+ " --compile"
42+ arg_type = String
43+ default = nothing
44+ metavar = " {yes|no|all|min}"
45+ range_tester = (x -> x == " yes" || x == " no" || x == " all" || x == " min" )
46+ help = " enable or disable JIT compiler, or request exhaustive compilation"
4147 " --cpu-target" , " -C"
4248 arg_type = String
4349 default = nothing
@@ -46,40 +52,43 @@ function main(args)
4652 " --optimize" , " -O"
4753 arg_type = Int
4854 default = nothing
49- range_tester = (x -> 0 <= x <= 3 )
5055 metavar = " {0,1,2,3}"
56+ range_tester = (x -> 0 <= x <= 3 )
5157 help = " set optimization level"
5258 " -g"
5359 arg_type = Int
5460 default = nothing
55- range_tester = (x -> 0 <= x <= 2 )
5661 dest_name = " debug"
5762 metavar = " {0,1,2}"
63+ range_tester = (x -> 0 <= x <= 2 )
5864 help = " set debugging information level"
5965 " --inline"
6066 arg_type = String
6167 default = nothing
62- range_tester = (x -> x == " yes" || x == " no" )
6368 metavar = " {yes|no}"
69+ range_tester = (x -> x == " yes" || x == " no" )
6470 help = " control whether inlining is permitted"
6571 " --check-bounds"
6672 arg_type = String
6773 default = nothing
68- range_tester = (x -> x == " yes" || x == " no" )
6974 metavar = " {yes|no}"
75+ range_tester = (x -> x == " yes" || x == " no" )
7076 help = " emit bounds checks always or never"
7177 " --math-mode"
7278 arg_type = String
7379 default = nothing
74- range_tester = (x -> x == " ieee" || x == " fast" )
7580 metavar = " {ieee,fast}"
81+ range_tester = (x -> x == " ieee" || x == " fast" )
7682 help = " set floating point optimizations"
7783 " --depwarn"
7884 arg_type = String
7985 default = nothing
80- range_tester = (x -> x == " yes" || x == " no" || x == " error" )
8186 metavar = " {yes|no|error}"
87+ range_tester = (x -> x == " yes" || x == " no" || x == " error" )
8288 help = " set syntax and method deprecation warnings"
89+ " --auto" , " -a"
90+ action = :store_true
91+ help = " automatically build required dependencies"
8392 " --object" , " -o"
8493 action = :store_true
8594 help = " build object file"
@@ -96,9 +105,9 @@ function main(args)
96105
97106 s. epilog = """
98107 examples:\n
99- \u a0\u a0juliac.jl -ve hello.jl # verbose, build executable\n
100- \u a0\u a0juliac.jl -ve hello.jl myprog.c # embed into user defined C program\n
101- \u a0\u a0juliac.jl -qo hello.jl # quiet, build object file\n
108+ \u a0\u a0juliac.jl -vae hello.jl # verbose, auto , build executable\n
109+ \u a0\u a0juliac.jl -vae hello.jl myprog.c # embed into user defined C program\n
110+ \u a0\u a0juliac.jl -qo hello.jl # quiet, build object file only \n
102111 \u a0\u a0juliac.jl -vosej hello.jl # build all and sync Julia libs\n
103112 """
104113
@@ -117,13 +126,15 @@ function main(args)
117126 parsed_args[" quiet" ],
118127 parsed_args[" clean" ],
119128 parsed_args[" sysimage" ],
129+ parsed_args[" compile" ],
120130 parsed_args[" cpu-target" ],
121131 parsed_args[" optimize" ],
122132 parsed_args[" debug" ],
123133 parsed_args[" inline" ],
124134 parsed_args[" check-bounds" ],
125135 parsed_args[" math-mode" ],
126136 parsed_args[" depwarn" ],
137+ parsed_args[" auto" ],
127138 parsed_args[" object" ],
128139 parsed_args[" shared" ],
129140 parsed_args[" executable" ],
@@ -132,12 +143,17 @@ function main(args)
132143end
133144
134145function julia_compile (julia_program, c_program= nothing , build_dir= " builddir" , verbose= false , quiet= false ,
135- clean= false , sysimage = nothing , cpu_target = nothing , optimize = nothing , debug = nothing ,
136- inline= nothing , check_bounds= nothing , math_mode= nothing , depwarn= nothing ,
137- object= false , shared= false , executable= true , julialibs= true )
146+ clean= false , sysimage = nothing , compile = nothing , cpu_target = nothing , optimize = nothing ,
147+ debug = nothing , inline= nothing , check_bounds= nothing , math_mode= nothing , depwarn= nothing ,
148+ auto = false , object= false , shared= false , executable= true , julialibs= true )
138149
139150 verbose && quiet && (verbose = false )
140151
152+ if auto
153+ executable && (shared = true )
154+ shared && (object = true )
155+ end
156+
141157 julia_program = abspath (julia_program)
142158 isfile (julia_program) || error (" Cannot find file:\n \" $julia_program \" " )
143159 quiet || println (" Julia program file:\n \" $julia_program \" " )
@@ -174,23 +190,24 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
174190 verbose && println (" Already in build directory" )
175191 end
176192
177- file_name = splitext (basename (julia_program))[1 ]
178- o_file = file_name * " .o"
179- s_file = " lib" * file_name * " .$(Libdl. dlext) "
180- e_file = file_name * (is_windows () ? " .exe" : " " )
193+ julia_program_basename = splitext (basename (julia_program))[1 ]
194+ o_file = julia_program_basename * " .o"
195+ s_file = " lib" * julia_program_basename * " .$(Libdl. dlext) "
196+ e_file = julia_program_basename * (is_windows () ? " .exe" : " " )
197+ tmp_dir = " tmp_v$VERSION "
181198
182199 # TODO : these should probably be emitted from julia-config also:
183200 shlibdir = is_windows () ? JULIA_HOME : abspath (JULIA_HOME, Base. LIBDIR)
184201 private_shlibdir = abspath (JULIA_HOME, Base. PRIVATE_LIBDIR)
185202
186- delete_object = false
187- if object || shared || executable
203+ if object
188204 julia_cmd = ` $(Base. julia_cmd ()) `
189205 if length (julia_cmd. exec) != 5 || ! all (startswith .(julia_cmd. exec[2 : 5 ], [" -C" , " -J" , " --compile" , " --depwarn" ]))
190206 error (" Unexpected format of \" Base.julia_cmd()\" , you may be using an incompatible version of Julia" )
191207 end
192208 sysimage == nothing || (julia_cmd. exec[3 ] = " -J$sysimage " )
193209 push! (julia_cmd. exec, " --startup-file=no" )
210+ compile == nothing || (julia_cmd. exec[4 ] = " --compile=$compile " )
194211 cpu_target == nothing || (julia_cmd. exec[2 ] = " -C$cpu_target " )
195212 optimize == nothing || push! (julia_cmd. exec, " -O$optimize " )
196213 debug == nothing || push! (julia_cmd. exec, " -g$debug " )
@@ -202,16 +219,15 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
202219 expr = "
203220 VERSION >= v\" 0.7+\" && Base.init_load_path($(repr (JULIA_HOME)) ) # initialize location of site-packages
204221 empty!(Base.LOAD_CACHE_PATH) # reset / remove any builtin paths
205- push!(Base.LOAD_CACHE_PATH, abspath(\" cache_ji_v $VERSION \" )) # enable usage of precompiled files
222+ push!(Base.LOAD_CACHE_PATH, abspath(\" $tmp_dir \" )) # enable usage of precompiled files
206223 include($(repr (julia_program)) ) # include \" julia_program\" file
207224 empty!(Base.LOAD_CACHE_PATH) # reset / remove build-system-relative paths"
208225 command = ` $julia_cmd -e $expr `
209- verbose && println (" Build \" .ji\" files local cache :\n $command " )
226+ verbose && println (" Build \" .ji\" files:\n $command " )
210227 run (command)
211- command = ` $julia_cmd --output-o $o_file -e $expr `
228+ command = ` $julia_cmd --output-o $( joinpath (tmp_dir, o_file)) -e $expr `
212229 verbose && println (" Build object file \" $o_file \" :\n $command " )
213230 run (command)
214- object || (delete_object = true )
215231 end
216232
217233 if shared || executable
@@ -222,10 +238,10 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
222238 cc = is_windows () ? " x86_64-w64-mingw32-gcc" : " gcc"
223239 end
224240
225- if shared || executable
226- command = ` $cc -m64 -shared -o $s_file $o_file $cflags $ldflags $ldlibs `
241+ if shared
242+ command = ` $cc -m64 -shared -o $s_file $( joinpath (tmp_dir, o_file)) $cflags $ldflags $ldlibs `
227243 if is_apple ()
228- command = ` $command -Wl,-install_name,@rpath/lib$file_name .dylib`
244+ command = ` $command -Wl,-install_name,@rpath/lib$julia_program_basename .dylib`
229245 elseif is_windows ()
230246 command = ` $command -Wl,--export-all-symbols`
231247 end
@@ -244,11 +260,6 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
244260 run (command)
245261 end
246262
247- if delete_object && isfile (o_file)
248- verbose && println (" Delete object file \" $o_file \" " )
249- rm (o_file)
250- end
251-
252263 if julialibs
253264 verbose && println (" Sync Julia libraries:" )
254265 libfiles = String[]
0 commit comments