From 39eb541a6587c4ab4cb39ab283b2500b2dbf129f Mon Sep 17 00:00:00 2001 From: Artem Tarasov Date: Thu, 13 Nov 2014 01:12:04 +0300 Subject: [PATCH] static linking on os x --- .travis.yml | 8 ++------ Makefile | 19 +++++++++++++------ README.md | 10 ++-------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d0c48dd..738c0bc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,18 +10,14 @@ env: - secure: J1ta2/K8lj5dbHRvk+jTUAMICSnepfyc8ILCfM/HFCRaXMJQJTX1HDzEMwK3tAzzKaKEp9Tbm2b3IwE1tCtFaAfYUGozmHLirkFfKqCu/jNUkxL807M8NiqMx+H7tu2aR6t9opYyBjNhtuthbIdir3c42nldYdpse0ZLhzQTLfs= before_install: - - brew tap homebrew/science - - brew install htslib + - brew install ldc - git submodule update --init --recursive - - wget https://dl.dropboxusercontent.com/u/7916095/ldc2-0.13.0-osx-x86_64.tar.bz2 - - tar xjf ldc2-0.13.0-osx-x86_64.tar.bz2 - - export PATH=ldc2-0.13.0-osx-x86_64/bin:$PATH - wget https://github.com/craigcitro/r-travis/raw/master/scripts/dropbox.sh - chmod +x dropbox.sh - curl -L "https://dl.dropboxusercontent.com/u/7916095/shunit2-2.0.3.tgz" | tar zx script: - - make sambamba-ldmd2-64-osx + - make sambamba-ldmd2-64 - ./.run_tests.sh after_success: diff --git a/Makefile b/Makefile index b7fa6607..b4fd0065 100644 --- a/Makefile +++ b/Makefile @@ -5,30 +5,37 @@ HTSLIB_PATH=-Lhtslib HTSLIB_SUBCMD=$(HTSLIB_PATH) -Wl,-Bstatic -lhts -Wl,-Bdynamic RDMD_FLAGS=--force --build-only --compiler=$(D_COMPILER) $(D_FLAGS) +# Linux & DMD only - this goal is used because of fast compilation speed, during development all: htslib-static mkdir -p build/ rdmd --force --build-only $(D_FLAGS) -c -ofbuild/sambamba.o main.d gcc -Wl,--gc-sections -o build/sambamba build/sambamba.o $(HTSLIB_SUBCMD) -l:libphobos2.a -lrt -lpthread -lm +PLATFORM := $(shell uname -s) + +ifeq "$(PLATFORM)" "Darwin" +LINK_CMD=gcc -dead_strip -lphobos2-ldc -ldruntime-ldc -lm -lpthread htslib/libhts.a build/sambamba.o -o build/sambamba +else +LINK_CMD=gcc -Wl,--gc-sections -o build/sambamba build/sambamba.o $(HTSLIB_SUBCMD) -l:libphobos2-ldc.a -l:libdruntime-ldc.a -lrt -lpthread -lm +endif + +# This is the main Makefile goal, used for building releases (best performance) sambamba-ldmd2-64: htslib-static mkdir -p build/ ldmd2 @sambamba-ldmd-release.rsp - gcc -Wl,--gc-sections -o build/sambamba build/sambamba.o $(HTSLIB_SUBCMD) -l:libphobos2-ldc.a -l:libdruntime-ldc.a -lrt -lpthread -lm + $(LINK_CMD) +# For debugging; GDB & Valgrind are more friendly to executables created using LDC/GDC than DMD sambamba-ldmd2-debug: htslib-static mkdir -p build/ ldmd2 @sambamba-ldmd-debug.rsp - gcc -Wl,--gc-sections -o build/sambamba build/sambamba.o $(HTSLIB_SUBCMD) -l:libphobos2-ldc.a -l:libdruntime-ldc.a -lrt -lpthread -lm + $(LINK_CMD) htslib-static: cd htslib && $(MAKE) # all below link to libhts dynamically for simplicity -sambamba-ldmd2-64-osx: - mkdir -p build/ - rdmd --force --build-only --compiler=ldmd2 -IBioD -O -L-lhts -release -inline -noboundscheck -ofbuild/sambamba main.d - sambamba-flagstat: mkdir -p build/ rdmd $(RDMD_FLAGS) -L-lhts -version=standalone -ofbuild/sambamba-flagstat sambamba/flagstat.d diff --git a/README.md b/README.md index d124ff84..c7b49034 100644 --- a/README.md +++ b/README.md @@ -51,17 +51,11 @@ which targets LLVM. ## Compiling for Mac OS X -(The Dropbox archive differs from the official LDC release in that it also contains `rdmd` executable from DMD distribution.) - ```sh - brew tap homebrew/science - brew install htslib - wget https://dl.dropboxusercontent.com/u/7916095/ldc2-0.13.0-osx-x86_64.tar.bz2 - tar xjf ldc2-0.13.0-osx-x86_64.tar.bz2 + brew install ldc git clone --recursive https://github.com/lomereiter/sambamba.git cd sambamba - export PATH=../ldc2-0.13.0-osx-x86_64/bin:$PATH - make sambamba-ldmd2-64-osx + make sambamba-ldmd2-64 ``` ## Compiling for Linux using Docker