INCL = ../inst/include
PKG_CPPFLAGS = -DNO_UNALIGNED -DLIBDEFLATE_STATIC -DPGENLIB_NOPRINT -I$(INCL) -I$(INCL)/libdeflate
PKG_LIBS = -L. -lPLINK2 -lzstd -lPGDEFLATE -lz -lpthread

LIBDEFLATE_SOURCES = $(INCL)/libdeflate/lib/zlib_decompress.c $(INCL)/libdeflate/lib/zlib_compress.c $(INCL)/libdeflate/lib/utils.c $(INCL)/libdeflate/lib/gzip_compress.c $(INCL)/libdeflate/lib/crc32.c $(INCL)/libdeflate/lib/adler32.c $(INCL)/libdeflate/lib/deflate_decompress.c $(INCL)/libdeflate/lib/deflate_compress.c $(INCL)/libdeflate/lib/gzip_decompress.c $(INCL)/libdeflate/lib/arm/arm_cpu_features.c $(INCL)/libdeflate/lib/x86/x86_cpu_features.c
LIBDEFLATE = $(LIBDEFLATE_SOURCES:.c=.o)

LIBPLINK2_SOURCES = $(INCL)/include/plink2_base.cc $(INCL)/include/plink2_bits.cc $(INCL)/include/pgenlib_ffi_support.cc $(INCL)/include/pgenlib_misc.cc $(INCL)/include/pgenlib_read.cc $(INCL)/include/plink2_bgzf.cc $(INCL)/include/plink2_htable.cc $(INCL)/include/plink2_memory.cc $(INCL)/include/plink2_string.cc $(INCL)/include/plink2_text.cc $(INCL)/include/plink2_thread.cc $(INCL)/include/plink2_zstfile.cc $(INCL)/include/pvar_ffi_support.cc
LIBPLINK2 = $(LIBPLINK2_SOURCES:.cc=.o)

$(SHLIB): libPGDEFLATE.a libPLINK2.a

libPGDEFLATE.a: $(LIBDEFLATE)
	$(AR) rcs libPGDEFLATE.a $(LIBDEFLATE)

libPLINK2.a: $(LIBPLINK2)
	$(AR) rcs libPLINK2.a $(LIBPLINK2)

clean:
	rm -f $(SHLIB) $(OBJECTS) $(LIBDEFLATE) $(LIBPLINK2)

OBJECTS = pvar.o pgenlibr.o RcppExports.o
