|
| 1 | +# Building OpenSpecFun from scratch |
| 2 | + |
| 3 | +using Base.Math: libm |
| 4 | + |
| 5 | +# If Julia is built with OpenLibm, we want to build OpenSpecFun with it as well. |
| 6 | +# Unfortunately this requires a fair bit more work, as we need to link to the .so |
| 7 | +# and to include the headers, which aren't readily available. |
| 8 | +if libm == "libopenlibm" |
| 9 | + const OLM_VERS = v"0.5.4" |
| 10 | + use_openlibm = true |
| 11 | + |
| 12 | + if !isdir(libdir(openspecfun)) |
| 13 | + mkpath(libdir(openspecfun)) |
| 14 | + end |
| 15 | + |
| 16 | + openlibm_so = Libdl.dlpath(libm) |
| 17 | + |
| 18 | + # Copy over the OpenLibm .so |
| 19 | + cp(openlibm_so, joinpath(libdir(openspecfun), basename(openlibm_so)), |
| 20 | + remove_destination=true) |
| 21 | + |
| 22 | + if !isdir(srcdir(openspecfun)) |
| 23 | + mkpath(srcdir(openspecfun)) |
| 24 | + end |
| 25 | + |
| 26 | + # Grab and unpack the tarball so we can get the header files |
| 27 | + openlibm_tarball = joinpath(srcdir(openspecfun), "openlibm-$OLM_VERS.tar.gz") |
| 28 | + run(``` |
| 29 | + curl -fkL --connect-timeout 15 -y 15 |
| 30 | + https://github.com/JuliaLang/openlibm/archive/v$OLM_VERS.tar.gz |
| 31 | + -o $openlibm_tarball |
| 32 | + ```) |
| 33 | + openlibm_src = joinpath(srcdir(openspecfun), "openlibm") |
| 34 | + if !isdir(openlibm_src) |
| 35 | + mkpath(openlibm_src) |
| 36 | + end |
| 37 | + run(`tar -C $openlibm_src --strip-components 1 -xf $openlibm_tarball`) |
| 38 | + |
| 39 | + # Copy over all of the OpenLibm headers |
| 40 | + openlibm_include = joinpath(includedir(openspecfun), "openlibm") |
| 41 | + if !isdir(openlibm_include) |
| 42 | + mkpath(openlibm_include) |
| 43 | + end |
| 44 | + for f in readdir(joinpath(openlibm_src, "include")) |
| 45 | + cp(joinpath(openlibm_src, "include", f), joinpath(openlibm_include, f), |
| 46 | + remove_destination=true) |
| 47 | + end |
| 48 | + for f in readdir(joinpath(openlibm_src, "src")) |
| 49 | + if endswith(f, ".h") |
| 50 | + cp(joinpath(openlibm_src, "src", f), joinpath(openlibm_include, f), |
| 51 | + remove_destination=true) |
| 52 | + end |
| 53 | + end |
| 54 | +else |
| 55 | + use_openlibm = false |
| 56 | +end |
| 57 | + |
| 58 | +fc = "gfortran" |
| 59 | + |
| 60 | +# macOS has precompiled binaries, so it's just FreeBSD that should default to Clang |
| 61 | +if Sys.KERNEL === :FreeBSD |
| 62 | + cc = "clang" |
| 63 | + use_clang = true |
| 64 | +else |
| 65 | + cc = "gcc" |
| 66 | + use_clang = false |
| 67 | +end |
| 68 | + |
| 69 | +if Sys.ARCH in [:i386, :i387, :i486, :i586, :i686] |
| 70 | + cc *= " -m32" |
| 71 | + fc *= " -m32" |
| 72 | +elseif Sys.ARCH === :x86_64 |
| 73 | + cc *= " -m64" |
| 74 | + fc *= " -m64" |
| 75 | +end |
| 76 | + |
| 77 | +flags = [ |
| 78 | + # OpenSpecFun build flags |
| 79 | + "ARCH=\"$(Sys.ARCH)\"", |
| 80 | + "CC=\"$cc\"", |
| 81 | + "FC=\"$fc\"", |
| 82 | + "USECLANG=$(Int(use_clang))", |
| 83 | + "USEGCC=$(Int(!use_clang))", |
| 84 | + "USE_OPENLIBM=$(Int(use_openlibm))", |
| 85 | + "CFLAGS=\"-O3 -std=c99\"", |
| 86 | + "FFLAGS=\"-O2 -fPIC\"", |
| 87 | + "LDFLAGS=\"-L$(libdir(openspecfun)) -Wl,-rpath,'\$\$ORIGIN' -Wl,-z,origin\"", |
| 88 | + # Make flags |
| 89 | + "DESTDIR=\"\"", |
| 90 | + "prefix=$(depsdir(openspecfun))", |
| 91 | + "libdir=$(libdir(openspecfun))", |
| 92 | + "shlibdir=$(libdir(openspecfun))", |
| 93 | + "includedir=$(includedir(openspecfun))", |
| 94 | + "O=" |
| 95 | +] |
| 96 | + |
| 97 | +provides(Sources, URI("https://github.com/JuliaLang/openspecfun/archive/v$OSF_VERS.tar.gz"), |
| 98 | + openspecfun) |
| 99 | + |
| 100 | +provides(BuildProcess, |
| 101 | + (@build_steps begin |
| 102 | + GetSources(openspecfun) |
| 103 | + CreateDirectory(builddir(openspecfun)) |
| 104 | + @build_steps begin |
| 105 | + ChangeDirectory(builddir(openspecfun)) |
| 106 | + FileRule(joinpath(libdir(openspecfun), "libopenspecfun." * Libdl.dlext), |
| 107 | + @build_steps begin |
| 108 | + CreateDirectory(libdir(openspecfun)) |
| 109 | + `$MAKE_CMD install $flags` |
| 110 | + end) |
| 111 | + end |
| 112 | + end), openspecfun) |
0 commit comments