@@ -137,7 +137,10 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
137137 s_file = " lib" * file_name * " .$(Libdl. dlext) "
138138 e_file = file_name * (is_windows () ? " .exe" : " " )
139139
140+ # TODO : these should probably be emitted from julia-config also:
140141 julia_pkglibdir = joinpath (dirname (Pkg. dir ()), " lib" , basename (Pkg. dir ()))
142+ shlibdir = is_windows () ? JULIA_HOME : abspath (JULIA_HOME, Base. LIBDIR)
143+ private_shlibdir = abspath (JULIA_HOME, Base. PRIVATE_LIBDIR)
141144
142145 if is_windows ()
143146 julia_program = replace (julia_program, " \\ " , " \\\\ " )
@@ -146,12 +149,18 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
146149
147150 delete_object = false
148151 if object || shared || executable
149- command = ` "$(Base. julia_cmd ()) " "--startup-file=no" "--output-o" "$o_file " "-e"
150- "include(\" $julia_program \" ); push!(Base.LOAD_CACHE_PATH, \" $julia_pkglibdir \" ); empty!(Base.LOAD_CACHE_PATH)"`
152+ command = ` $(Base. julia_cmd ()) --startup-file=no -e "
153+ VERSION >= v\" 0.7+\" && Base.init_load_path($(repr (JULIA_HOME)) ) # initialize location of site-packages
154+ empty!(Base.LOAD_CACHE_PATH) # reset / remove any builtin paths
155+ push!(Base.LOAD_CACHE_PATH, abspath(\" ji$VERSION \" )) #$(repr (julia_pkglibdir)) ) # enable usage of precompile files
156+ include($(repr (julia_program)) )
157+ empty!(Base.LOAD_CACHE_PATH) # reset / remove build-system-relative paths
158+ "`
151159 if verbose
152160 println (" Build object file \" $o_file \" :\n $command " )
153161 end
154- run (command)
162+ run (command) # first populate the .ji cache (when JULIA_HOME is defined)
163+ run (` $command --output-o $o_file ` ) # then output the combined file
155164 if ! object
156165 delete_object = true
157166 end
@@ -167,7 +176,9 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
167176
168177 if shared || executable
169178 command = ` $cc -m64 -shared -o $s_file $o_file $cflags $ldflags $ldlibs `
170- if is_windows ()
179+ if is_apple ()
180+ command = ` $command -Wl,-install_name,@rpath/lib$file_name .dylib`
181+ elseif is_windows ()
171182 command = ` $command -Wl,--export-all-symbols`
172183 end
173184 if verbose
@@ -178,7 +189,9 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
178189
179190 if executable
180191 command = ` $cc -m64 -o $e_file $c_program $s_file $cflags $ldflags $ldlibs `
181- if is_unix ()
192+ if is_apple ()
193+ command = ` $command -Wl,-rpath,@executable_path`
194+ elseif is_unix ()
182195 command = ` $command -Wl,-rpath,\$ ORIGIN`
183196 end
184197 if verbose
@@ -198,15 +211,14 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
198211 if verbose
199212 println (" Sync Julia libraries:" )
200213 end
201- if is_windows ()
202- dir = JULIA_HOME
203- libfiles = joinpath .(dir, filter (x -> ismatch (r" .+\. dll$" , x), readdir (dir)))
204- else
205- dir = joinpath (JULIA_HOME, " .." , " lib" )
206- libfiles1 = joinpath .(dir, filter (x -> ismatch (r" ^lib.*\. so(?:$|\. )" , x), readdir (dir)))
207- dir = joinpath (JULIA_HOME, " .." , " lib" , " julia" )
208- libfiles2 = joinpath .(dir, filter (x -> ismatch (r" ^lib.*\. so(?:$|\. )" , x), readdir (dir)))
209- libfiles = vcat (libfiles1, libfiles2)
214+ libfiles = String[]
215+ dlext = " ." * Libdl. dlext
216+ for dir in (shlibdir, private_shlibdir)
217+ if is_windows () || is_apple ()
218+ append! (libfiles, joinpath .(dir, filter (x -> endswith (x, dlext), readdir (dir))))
219+ else
220+ append! (libfiles, joinpath .(dir, filter (x -> ismatch (r" ^lib.+\. so(?:\.\d +)*$" , x), readdir (dir))))
221+ end
210222 end
211223 sync = false
212224 for src in libfiles
@@ -218,11 +230,11 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
218230 if verbose
219231 println (" $dst " )
220232 end
221- cp (src, dst, remove_destination= true )
233+ cp (src, dst, remove_destination= true , follow_symlinks = false )
222234 sync = true
223235 end
224236 end
225- if ! sync
237+ if verbose && ! sync
226238 println (" none" )
227239 end
228240 end
0 commit comments