--- samtools-1.2/Makefile.orig	2015-02-03 17:27:34.000000000 +0100
+++ samtools-1.2/Makefile	2015-03-19 11:19:38.289234982 +0100
@@ -21,9 +21,7 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
-CC       = gcc
 CPPFLAGS = $(DFLAGS) $(INCLUDES)
-CFLAGS   = -g -Wall -O2
 LDFLAGS  =
 LDLIBS   =
 DFLAGS=     -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_CURSES_LIB=1
@@ -36,9 +34,9 @@
             cut_target.o phase.o bam2depth.o padding.o bedcov.o bamshuf.o \
             faidx.o stats.o stats_isize.o bam_flags.o bam_split.o \
             bam_tview.o bam_tview_curses.o bam_tview_html.o bam_lpileup.o
-INCLUDES=   -I. -I$(HTSDIR)
-LIBCURSES=  -lcurses # -lXCurses
-
+INCLUDES=   -I$(EBROOTNCURSES)/include -I$(EBROOTZLIB)/include -I. -I$(EBROOTHTSLIB)/include
+LIBCURSES=  -L$(EBROOTNCURSES)/lib -lcurses # -lXCurses
+ZLIB=		-L$(EBROOTZLIB)/lib -lz
 prefix      = /usr/local
 exec_prefix = $(prefix)
 bindir      = $(exec_prefix)/bin
@@ -82,10 +80,9 @@
 
 
 # Adjust $(HTSDIR) to point to your top-level htslib directory
-HTSDIR = htslib-1.2.1
-include $(HTSDIR)/htslib.mk
-HTSLIB = $(HTSDIR)/libhts.a
-BGZIP  = $(HTSDIR)/bgzip
+HTSDIR = $(EBROOTHTSLIB)/include
+HTSLIB = $(EBROOTHTSLIB)/lib/libhts.a
+BGZIP  = $(EBROOTHTSLIB)/bin/bgzip
 
 
 PACKAGE_VERSION = 1.2
@@ -122,7 +119,7 @@
 	$(AR) -csru $@ $(LOBJS)
 
 samtools: $(AOBJS) libbam.a $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ $(AOBJS) libbam.a $(HTSLIB) $(LDLIBS) $(LIBCURSES) -lm -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ $(AOBJS) libbam.a $(HTSLIB) $(LDLIBS) $(LIBCURSES) -lm $(ZLIB)
 
 bam_h = bam.h $(htslib_bgzf_h) $(htslib_sam_h)
 bam2bcf_h = bam2bcf.h $(htslib_vcf_h) errmod.h
@@ -192,31 +189,31 @@
 
 
 test/merge/test_bam_translate: test/merge/test_bam_translate.o test/test.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/merge/test_bam_translate.o test/test.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/merge/test_bam_translate.o test/test.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test/merge/test_pretty_header: test/merge/test_pretty_header.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/merge/test_pretty_header.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/merge/test_pretty_header.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test/merge/test_rtrans_build: test/merge/test_rtrans_build.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/merge/test_rtrans_build.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/merge/test_rtrans_build.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test/merge/test_trans_tbl_init: test/merge/test_trans_tbl_init.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/merge/test_trans_tbl_init.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/merge/test_trans_tbl_init.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test/split/test_count_rg: test/split/test_count_rg.o test/test.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/split/test_count_rg.o test/test.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/split/test_count_rg.o test/test.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test/split/test_expand_format_string: test/split/test_expand_format_string.o test/test.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/split/test_expand_format_string.o test/test.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/split/test_expand_format_string.o test/test.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test/split/test_filter_header_rg: test/split/test_filter_header_rg.o test/test.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/split/test_filter_header_rg.o test/test.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/split/test_filter_header_rg.o test/test.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test/split/test_parse_args: test/split/test_parse_args.o test/test.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/split/test_parse_args.o test/test.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/split/test_parse_args.o test/test.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test/vcf-miniview: test/vcf-miniview.o $(HTSLIB)
-	$(CC) -pthread $(LDFLAGS) -o $@ test/vcf-miniview.o $(HTSLIB) $(LDLIBS) -lz
+	$(CC) -pthread $(LDFLAGS) -o $@ test/vcf-miniview.o $(HTSLIB) $(LDLIBS) $(ZLIB)
 
 test_test_h = test/test.h $(htslib_sam_h)
 
@@ -235,22 +232,22 @@
 # misc programs
 
 misc/ace2sam: misc/ace2sam.o
-	$(CC) $(LDFLAGS) -o $@ misc/ace2sam.o $(LDLIBS) -lz
+	$(CC) $(LDFLAGS) -o $@ misc/ace2sam.o $(LDLIBS) $(ZLIB)
 
 misc/maq2sam-short: misc/maq2sam-short.o
-	$(CC) $(LDFLAGS) -o $@ misc/maq2sam-short.o $(LDLIBS) -lz
+	$(CC) $(LDFLAGS) -o $@ misc/maq2sam-short.o $(LDLIBS) $(ZLIB)
 
 misc/maq2sam-long: misc/maq2sam-long.o
-	$(CC) $(LDFLAGS) -o $@ misc/maq2sam-long.o $(LDLIBS) -lz
+	$(CC) $(LDFLAGS) -o $@ misc/maq2sam-long.o $(LDLIBS) $(ZLIB)
 
 misc/md5fa: misc/md5fa.o misc/md5.o
-	$(CC) $(LDFLAGS) -o $@ misc/md5fa.o misc/md5.o $(LDLIBS) -lz
+	$(CC) $(LDFLAGS) -o $@ misc/md5fa.o misc/md5.o $(LDLIBS) $(ZLIB)
 
 misc/md5sum-lite: misc/md5sum-lite.o
 	$(CC) $(LDFLAGS) -o $@ misc/md5sum-lite.o $(LDLIBS)
 
 misc/wgsim: misc/wgsim.o
-	$(CC) $(LDFLAGS) -o $@ misc/wgsim.o $(LDLIBS) -lm -lz
+	$(CC) $(LDFLAGS) -o $@ misc/wgsim.o $(LDLIBS) -lm $(ZLIB)
 
 misc/ace2sam.o: misc/ace2sam.c $(HTSDIR)/htslib/kstring.h $(HTSDIR)/htslib/kseq.h
 misc/md5.o: misc/md5.c misc/md5.h
