<commit_before>DEP_DIR:=./deps
SRC_DIR:=src
ALGORITHMS_SRC_DIR:=$(SRC_DIR)/algorithms
IO_SRC_DIR:=$(SRC_DIR)/io
SUBCOMMAND_SRC_DIR:=$(SRC_DIR)/subcommand
UNITTEST_SRC_DIR:=$(SRC_DIR)/unittest
BIN_DIR:=bin
OBJ_DIR:=obj
ALGORITHMS_OBJ_DIR:=$(OBJ_DIR)/algorithms
IO_OBJ_DIR:=$(OBJ_DIR)/io
SUBCOMMAND_OBJ_DIR:=$(OBJ_DIR)/subcommand
UNITTEST_OBJ_DIR:=$(OBJ_DIR)/unittest
LIB_DIR:=lib
# INC_DIR must be a relative path
INC_DIR:=include
CWD:=$(shell pwd)
CXX ?= g++

EXE:=vg

all: $(BIN_DIR)/$(EXE)

# Magic dependencies (see <http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr>)
include $(wildcard $(OBJ_DIR)/*.d)
include $(wildcard $(ALGORITHMS_OBJ_DIR)/*.d)
include $(wildcard $(IO_OBJ_DIR)/*.d)
include $(wildcard $(SUBCOMMAND_OBJ_DIR)/*.d)
include $(wildcard $(UNITTEST_OBJ_DIR)/*.d)

# We don't ask for -fopenmp here because how we get it can depend on the compiler.
CXXFLAGS := -O3 -Werror=return-type -std=c++14 -ggdb -g -MMD -MP -msse4.2 $(CXXFLAGS)

# Set include flags. All -I options need to go in here, so the first directory listed is genuinely searched first.
INCLUDE_FLAGS:=-I$(CWD)/$(INC_DIR) -I. -I$(CWD)/$(SRC_DIR) -I$(CWD)/$(UNITTEST_SRC_DIR) -I$(CWD)/$(SUBCOMMAND_SRC_DIR) -I$(CWD)/$(INC_DIR)/dynamic -I$(CWD)/$(INC_DIR)/sonLib $(shell pkg-config --cflags cairo jansson)

# Define libraries to link against. Make sure to always link statically against
# htslib and libdeflate and Protobuf so that we can use position-dependent code
# there for speed.
LD_LIB_FLAGS:= -L$(CWD)/$(LIB_DIR) $(CWD)/$(LIB_DIR)/libvgio.a -lxg -lhandlegraph -lvcflib -lgssw -lssw $(CWD)/$(LIB_DIR)/libprotobuf.a -lsublinearLS $(CWD)/$(LIB_DIR)/libhts.a $(CWD)/$(LIB_DIR)/libdeflate.a -lpthread -ljansson -lncurses -lgcsa2 -lgbwt -ldivsufsort -ldivsufsort64 -lvcfh -lraptor2 -lsdsl -lpinchesandcacti -l3edgeconnected -lsonlib -lfml -llz4 -lstructures -lvw -lboost_program_options -lallreduce -lbdsg -latomic
# Use pkg-config to find Cairo and all the libs it uses
LD_LIB_FLAGS += $(shell pkg-config --libs --static cairo jansson)


ifeq ($(shell uname -s),Darwin)
    # We may need libraries from Macports
    # TODO: where does Homebrew keep libraries?
    ifeq ($(shell if [ -d /opt/local/lib ];then echo 1;else echo 0;fi), 1)
        # Use /opt/local/lib if present
        LD_LIB_FLAGS += -L/opt/local/lib
    endif

    ifeq ($(shell if [ -d /usr/local/lib ];then echo 1;else echo 0;fi), 1)
        # Use /usr/local/lib if present.
        LD_LIB_FLAGS += -L/usr/local/lib
    endif
    
    ifeq ($(shell if [ -d /usr/local/include ];then echo 1;else echo 0;fi), 1)
        # Use /usr/local/include to the end of the include search path.
        INCLUDE_FLAGS += -I /usr/local/include

        ifeq ($(shell if [ -d /usr/local/include/cairo ];then echo 1;else echo 0;fi), 1)	
            # pkg-config is not always smart enough to find Cairo's include path for us.
            # We make sure to grab its directory manually if we see it.
            INCLUDE_FLAGS += -I /usr/local/include/cairo
            LD_LIB_FLAGS += -lcairo
        endif
    endif

    # Our compiler might be clang that lacks -fopenmp support.
    # Sniff that
    ifeq ($(strip $(shell $(CXX) -fopenmp /dev/null -o/dev/null 2>&1 | grep fopenmp | wc -l)), 1)
        # The compiler complained about fopenmp instead of its nonsense input file.
        # We need to use the hard way of getting OpenMP not bundled with the compiler.
        # The compiler only needs to do the preprocessing
        CXXFLAGS += -Xpreprocessor -fopenmp

        ifeq ($(shell if [ -d /opt/local/lib/libomp ];then echo 1;else echo 0;fi), 1)
            # Use /opt/local/lib/libomp if present, because Macports installs libomp there.
            # Brew is supposed to put it somewhere the compiler can find it by default.
            LD_LIB_FLAGS += -L/opt/local/lib/libomp
            # And we need to find the includes. Homebrew puts them in the normal place
            # but Macports hides them in "libomp"
            INCLUDE_FLAGS += -I/opt/local/include/libomp
        endif

        # We also need to link it
        LD_LIB_FLAGS += -lomp
        # And we need to find the includes. Homebrew puts them in the normal place but macports hides them in "libomp"
        INCLUDE_FLAGS += -I/opt/local/include/libomp
    else
        CXXFLAGS += -fopenmp
    endif
	
    # Note shared libraries are dylibs
    SHARED_SUFFIX = dylib
    
    # Define options to start and end static linking of libraries.
	# We don't actually do any static linking on Mac, so we leave these empty.
    START_STATIC =
    END_STATIC =

else
    # We are not running on OS X
    # We can also have a normal Unix rpath
    LD_LIB_FLAGS += -Wl,-rpath,$(CWD)/$(LIB_DIR)
    # Make sure to allow backtrace access to all our symbols, even those which are not exported.
    # Absolutely no help in a static build.
    LD_LIB_FLAGS += -rdynamic

    # We want to link against the elfutils libraries
    LD_LIB_FLAGS += -ldwfl -ldw -ldwelf -lelf -lebl

    # We get OpenMP the normal way, using whatever the compiler knows about
    CXXFLAGS += -fopenmp
	
    # Note shared libraries are so files
    SHARED_SUFFIX = so
    
	# Define options to start and end static linking of libraries on GNU ld
    START_STATIC = -Wl,-Bstatic
    END_STATIC = -Wl,-Bdynamic
	<commit_msg>add back -latomic, but only on macs that dont complain about it<commit_after>DEP_DIR:=./deps
SRC_DIR:=src
ALGORITHMS_SRC_DIR:=$(SRC_DIR)/algorithms
IO_SRC_DIR:=$(SRC_DIR)/io
SUBCOMMAND_SRC_DIR:=$(SRC_DIR)/subcommand
UNITTEST_SRC_DIR:=$(SRC_DIR)/unittest
BIN_DIR:=bin
OBJ_DIR:=obj
ALGORITHMS_OBJ_DIR:=$(OBJ_DIR)/algorithms
IO_OBJ_DIR:=$(OBJ_DIR)/io
SUBCOMMAND_OBJ_DIR:=$(OBJ_DIR)/subcommand
UNITTEST_OBJ_DIR:=$(OBJ_DIR)/unittest
LIB_DIR:=lib
# INC_DIR must be a relative path
INC_DIR:=include
CWD:=$(shell pwd)
CXX ?= g++

EXE:=vg

all: $(BIN_DIR)/$(EXE)

# Magic dependencies (see <http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr>)
include $(wildcard $(OBJ_DIR)/*.d)
include $(wildcard $(ALGORITHMS_OBJ_DIR)/*.d)
include $(wildcard $(IO_OBJ_DIR)/*.d)
include $(wildcard $(SUBCOMMAND_OBJ_DIR)/*.d)
include $(wildcard $(UNITTEST_OBJ_DIR)/*.d)

# We don't ask for -fopenmp here because how we get it can depend on the compiler.
CXXFLAGS := -O3 -Werror=return-type -std=c++14 -ggdb -g -MMD -MP -msse4.2 $(CXXFLAGS)

# Set include flags. All -I options need to go in here, so the first directory listed is genuinely searched first.
INCLUDE_FLAGS:=-I$(CWD)/$(INC_DIR) -I. -I$(CWD)/$(SRC_DIR) -I$(CWD)/$(UNITTEST_SRC_DIR) -I$(CWD)/$(SUBCOMMAND_SRC_DIR) -I$(CWD)/$(INC_DIR)/dynamic -I$(CWD)/$(INC_DIR)/sonLib $(shell pkg-config --cflags cairo jansson)

# Define libraries to link against. Make sure to always link statically against
# htslib and libdeflate and Protobuf so that we can use position-dependent code
# there for speed.
LD_LIB_FLAGS:= -L$(CWD)/$(LIB_DIR) $(CWD)/$(LIB_DIR)/libvgio.a -lxg -lhandlegraph -lvcflib -lgssw -lssw $(CWD)/$(LIB_DIR)/libprotobuf.a -lsublinearLS $(CWD)/$(LIB_DIR)/libhts.a $(CWD)/$(LIB_DIR)/libdeflate.a -lpthread -ljansson -lncurses -lgcsa2 -lgbwt -ldivsufsort -ldivsufsort64 -lvcfh -lraptor2 -lsdsl -lpinchesandcacti -l3edgeconnected -lsonlib -lfml -llz4 -lstructures -lvw -lboost_program_options -lallreduce -lbdsg -latomic
# Use pkg-config to find Cairo and all the libs it uses
LD_LIB_FLAGS += $(shell pkg-config --libs --static cairo jansson)


ifeq ($(shell uname -s),Darwin)
    # We may need libraries from Macports
    # TODO: where does Homebrew keep libraries?
    ifeq ($(shell if [ -d /opt/local/lib ];then echo 1;else echo 0;fi), 1)
        # Use /opt/local/lib if present
        LD_LIB_FLAGS += -L/opt/local/lib
    endif

    ifeq ($(shell if [ -d /usr/local/lib ];then echo 1;else echo 0;fi), 1)
        # Use /usr/local/lib if present.
        LD_LIB_FLAGS += -L/usr/local/lib
    endif
    
    ifeq ($(shell if [ -d /usr/local/include ];then echo 1;else echo 0;fi), 1)
        # Use /usr/local/include to the end of the include search path.
        INCLUDE_FLAGS += -I /usr/local/include

        ifeq ($(shell if [ -d /usr/local/include/cairo ];then echo 1;else echo 0;fi), 1)	
            # pkg-config is not always smart enough to find Cairo's include path for us.
            # We make sure to grab its directory manually if we see it.
            INCLUDE_FLAGS += -I /usr/local/include/cairo
            LD_LIB_FLAGS += -lcairo
        endif
    endif

    # Our compiler might be clang that lacks -fopenmp support.
    # Sniff that
    ifeq ($(strip $(shell $(CXX) -fopenmp /dev/null -o/dev/null 2>&1 | grep fopenmp | wc -l)), 1)
        # The compiler complained about fopenmp instead of its nonsense input file.
        # We need to use the hard way of getting OpenMP not bundled with the compiler.
        # The compiler only needs to do the preprocessing
        CXXFLAGS += -Xpreprocessor -fopenmp

        ifeq ($(shell if [ -d /opt/local/lib/libomp ];then echo 1;else echo 0;fi), 1)
            # Use /opt/local/lib/libomp if present, because Macports installs libomp there.
            # Brew is supposed to put it somewhere the compiler can find it by default.
            LD_LIB_FLAGS += -L/opt/local/lib/libomp
            # And we need to find the includes. Homebrew puts them in the normal place
            # but Macports hides them in "libomp"
            INCLUDE_FLAGS += -I/opt/local/include/libomp
        endif

        # We also need to link it
        LD_LIB_FLAGS += -lomp
        # And we need to find the includes. Homebrew puts them in the normal place but macports hides them in "libomp"
        INCLUDE_FLAGS += -I/opt/local/include/libomp
    else
        CXXFLAGS += -fopenmp
    endif

    # Travis needs -latomic for the GCC build on Mac, but this flag seems to break every other build
    ifeq ($(strip $(shell $(CXX) -latomic /dev/null -o/dev/null 2>&1 | grep latomic | wc -l)), 0)
        # We're on Mac and the compiler doesn't complain about latomic, so use it
        LD_LIB_FLAGS += -latomic
    endif
	
    # Note shared libraries are dylibs
    SHARED_SUFFIX = dylib
    
    # Define options to start and end static linking of libraries.
	# We don't actually do any static linking on Mac, so we leave these empty.
    START_STATIC =
    END_STATIC =

else
    # We are not running on OS X
    # We can also have a normal Unix rpath
    LD_LIB_FLAGS += -Wl,-rpath,$(CWD)/$(LIB_DIR)
    # Make sure to allow backtrace access to all our symbols, even those which are not exported.
    # Absolutely no help in a static build.
    LD_LIB_FLAGS += -rdynamic

    # We want to link against the elfutils libraries
    LD_LIB_FLAGS += -ldwfl -ldw -ldwelf -lelf -lebl

    # We get OpenMP the normal way, using whatever the compiler knows about
    CXXFLAGS += -fopenmp
	
    # Note shared libraries are so files
    SHARED_SUFFIX = so
    
	# Define options to start and end static linking of libraries on GNU ld
    START_STATIC = -Wl,-Bstatic
    END_STATIC = -Wl,-Bdynamic
	
{'fraction_non_alphanumeric': 0.11246255786511755, 'fraction_numerical': 0.0055368975220114365, 'mean_word_length': 3.022635998539613, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '27134', 'n_tokens_mistral': 3931, 'n_tokens_neox': 3651, 'n_words': 1226}