#Copyright inria / irisa (2013)
#
#
#raluca.uricaru@gmail.com
#pierre.peterlongo@inria.fr
#
#This software is a computer program whose purpose is to call SNPs from NGS reads.
#
#This software is governed by the CeCILL license under French law and
#abiding by the rules of distribution of free software.  You can  use,
#modify and/ or redistribute the software under the terms of the CeCILL
#license as circulated by CEA, CNRS and INRIA at the following URL
#"http:#www.cecill.info".
#
#As a counterpart to the access to the source code and  rights to copy,
#modify and redistribute granted by the license, users are provided only
#with a limited warranty  and the software's author,  the holder of the
#economic rights,  and the successive licensors  have only  limited
#liability.
#
#In this respect, the user's attention is drawn to the risks associated
#with loading,  using,  modifying and/or developing or reproducing the
#software by the user in light of its specific status of free software,
#that may mean  that it is complicated to manipulate,  and  that  also
#therefore means  that it is reserved for developers  and  experienced
#professionals having in-depth computer knowledge. Users are therefore
#encouraged to load and test the software's suitability as regards their
#requirements in conditions enabling the security of their systems and/or
#data to be ensured and,  more generally, to use and operate it in the
#same conditions as regards security.
#
#The fact that you are presently reading this means that you have had
#knowledge of the CeCILL license and that you accept its terms.

CC=g++
CFLAGS=  -O4 -lz -DMINIA_IS_IN_PARENT_FOLDER
#CFLAGS=  -O4 -lz -DMINIA_IS_IN_PARENT_FOLDER -DDONTMARK
SRC=../minia/Pool.cpp ../minia/Bank.cpp ../minia/Bloom.cpp ../minia/Hash16.cpp ../minia/Terminator.cpp ../minia/Kmer.cpp ../minia/Traversal.cpp ../minia/LinearCounter.cpp ../minia/Set.cpp ../minia/Utils.cpp ../minia/SortingCount.cpp ../minia/Debloom.cpp ../minia/OAHash.cpp Kmer_for_kissnp2.cpp SNP.cpp filter.cpp IterativeExtensions.cpp commons.cpp
EXEC=kissnp2
OBJ= $(SRC:.cpp=.o)
all: $(EXEC)

ifeq ($(prof),1)
 CFLAGS=-O3 -pg -lz
endif
ifeq ($(deb),1)
 CFLAGS+=-O0 -DASSERTS -g -lz 
endif

k := 0$(k) # dummy k if not specified 
K_BELOW_32 := $(shell echo $(k)\<=32 | bc)
K_BELOW_64 := $(shell echo $(k)\<=64 | bc)
ARCH := $(shell getconf LONG_BIT) # detects sizeof(int)
USING_UINT128 := 0

ifeq ($(K_BELOW_32),0)

    # use uint128 when k<=64 and 64-bit architecture
    ifeq ($(K_BELOW_64),1)
        ifeq ($ARCH),64)
            CFLAGS += -Dkmer_type=__uint128_t
            USING_UINT128 := 1
        endif
    endif
    
    # use a bigint library otherwise
    ifeq ($(USING_UINT128),0)
        ttmath := 1
    endif
endif

# ttmath is used when you type "make k=[kmer size]" with a kmer size longer than supported integer type,
# or when typing "make k=[anything] ttmath=1"
ifeq ($(ttmath),1)
    KMER_PRECISION := $(shell echo \($(k)+15\)/16 | bc)
    CFLAGS += -D_ttmath -DKMER_PRECISION=$(KMER_PRECISION)
endif

all: $(EXEC)

kissnp2:  $(OBJ) kissnp2.cpp
	$(CC) -o $@ $^ $(CFLAGS) 

%.o: %.cpp %.h
	$(CC) -o $@ -c $< $(CFLAGS)


%.o: %.c %.h 
	$(CC) -o $@ -c $< $(CFLAGS)
    
clean:
	rm -rf *.o ../minia/*.o
