savvy-bindgen 0.8.11

Parse Rust functions, and generate C and R code
Documentation
TARGET = @TARGET@

PROFILE = @PROFILE@
FEATURE_FLAGS = @FEATURE_FLAGS@

# Add flags if necessary
RUSTFLAGS = 

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: $(SHLIB) clean_intermediate

$(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" && \
	  export CC="$(CC)" && \
	  export CFLAGS="$(CFLAGS)" && \
	  export RUSTFLAGS="$(RUSTFLAGS)" && \
	  cargo build --target $(TARGET) --lib --profile $(PROFILE) $(FEATURE_FLAGS) --manifest-path ./rust/Cargo.toml --target-dir $(TARGET_DIR)

clean_intermediate: $(SHLIB)
	rm -f $(STATLIB)

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

.PHONY: all clean_intermediate clean