Skip to content

Commit b3e80d9

Browse files
NHDalySimonDanisch
authored andcommitted
Carry -g & -O through to the gcc commands also. (#22)
* Carry -g & -O through to the `gcc` commands also. Before this commit, those flags only affect the julia parts of the script (building object file). This commit changes juliac to also pass `-g` and `-O` to `gcc` when building a shared library or executable. * Oops, also pass debug flag in src/system_image.jl's build_shared(). Also carry `debug` value through when calling build_shared() in `compile_system_image` if `debug == true`. Skips optmization, since there's flag for it in system_image.jl.
1 parent 57aa56a commit b3e80d9

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/static_julia.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,33 +122,38 @@ function julia_compile(
122122
math_mode, depwarn
123123
)
124124

125-
shared && build_shared(s_file, joinpath(tmp_dir, o_file), verbose)
125+
shared && build_shared(s_file, joinpath(tmp_dir, o_file), verbose, optimize, debug)
126126

127-
executable && compile_executable(s_file, e_file, cprog, verbose)
127+
executable && compile_executable(s_file, e_file, cprog, verbose, optimize, debug)
128128

129129
julialibs && sync_julia_files(verbose)
130130

131131
end
132132

133133

134-
function julia_flags()
134+
function julia_flags(optimize, debug)
135135
if julia_v07
136136
command = `$(Base.julia_cmd()) --startup-file=no $(joinpath(dirname(Sys.BINDIR), "share", "julia", "julia-config.jl"))`
137-
return `$(Base.shell_split(read(\`$command --allflags\`, String)))`
137+
flags = `$(Base.shell_split(read(\`$command --allflags\`, String)))`
138+
optimize == nothing || (flags = `$flags -O$optimize`)
139+
debug != 2 || (flags = `$flags -g`)
140+
return flags
138141
else
139142
command = `$(Base.julia_cmd()) --startup-file=no $(joinpath(dirname(JULIA_HOME), "share", "julia", "julia-config.jl"))`
140143
cflags = `$(Base.shell_split(readstring(\`$command --cflags\`)))`
144+
optimize == nothing || (cflags = `$cflags -O$optimize`)
145+
debug != 2 || (cflags = `$cflags -g`)
141146
ldflags = `$(Base.shell_split(readstring(\`$command --ldflags\`)))`
142147
ldlibs = `$(Base.shell_split(readstring(\`$command --ldlibs\`)))`
143148
return `$cflags $ldflags $ldlibs`
144149
end
145150
end
146151
147152
148-
function build_shared(s_file, o_file, verbose = false)
153+
function build_shared(s_file, o_file, verbose, optimize, debug)
149154
cc = system_compiler()
150155
bitness = bitness_flag()
151-
flags = julia_flags()
156+
flags = julia_flags(optimize, debug)
152157
command = `$cc $bitness -shared -o $s_file $o_file $flags`
153158
if isapple()
154159
command = `$command -Wl,-install_name,@rpath/$s_file`
@@ -160,10 +165,10 @@ function build_shared(s_file, o_file, verbose = false)
160165
end
161166
162167
163-
function compile_executable(s_file, e_file, cprog, verbose = false)
168+
function compile_executable(s_file, e_file, cprog, verbose, optimize, debug)
164169
bitness = bitness_flag()
165170
cc = system_compiler()
166-
flags = julia_flags()
171+
flags = julia_flags(optimize, debug)
167172
command = `$cc $bitness -DJULIAC_PROGRAM_LIBNAME=\"$s_file\" -o $e_file $cprog $s_file $flags`
168173
if iswindows()
169174
RPMbindir = PackageCompiler.mingw_dir("bin")

src/system_image.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function compile_system_image(sysimg_path, cpu_target; debug = false)
3434
info("$julia -C $cpu_target --output-ji $sysimg_path.ji --output-o $sysimg_path.o -J $inference_path.ji --startup-file=no sysimg.jl")
3535
run(`$julia -C $cpu_target --output-ji $sysimg_path.ji --output-o $sysimg_path.o -J $inference_path.ji --startup-file=no sysimg.jl`)
3636

37-
build_shared("$sysimg_path.$(Libdl.dlext)", "$sysimg_path.o", true)
37+
build_shared("$sysimg_path.$(Libdl.dlext)", "$sysimg_path.o",
38+
true, nothing, (if debug 2 else nothing end))
3839
end
3940
end

0 commit comments

Comments
 (0)