CWARN = -Wall -Wextra -Wshadow -Wformat-security -Wdouble-promotion -Wfloat-conversion
CXXWARN = ${CWARN} -Wold-style-cast

# Necessary for older gcc versions.
CWARN2 = -Wall -Wextra -Wshadow -Wformat-security
CXXWARN2 = ${CWARN2} -Wold-style-cast

CSRC = include/SFMT.c \
       libdeflate/lib/adler32.c \
       libdeflate/lib/crc32.c \
       libdeflate/lib/deflate_compress.c \
       libdeflate/lib/deflate_decompress.c \
       libdeflate/lib/gzip_compress.c \
       libdeflate/lib/gzip_decompress.c \
       libdeflate/lib/utils.c \
       libdeflate/lib/zlib_compress.c \
       libdeflate/lib/zlib_decompress.c \
       libdeflate/lib/arm/arm_cpu_features.c \
       libdeflate/lib/x86/x86_cpu_features.c

ZCSRC = zstd/lib/common/debug.c \
        zstd/lib/common/entropy_common.c \
        zstd/lib/common/error_private.c \
        zstd/lib/common/fse_decompress.c \
        zstd/lib/common/pool.c \
        zstd/lib/common/threading.c \
        zstd/lib/common/xxhash.c \
        zstd/lib/common/zstd_common.c \
        zstd/lib/compress/fse_compress.c \
        zstd/lib/compress/hist.c \
        zstd/lib/compress/huf_compress.c \
        zstd/lib/compress/zstd_compress.c \
        zstd/lib/compress/zstd_compress_literals.c \
        zstd/lib/compress/zstd_compress_sequences.c \
        zstd/lib/compress/zstd_compress_superblock.c \
        zstd/lib/compress/zstd_double_fast.c \
        zstd/lib/compress/zstd_fast.c \
        zstd/lib/compress/zstd_lazy.c \
        zstd/lib/compress/zstd_ldm.c \
        zstd/lib/compress/zstd_opt.c \
        zstd/lib/compress/zstd_preSplit.c \
        zstd/lib/compress/zstdmt_compress.c \
        zstd/lib/decompress/huf_decompress.c \
        zstd/lib/decompress/zstd_ddict.c \
        zstd/lib/decompress/zstd_decompress.c \
        zstd/lib/decompress/zstd_decompress_block.c

ZSSRC = zstd/lib/decompress/huf_decompress_amd64.S

PGENLIB_CCSRC = include/plink2_base.cc \
                include/plink2_bits.cc \
                include/pgenlib_misc.cc \
                include/pgenlib_read.cc \
                include/pgenlib_write.cc

PLINK2LIB_CCSRC = $(PGENLIB_CCSRC) \
                  include/plink2_bgzf.cc \
                  include/plink2_bitmap.cc \
                  include/plink2_fmath.cc \
                  include/plink2_htable.cc \
                  include/plink2_memory.cc \
                  include/plink2_stats.cc \
                  include/plink2_string.cc \
                  include/plink2_text.cc \
                  include/plink2_thread.cc \
                  include/plink2_zstfile.cc

TEXTLIB_CCSRC = include/plink2_base.cc \
                include/plink2_bits.cc \
                include/plink2_bgzf.cc \
                include/plink2_htable.cc \
                include/plink2_memory.cc \
                include/plink2_string.cc \
                include/plink2_text.cc \
                include/plink2_thread.cc \
                include/plink2_zstfile.cc

CCSRC = $(PLINK2LIB_CCSRC) \
        plink2.cc \
        plink2_adjust.cc \
        plink2_cmdline.cc \
        plink2_common.cc \
        plink2_compress_stream.cc \
        plink2_data.cc \
        plink2_decompress.cc \
        plink2_export.cc \
        plink2_export_legacy.cc \
        plink2_family.cc \
        plink2_fasta.cc \
        plink2_filter.cc \
        plink2_glm.cc \
        plink2_glm_linear.cc \
        plink2_glm_logistic.cc \
        plink2_glm_shared.cc \
        plink2_help.cc \
        plink2_import.cc \
        plink2_import_legacy.cc \
        plink2_ld.cc \
        plink2_matrix.cc \
        plink2_matrix_calc.cc \
        plink2_merge.cc \
        plink2_misc.cc \
        plink2_psam.cc \
        plink2_pvar.cc \
        plink2_random.cc \
        plink2_set.cc

ZLIB_VER = 1.3.1

OBJ_NO_ZSTD = $(CSRC:.c=.o) $(CCSRC:.cc=.o)
OBJ = $(CSRC:.c=.o) $(ZCSRC:.c=.o) $(ZSSRC:.S=.o) $(CCSRC:.cc=.o)
PGENLIB_OBJ = $(PGENLIB_CCSRC:.cc=.o)
PLINK2LIB_OBJ = $(CSRC:.c=.o) $(ZCSRC:.c=.o) $(ZSSRC:.S=.o) $(PLINK2LIB_CCSRC:.cc=.o)
TEXTLIB_OBJ = $(CSRC:.c=.o) $(ZCSRC:.c=.o) $(ZSSRC:.S=.o) $(TEXTLIB_CCSRC:.cc=.o)
OBJL = $(notdir $(OBJ))
PGENLIB_OBJL = $(notdir $(PGENLIB_OBJ))
PLINK2LIB_OBJL = $(notdir $(PLINK2LIB_OBJ))
TEXTLIB_OBJL = $(notdir $(TEXTLIB_OBJ))

CSRC2 = $(foreach fname,$(CSRC),../$(fname))
ZCSRC2 = $(foreach fname,$(ZCSRC),../$(fname))
ZSSRC2 = $(foreach fname,$(ZSSRC),../$(fname))
CCSRC2 = $(foreach fname,$(CCSRC),../$(fname))
PGENLIB_CCSRC2 = $(foreach fname,$(PGENLIB_CCSRC),../$(fname))
PLINK2LIB_CCSRC2 = $(foreach fname,$(PLINK2LIB_CCSRC),../$(fname))
TEXTLIB_CCSRC2 = $(foreach fname,$(TEXTLIB_CCSRC),../$(fname))
OBJ2 = $(CSRC2:.c=.o) $(ZCSRC2:.c=.o) $(ZSSRC2:.S=.o) $(CCSRC2:.cc=.o)

CSRC3 = $(foreach fname,$(CSRC),../../$(fname))
ZCSRC3 = $(foreach fname,$(ZCSRC),../../$(fname))
ZSSRC3 = $(foreach fname,$(ZSSRC),../../$(fname))
CCSRC3 = $(foreach fname,$(CCSRC),../../$(fname))
PLINK2LIB_CCSRC3 = $(foreach fname,$(PLINK2LIB_CCSRC),../../$(fname))
TEXTLIB_CCSRC3 = $(foreach fname,$(TEXTLIB_CCSRC),../../$(fname))
OBJ3 = $(CSRC3:.c=.o) $(ZCSRC3:.c=.o) $(ZSSRC3:.S=.o) $(CCSRC3:.cc=.o)

CINCLUDE = -Ilibdeflate
CINCLUDE2 = -I../libdeflate
CINCLUDE3 = -I../../libdeflate
CXXINCLUDE = -Ilibdeflate "-I../zlib-"$(ZLIB_VER)
CXXINCLUDE2 = -I../libdeflate "-I../../zlib-"$(ZLIB_VER)
CXXINCLUDE3 = -I../../libdeflate "-I../../../zlib-"$(ZLIB_VER)
ZSTD_INCLUDE =
ZSTD_INCLUDE2 =
ZSTD_INCLUDE3 =

PGCSRC = $(PGENLIB_CCSRC) pgen_compress.cc
PGCOBJ = $(PGCSRC:.cc=.o)
PGCSRC2 = $(foreach fname,$(PGCSRC),../$(fname))

CLEAN = *.o \
        include/*.o \
        libdeflate/lib/*.o \
        libdeflate/lib/arm/*.o \
        libdeflate/lib/x86/*.o \
        zstd/lib/common/*.o \
        zstd/lib/compress/*.o \
        zstd/lib/decompress/*.o \
        pgenlibr/src/*.a \
        pgenlibr/src/*.o \
        pgenlibr/src/Makevars \
        pgenlibr/src/pgenlibr.so \
        utils/vcf_subset/*.o \
        bin/plink2 bin/pgen_compress
CLEAN2 = $(foreach expr,$(CLEAN),../$(expr))
