savvy-bindgen 0.5.2

Parse Rust functions, and generate C and R code
Documentation
TARGET = x86_64-pc-windows-gnu

# catch DEBUG envvar, which is passed from pkgbuild::compile_dll()
PROFILE = $(subst x,release,$(subst truex,dev,$(DEBUG)x))

TARGET_DIR = $(CURDIR)/rust/target
LIBDIR = $(TARGET_DIR)/$(TARGET)/$(subst dev,debug,$(PROFILE))
STATLIB = $(LIBDIR)/lib{}.a
PKG_LIBS = -L$(LIBDIR) -l{} -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll

# Rtools doesn't have the linker in the location that cargo expects, so we need
# to overwrite it via configuration.
CARGO_LINKER = x86_64-w64-mingw32.static.posix-gcc.exe

all: C_clean

$(SHLIB): $(STATLIB)

$(STATLIB):
	# When the GNU toolchain is used (i.e. on CRAN), -lgcc_eh is specified for
	# building proc-macro2, but Rtools doesn't contain libgcc_eh. This isn't used
	# in actual, but we need this tweak to please the compiler.
	mkdir -p $(LIBDIR)/libgcc_mock && touch $(LIBDIR)/libgcc_mock/libgcc_eh.a

	export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="$(CARGO_LINKER)" && \
	  export LIBRARY_PATH="$${{LIBRARY_PATH}};$(LIBDIR)/libgcc_mock" && \
	  cargo build --target $(TARGET) --lib --profile $(PROFILE) --manifest-path ./rust/Cargo.toml --target-dir $(TARGET_DIR)

C_clean:
	rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)

clean:
	rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) rust/target