From e6b5fc1dfc61a74a0bd4982bd7cce0b6342cca62 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 9 Oct 2018 09:41:25 +0200 Subject: [PATCH] buildsys: make Julia integration more robust Now configure only checks for a julia binary; then we use julia-config.jl to determine all relevant paths, and do it all from inside Makefile.rules. The downside of this is that if we find a broken Julia, this won't work, but configure won't tell us. The upside is that we get all the correct compiler and linker flags. In particular, we don't have to hardcode `#define JULIA_ENABLE_THREADING` anymore. --- GNUmakefile.in | 1 + Makefile.rules | 2 ++ configure.ac | 65 ++++++++++++++++++++++++++------------------------ src/julia_gc.c | 2 -- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/GNUmakefile.in b/GNUmakefile.in index bcda69c27b..c7e36e38bb 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -66,6 +66,7 @@ READLINE_CPPFLAGS = @READLINE_CPPFLAGS@ READLINE_LDFLAGS = @READLINE_LDFLAGS@ READLINE_LIBS = @READLINE_LIBS@ +JULIA = @JULIA@ JULIA_CPPFLAGS = @JULIA_CPPFLAGS@ JULIA_LDFLAGS = @JULIA_LDFLAGS@ JULIA_LIBS = @JULIA_LIBS@ diff --git a/Makefile.rules b/Makefile.rules index ac0afce8b8..28d87e61fb 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -684,6 +684,8 @@ sysinfo.gap: config.status $(srcdir)/Makefile.rules cnf/GAP-CFLAGS cnf/GAP-CPPFL @echo "GAP_LIBS=\"$(GAP_LIBS)\"" >> $@ @echo "" >> $@ @echo "GAP_OBJS=\"$(OBJS)\"" >> $@ + @echo "" >> $@ + @echo "JULIA=\"$(JULIA)\"" >> $@ # regenerate bin/gap.sh if necessary all: bin/gap.sh diff --git a/configure.ac b/configure.ac index 6a9f1512d5..da8ddb2ed8 100644 --- a/configure.ac +++ b/configure.ac @@ -478,44 +478,47 @@ AC_SUBST([READLINE_LIBS]) dnl Find julia AC_ARG_WITH([julia], [AS_HELP_STRING([--with-julia@<:@=PREFIX@:>@], - [specify a prefix where julia can be found])]) + [specify a prefix where julia can be found])], + [],[with_julia=no] +) AS_IF([test "x$with_julia" != xno],[ - JULIA_LIBS="-ljulia" - AS_CASE([x"$with_julia"], - [xyes|x],[ - JULIA_CPPFLAGS= - JULIA_LDFLAGS= - ], - [*],[ - JULIA_CPPFLAGS="-I$with_julia/include/julia" - JULIA_LDFLAGS="-L$with_julia/lib -Wl,-rpath,$with_julia/lib" - JULIA_LIBS="-ljulia" - ] - ) - - AX_CHECK_LIBRARY([JULIA], [julia.h], [julia], [jl_gc_alloc], [], [], []) - - # TODO: also check for gcext.h, so that we can be sure the user is pointing - # at a modified version of Julia. - - AS_IF([test $ax_cv_have_JULIA = yes],[ - AC_DEFINE([HAVE_LIBJULIA], [1], [Define if you have libjulia]) - ],[ - AS_CASE([x"$with_julia"], - [x], [JULIA_CPPFLAGS= JULIA_LDFLAGS= JULIA_LIBS=], - [*], [AC_MSG_FAILURE([--with-julia was given, but test for julia failed])] - ) - ]) + AC_PATH_PROG([JULIA], [julia], [], [${with_julia}/bin ${PATH}]) + AS_IF([test "x$JULIA" = x],[ AC_MSG_ERROR([no julia executable found]) ]) + + JL_SHARE=$($JULIA -e 'print(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia"))') + AS_IF([test -f "${JL_SHARE}/julia-config.jl"], [], [AC_MSG_ERROR([no julia-config.jl found])]) + + AC_MSG_CHECKING([for JULIA_CPPFLAGS]) + JULIA_CPPFLAGS=$(${JULIA} ${JL_SHARE}/julia-config.jl --cflags 2>/dev/null) + AS_IF([ test $? != 0 ], [AC_MSG_ERROR([failed to obtain JULIA_CPPFLAGS from julia-config.jl])]) + JULIA_CPPFLAGS=${JULIA_CPPFLAGS/-std=gnu99/} # need to remove -std=gnu99 for our C++ code + # remove apostrophes, they mess up quoting when used in shell code(although + # they are fine inside of Makefiles); this could cause problems if any + # paths involve spaces, but then we likely will haves problem in other + # places; in any case, if anybody ever cares about this, we can work on + # finding a better solution. + JULIA_CPPFLAGS=${JULIA_CPPFLAGS//\'/} + AC_MSG_RESULT([${JULIA_CPPFLAGS}]) + + AC_MSG_CHECKING([for JULIA_LDFLAGS]) + JULIA_LDFLAGS=$(${JULIA} ${JL_SHARE}/julia-config.jl --ldflags) + AS_IF([ test $? != 0 ], [AC_MSG_ERROR([failed to obtain JULIA_LDFLAGS from julia-config.jl])]) + JULIA_LDFLAGS=${JULIA_LDFLAGS//\'/} + AC_MSG_RESULT([${JULIA_LDFLAGS}]) + + AC_MSG_CHECKING([for JULIA_LIBS]) + JULIA_LIBS=$(${JULIA} ${JL_SHARE}/julia-config.jl --ldlibs) + AS_IF([ test $? != 0 ], [AC_MSG_ERROR([failed to obtain JULIA_LIBS from julia-config.jl])]) + JULIA_LIBS=${JULIA_LIBS//\'/} + AC_MSG_RESULT([${JULIA_LIBS}]) ]) - -dnl TODO: check if $with_gc = julia; if so, error out if julia is not found - - +AC_SUBST([JULIA]) AC_SUBST([JULIA_CPPFLAGS]) AC_SUBST([JULIA_LDFLAGS]) AC_SUBST([JULIA_LIBS]) +dnl TODO: check if $with_gc = julia; if so, error out if julia is not found dnl Find ward (if HPC-GAP mode is enabled) AC_ARG_WITH([ward], diff --git a/src/julia_gc.c b/src/julia_gc.c index 7f7f3fac9f..47c101a5ac 100644 --- a/src/julia_gc.c +++ b/src/julia_gc.c @@ -9,8 +9,6 @@ ** and gasman.c for two other garbage collector implementations. **/ -#define JULIA_ENABLE_THREADING - #include "code.h" #include "funcs.h" #include "gapstate.h"