CC=g++ 
EXEC=mapsembler
#CFLAGS=  -O4 -lz --std=gnu++0x
CFLAGS=  -g -lz -DMINIA_IS_IN_PARENT_FOLDER
#CFLAGS=  -O3 -lz -DMINIA_IS_IN_PARENT_FOLDER
#CFLAGS=  -g -lz --std=gnu++0x -DMINIA_IS_IN_PARENT_FOLDER
#CFLAGS=  -g -lz -DMINIA_IS_IN_PARENT_FOLDER
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 Extension.cpp Extension_Bank.cpp Starter.cpp commons.cpp  read_coherence_mapsembler/libchash.cpp     read_coherence_mapsembler/couple.cpp  read_coherence_mapsembler/misc_tools.cpp    read_coherence_mapsembler/read_groups.cpp read_coherence_mapsembler/consensus_common.cpp  read_coherence_mapsembler/list.cpp    read_coherence_mapsembler/read_coherence.cpp  read_coherence_mapsembler/interface_libchash.cpp BooleanVector.cpp Starter_Bank.cpp IterativeExtensions.cpp Fragment_Bank.cpp Fragment.cpp GraphOutput.cpp  
OBJ= $(SRC:.cpp=.o) 
all: $(EXEC)

ifeq ($(prof),1)
 CFLAGS+=-O3 -pg
endif
ifeq ($(deb),1)
 CFLAGS+=-O0 -DASSERTS -g
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)

mapsembler:  $(OBJ) $(OBJ2) mapsembler.cpp
#mapsembler:  $(OBJ) $(OBJ2) test.cpp
	$(CC) -o $@ $^ $(CFLAGS) 

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


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