TARGET_DIR = ./rust/target
LIBDIR = $(TARGET_DIR)/release
STATLIB = $(LIBDIR)/libcrosscell_r.a
PKG_LIBS = -L$(LIBDIR) -lcrosscell_r

all: C_clean

$(SHLIB): $(STATLIB)

CARGOTMP = $(CURDIR)/.cargo

$(STATLIB):
	# In some environments, ~/.cargo/bin might not be in PATH, so we need
	# to set it here to ensure cargo can be found
	export PATH="$(PATH):$(HOME)/.cargo/bin" && \
		cargo build --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
	if [ "$(NOT_CRAN)" != "true" ]; then \
		rm -Rf $(CARGOTMP) && \
		rm -Rf $(LIBDIR)/build; \
	fi

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

clean:
	rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR)
