#CC=/opt/local/bin/g++-mp-4.7
CC=g++
EXEC=kissreads_graph
#Loader.cpp CFLAGS=  -g -lz -std=c++11 -DMINIA_IS_IN_PARENT_FOLDER
#Loader.cpp 
#CFLAGS=  -O3 -lz -DMINIA_IS_IN_PARENT_FOLDER
CFLAGS=  -g -lz -DMINIA_IS_IN_PARENT_FOLDER
SRC=block_allocator.cpp  DeBruijnGraph.cpp  Fragment.cpp  json.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 commons.cpp ../minia/Kmer.cpp ../minia/Bank.cpp Loader.cpp BooleanVector.cpp ReadMapper.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)

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

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



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