diff --git a/Cargo.toml b/Cargo.toml index fe3a0fd..c071d6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,8 @@ [package] name = "lbfgsb-sys" -version = "0.1.0" -authors = ["noshu "] +version = "0.1.1" +authors = ["noshu ", + "Felix C. Morency "] license= "MIT/BSD-3-Clause" description = "The package provides an interface to L-BFGS-B fortran routine" homepage = "https://github.com/noshu/lbfgsb-sys" @@ -10,4 +11,4 @@ build = "build.rs" [features] static = [] [dependencies] -libc = "0.2.11" \ No newline at end of file +libc = "0.2.11" diff --git a/build.rs b/build.rs index c0aa39f..81c52f9 100644 --- a/build.rs +++ b/build.rs @@ -19,16 +19,38 @@ fn main() { let os = if cfg!(target_os = "macos"){"Macos"} else if cfg!(target_os = "windows"){"Windows"} else {"Linux"}; - let com = if os=="Windows" {"mingw32-make"}else{"make"}; - run(Command::new(com) + let make_cmd = if os == "Windows" { "mingw32-make" } else { "make" }; + run(Command::new(make_cmd) .arg(kind) - .arg(format!("OUTPUT={}",output.display())) - .arg(format!("OSNAME={}",os)) + .arg(format!("OUTPUT={}", output.display())) + .arg(format!("OSNAME={}", os)) .current_dir(&source)); println!("cargo:rustc-link-search={}", output.display()); - println!("cargo:rustc-link-lib={}=lbfgs",kind); - println!("cargo:rustc-link-lib=dylib=gfortran"); + println!("cargo:rustc-link-lib={}=lbfgs", kind); + println!("cargo:rustc-link-lib=dylib=gcc"); + + let target = variable!("TARGET"); + let mut fc_lib_type = "dylib"; + if target == "x86_64-apple-darwin" || target == "x86_64-pc-windows-gnu" { + fc_lib_type = "static"; + + // Poke $FC$ for static lib folder + let fc_out = Command::new(variable!("FC")) + .arg("-print-file-name=libgfortran.a") + .output() + .expect("Failed to find libgfortran.a"); + let fc_stdout = String::from_utf8(fc_out.stdout).expect("Invalid path to libgfortran.a"); + let fc_lib_cwd = PathBuf::from(fc_stdout.to_string()); + let fc_lib_pwd = fc_lib_cwd.parent().expect("Path to libgfortran.a not found"); + println!("cargo:rustc-link-search={}", fc_lib_pwd.to_str().unwrap()); + } + + println!("cargo:rustc-link-lib={}=gfortran", fc_lib_type); + + if target == "x86_64-apple-darwin" { + println!("cargo:rustc-link-lib={}=quadmath", fc_lib_type); + } } fn run(command: &mut Command) { println!("Running: {:?}", command); diff --git a/fortran/Makefile b/fortran/Makefile index b367905..7374c58 100644 --- a/fortran/Makefile +++ b/fortran/Makefile @@ -1,5 +1,3 @@ -FC = gfortran -AR = ar AFLAG = crus SFlAG = -shared -o FFLAGS = -O3 -Wall -fexceptions -g -Wno-uninitialized -c -fPIC -o @@ -8,7 +6,7 @@ LINPACK = linpack.f BLAS = blas.f TIMER = timer.f STRING = string.f -static : +static : @echo "static linking selected" @echo "Compiling" $(FC) $(LBFGSB) $(FFLAGS) $(OUTPUT)/lbfgsb.o @@ -26,7 +24,7 @@ ifeq ($(OSNAME),Windows) $(FC) $(LINPACK) $(FFLAGS) $(OUTPUT)/linpack.o $(FC) $(BLAS) $(FFLAGS) $(OUTPUT)/blas.o $(FC) $(TIMER) $(FFLAGS) $(OUTPUT)/timer.o - $(FC) $(STRING) $(FFLAGS) $(OUTPUT)/string.o + $(FC) $(STRING) $(FFLAGS) $(OUTPUT)/string.o @echo "creating static library" $(FC) $(SFlAG) $(OUTPUT)/liblbfgs.dll $(OUTPUT)/*.o endif diff --git a/fortran/lbfgsb.f b/fortran/lbfgsb.f index 79fd112..7f2e044 100644 --- a/fortran/lbfgsb.f +++ b/fortran/lbfgsb.f @@ -3278,8 +3278,10 @@ subroutine subsm ( n, m, nsub, ind, l, u, nbd, x, d, xp, ws, wy, 55 continue if ( dd_p .gt.zero ) then call dcopy( n, xp, 1, x, 1 ) - write(6,*) ' Positive dir derivative in projection ' - write(6,*) ' Using the backtracking step ' + if (iprint .ge. 0) then + write(6,*) ' Positive dir derivative in projection ' + write(6,*) ' Using the backtracking step ' + endif else go to 911 endif