CC=g++
EXEC=mapsembler_extend

#CFLAGS=  -O4 -lz
#CFLAGS=  -g  -lz
#CFLAGS=  -g  -lz
CFLAGS=  -O3  -lz
ifeq "$(CC)" "g++"
	empty:=
	space:= $(empty) $(empty)
	GCCVERSIONSTRING := $(shell expr `$(CC) -dumpversion`)
	#Create version number without "."
	GCCVERSION := $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f1 -d.)
	GCCVERSION += $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f2 -d.)
	GCCVERSION += $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f3 -d.)
	# Make sure the version number has at least 3 decimals
	GCCVERSION += 00
	# Remove spaces from the version number
	GCCVERSION := $(subst $(space),$(empty),$(GCCVERSION))
	# Crop the version number to 3 decimals.
	GCCVERSION := $(shell expr `echo $(GCCVERSION)` | cut -b1-3)

	INT_GCC_VERSION := $(shell expr `echo $(GCCVERSION)` \>= 470)

	ifeq "$(INT_GCC_VERSION)" "1"
    		CFLAGS += --std=c++11 -DMINIA_IS_IN_PARENT_FOLDER
	else
    		CFLAGS += --std=gnu++0x -DMINIA_IS_IN_PARENT_FOLDER
	endif
else	
	empty:=
	space:= $(empty) $(empty)
	CLANGVERSIONSTRING := $(shell expr `$(CC) -dumpversion`)
	#Create version number without "."
	CLANGVERSION := $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f1 -d.)
	CLANGVERSION += $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f2 -d.)
	CLANGVERSION += $(shell expr `echo $(GCCVERSIONSTRING)` | cut -f3 -d.)
	# Make sure the version number has at least 3 decimals
	CLANGVERSION += 00
	# Remove spaces from the version number
	CLANGVERSION := $(subst $(space),$(empty),$(GCCVERSION))
	# Crop the version number to 3 decimals.
	CLANGVERSION := $(shell expr `echo $(GCCVERSION)` | cut -b1-3)

	INT_CLANG_VERSION := $(shell expr `echo $(GCCVERSION)` \>= 360)

	ifeq "$(INT_CLANG_VERSION)" "1"
    		CFLAGS += --std=c++11 -DMINIA_IS_IN_PARENT_FOLDER
	else
    		CFLAGS += --std=gnu++0x -DMINIA_IS_IN_PARENT_FOLDER
	endif
endif

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 commons.cpp IterativeExtensions.cpp Fragment_Bank.cpp Fragment.cpp GraphOutput.cpp  
OBJ= $(SRC:.cpp=.o) 
all: $(EXEC)

ifeq ($(prof),1)
 CFLAGS+= -pg
endif

ifeq ($(unitig),1)
 CFLAGS+= -DUNITIG
endif


ifeq ($(deb),1)
 CFLAGS+= -O0 -DASSERTS -g
endif

ifeq ($(omp),1)
 CFLAGS=-O4  -fopenmp -DOMP=1
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_extend:  $(OBJ) $(OBJ2) mapsembler_extend.cpp
#mapsembler:  $(OBJ) $(OBJ2) test.cpp
	$(CC) -o $@ $^ $(CFLAGS) 

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


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