From: Michael R. Crusoe <crusoe@debian.org>
Subject: Enable cross building
Forwarded: https://github.com/benedictpaten/sonLib/pull/41
Forwarded: https://github.com/yoheirosen/sublinear-Li-Stephens/pull/7
Forwarded: https://github.com/benedictpaten/sonLib/pull/42
Forwarded: https://github.com/vgteam/cpp_progress_bar/pull/2
Forwarded: https://github.com/vgteam/gfakluge/pull/6

--- vg.orig/source_me.sh
+++ vg/source_me.sh
@@ -9,8 +9,8 @@
 export CFLAGS="-I $(pwd)/include ${CFLAGS}"
 export CXXFLAGS="-I $(pwd)/include -I$(pwd)/include/dynamic ${CXXFLAGS}"
 export PATH=`pwd`/bin:`pwd`/scripts:$PATH
-export CC=$(which gcc)
-export CXX=$(which g++)
+export CC="${CC:=gcc}"
+export CXX="${CXX:=g++}"
 
 #
 #  disable until file arguments work as in normal bash :(
--- vg.orig/deps/sonLib/include.mk
+++ vg/deps/sonLib/include.mk
@@ -3,6 +3,7 @@
 MACH = $(shell uname -m)
 SYS =  $(shell uname -s)
 
+CC ?= gcc
 #C compiler. FIXME: for some reason the cxx variable is used, which
 #typically means C++ compiler.
 ifeq (${CC},cc)
@@ -13,7 +14,7 @@
   else ifeq ($(SYS),Darwin) #This is to deal with the Mavericks replacing gcc with clang fully
 	cxx = clang -std=c99 
   else
-    cxx = gcc -std=c99
+    cxx = ${CC} -std=c99
   endif
 else
   cxx = ${CC} -std=c99
--- vg.orig/Makefile
+++ vg/Makefile
@@ -1,3 +1,4 @@
+PKG_CONFIG ?= pkg-config
 DEP_DIR:=./deps
 SRC_DIR:=src
 ALGORITHMS_SRC_DIR:=$(SRC_DIR)/algorithms
@@ -49,11 +50,11 @@
 # necessary on all platforms and suppresses warnings.
 # Also, pkg-config flags need to be made -isystem if our dependency install
 # directory is, or they might put a system HTSlib before ours.
-INCLUDE_FLAGS :=$(shell pkg-config --cflags libfastahack) $(shell pkg-config --cflags libsmithwaterman) $(shell pkg-config --cflags libvcflib) -I$(CWD)/$(INC_DIR) -isystem $(CWD)/$(INC_DIR) -I. -I$(CWD)/$(SRC_DIR) -I$(CWD)/$(UNITTEST_SRC_DIR) -I$(CWD)/$(SUBCOMMAND_SRC_DIR) -I$(CWD)/$(INC_DIR)/dynamic $(shell $(PKG_CONFIG) --cflags $(PKG_CONFIG_DEPS) $(PKG_CONFIG_STATIC_DEPS) | sed 's/ -I/ -isystem /g')
+INCLUDE_FLAGS :=$(shell $(PKG_CONFIG) --cflags libfastahack) $(shell $(PKG_CONFIG) --cflags libsmithwaterman) $(shell $(PKG_CONFIG) --cflags libvcflib) -I$(CWD)/$(INC_DIR) -isystem $(CWD)/$(INC_DIR) -I. -I$(CWD)/$(SRC_DIR) -I$(CWD)/$(UNITTEST_SRC_DIR) -I$(CWD)/$(SUBCOMMAND_SRC_DIR) -I$(CWD)/$(INC_DIR)/dynamic $(shell $(PKG_CONFIG) --cflags $(PKG_CONFIG_DEPS) $(PKG_CONFIG_STATIC_DEPS) | sed 's/ -I/ -isystem /g')
 
 # Define libraries to link against.
 LD_LIB_DIR_FLAGS := -L$(CWD)/$(LIB_DIR)
-LD_LIB_FLAGS := $(CWD)/$(LIB_DIR)/libvgio.a -lz -lvcflib -lgssw -lssw -lsublinearLS -lpthread -lncurses -lgcsa2 -lgbwtgraph -lgbwt -ldivsufsort -ldivsufsort64 -lraptor2 -lpinchesandcacti -l3edgeconnected -lsonlib -lfml -lstructures -lvw -lallreduce -lbdsg -lxg -lsdsl -lhandlegraph $(shell pkg-config --libs libfastahack) $(shell pkg-config --libs libsmithwaterman) $(shell pkg-config --libs libvcflib) $(shell pkg-config --libs htslib) -ltabixpp
+LD_LIB_FLAGS := $(CWD)/$(LIB_DIR)/libvgio.a -lz -lvcflib -lgssw -lssw -lsublinearLS -lpthread -lncurses -lgcsa2 -lgbwtgraph -lgbwt -ldivsufsort -ldivsufsort64 -lraptor2 -lpinchesandcacti -l3edgeconnected -lsonlib -lfml -lstructures -lvw -lallreduce -lbdsg -lxg -lsdsl -lhandlegraph $(shell $(PKG_CONFIG) --libs libfastahack) $(shell $(PKG_CONFIG) --libs libsmithwaterman) $(shell $(PKG_CONFIG) --libs libvcflib) $(shell $(PKG_CONFIG) --libs htslib) -ltabixpp
 # We omit Boost Program Options for now; we find it in a platform-dependent way.
 # By default it has no suffix
 BOOST_SUFFIX=""
@@ -460,7 +461,7 @@
 $(INC_DIR)/dynamic/dynamic.hpp: $(DYNAMIC_DIR)/include/*.hpp $(DYNAMIC_DIR)/include/internal/*.hpp
 	rm -Rf $(INC_DIR)/dynamic.hpp $(INC_DIR)/dynamic
 	# annoyingly doesn't have an install option on the cmake, so we manually move their external dependency headers
-	cd $(CWD)/$(DYNAMIC_DIR) && rm -Rf build && mkdir -p build && cd build && export CXXFLAGS="$(CPPFLAGS) $(CXXFLAGS)" && cmake -DCMAKE_VERBOSE_MAKEFILE=ON .. && make
+	cd $(CWD)/$(DYNAMIC_DIR) && rm -Rf build && mkdir -p build && cd build && export CXXFLAGS="$(CPPFLAGS) $(CXXFLAGS)" && cmake -DCMAKE_VERBOSE_MAKEFILE=ON .. && $(MAKE)
 	# Do the copy of the main file last so we can tell if this recipe failed and redo it.
 	# Otherwise we get dynamic.hpp without its deps
 	mkdir -p $(INC_DIR)/dynamic && cp -r $(CWD)/$(DYNAMIC_DIR)/include/* $(INC_DIR)/dynamic
--- vg.orig/deps/progress_bar/makefile
+++ vg/deps/progress_bar/makefile
@@ -1,4 +1,4 @@
-CC = g++
+CXX ?= g++
 CPPFLAGS += -std=c++11
 TARGET = progress_bar
 OBJ = main.o progress_bar.o
@@ -6,16 +6,13 @@
 all : progress_bar
 
 progress_bar : $(OBJ)
-	@echo "<***Linking***> $@"
-	@$(CC) $(CPPFLAGS) $(OBJ) -o $(TARGET)
+	$(CXX) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(OBJ) -o $(TARGET) $(LOADLIBES) $(LDLIBS)
 
 main.o : main.cpp
-	@echo "<**Compiling**> $@"
-	@$(CC) $(CPPFLAGS) -c $^
+	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $^
 
 progress_bar.o : progress_bar.cpp
-	@echo "<**Compiling**> $@"
-	@$(CC) $(CPPFLAGS) -c $^
+	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $^
 
 clean :
 	@rm -rf progress_bar $(OBJ)

