LIBDIR = myrustlib/target/release
STATLIB = $(LIBDIR)/libmyrustlib.a
PKG_CFLAGS = -pthread
PKG_LIBS = -L$(LIBDIR) -lmyrustlib -lresolv -pthread

#all: clean

$(SHLIB): $(STATLIB)

# CRAN policy forbids using $HOME so we build in the current working dir.
# This makes things really slow because we have to reinstall all dependencies.
CARGOTMP=$(PWD)/.cargo
export CARGO_HOME=$(CARGOTMP)
export CARGO_BUILD_JOBS=2

$(STATLIB):
	if [ -f myrustlib/vendor.tar.xz ]; then tar xf myrustlib/vendor.tar.xz && mkdir -p $(CARGOTMP) && cp myrustlib/vendor-config.toml $(CARGOTMP)/config.toml; fi
	PATH="${PATH}:${HOME}/.cargo/bin" cargo build --release --manifest-path=myrustlib/Cargo.toml
	rm -Rf $(CARGOTMP) vendor || true # CRAN wants us to remove "detritus"
	rm -Rf $(LIBDIR)/build || true

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