diff --git a/makefile b/makefile index 23e3001..1043290 100644 --- a/makefile +++ b/makefile @@ -1,10 +1,20 @@ SHELL = /bin/sh +OS := $(shell uname -s) +ARCH := $(shell uname -m) +MACHINE_ARCH := $(shell uname -p) -CC = clang++ -AR = ar -RANLIB = ranlib +ifeq ($(OS),Darwin) + LIBEXT = dylib +else + LIBEXT = so +endif -CFLAGS = -g -Wall +CC ?= clang +CXX ?= clang++ +AR ?= ar +RANLIB ?= ranlib + +CFLAGS ?= -g -Wall # Comment out CFLAGS line below for compatability mode for 32bit file sizes # (less than 2GB) and systems that have compilers that treat int as 64bit @@ -15,13 +25,21 @@ CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 CFLAGS += -O3 -fomit-frame-pointer -fstrict-aliasing -ffast-math # Comment out CFLAGS line below to disable AVX2 instruction set (performance will suffer) -CFLAGS += -mavx2 +ifneq (,$(filter x86_64 i686 i386,$(ARCH))) + CFLAGS += -mavx2 +endif # Comment out CFLAGS line below to disable OpenMP optimizations -CFLAGS += -fopenmp -DLIBBSC_OPENMP_SUPPORT +OPENMP ?= 0 +ifneq (,$(filter 1 true yes,$(OPENMP))) + CFLAGS += -fopenmp -DLIBBSC_OPENMP_SUPPORT +endif # Comment out CFLAGS line below to enable debug output -CFLAGS += -DNDEBUG +DEBUG ?= 0 +ifneq (,$(filter 0 false no,$(DEBUG))) + CFLAGS += -DNDEBUG +endif # Comment out CFLAGS line below to disable Sort Transform CFLAGS += -DLIBBSC_SORT_TRANSFORM_SUPPORT @@ -30,7 +48,18 @@ CFLAGS += -DLIBBSC_SORT_TRANSFORM_SUPPORT CFLAGS += -DLIBBSC_ALLOW_UNALIGNED_ACCESS # Where you want bsc installed when you do 'make install' -PREFIX = /usr +PREFIX ?= /usr + +NATIVE ?= 0 +ifneq (,$(filter 1 true yes,$(NATIVE))) + ifneq (,$(filter arm% aarch64,$(ARCH))) + CFLAGS += -mcpu=native + else ifneq (,$(filter powerpc,$(MACHINE_ARCH))) + CFLAGS += -mtune=native + else + CFLAGS += -march=native + endif +endif OBJS = \ adler32.o \ @@ -46,21 +75,25 @@ OBJS = \ st.o \ bwt.o \ -all: libbsc.a bsc +all: libbsc.a bsc libbsc.$(LIBEXT) bsc: libbsc.a bsc.cpp - $(CC) $(CFLAGS) bsc.cpp -o bsc -L. -lbsc + $(CXX) $(CFLAGS) $(LDFLAGS) bsc.cpp -o $@ $< libbsc.a: $(OBJS) - rm -f libbsc.a - $(AR) cq libbsc.a $(OBJS) + rm -f $@ + $(AR) cq $@ $(OBJS) @if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \ -f /bin/ranlib -o -f /usr/ccs/bin/ranlib ) ; then \ - echo $(RANLIB) libbsc.a ; \ - $(RANLIB) libbsc.a ; \ + echo $(RANLIB) $@ ; \ + $(RANLIB) $@ ; \ fi -install: libbsc.a bsc +libbsc.$(LIBEXT): $(OBJS) + rm -f $@ + $(CC) $(CFLAGS) -fPIC -shared $(LDFLAGS) -o $@ $(OBJS) + +install: libbsc.a bsc libbsc.$(LIBEXT) if ( test ! -d $(DESTDIR)$(PREFIX)/bin ) ; then mkdir -p $(DESTDIR)$(PREFIX)/bin ; fi if ( test ! -d $(DESTDIR)$(PREFIX)/lib ) ; then mkdir -p $(DESTDIR)$(PREFIX)/lib ; fi if ( test ! -d $(DESTDIR)$(PREFIX)/include ) ; then mkdir -p $(DESTDIR)$(PREFIX)/include ; fi @@ -70,42 +103,44 @@ install: libbsc.a bsc chmod a+r $(DESTDIR)$(PREFIX)/include/libbsc.h cp -f libbsc.a $(DESTDIR)$(PREFIX)/lib chmod a+r $(DESTDIR)$(PREFIX)/lib/libbsc.a + cp -f libbsc.$(LIBEXT) $(DESTDIR)$(PREFIX)/lib + chmod a+r $(DESTDIR)$(PREFIX)/lib/libbsc.$(LIBEXT) clean: - rm -f *.o libbsc.a bsc + rm -rf *.o libbsc.a libbsc.$(LIBEXT) bsc bsc.dSYM adler32.o: libbsc/adler32/adler32.cpp - $(CC) $(CFLAGS) -c libbsc/adler32/adler32.cpp + $(CXX) $(CFLAGS) -c libbsc/adler32/adler32.cpp libsais.o: libbsc/bwt/libsais/libsais.c $(CC) $(CFLAGS) -c libbsc/bwt/libsais/libsais.c coder.o: libbsc/coder/coder.cpp - $(CC) $(CFLAGS) -c libbsc/coder/coder.cpp + $(CXX) $(CFLAGS) -c libbsc/coder/coder.cpp qlfc.o: libbsc/coder/qlfc/qlfc.cpp - $(CC) $(CFLAGS) -c libbsc/coder/qlfc/qlfc.cpp + $(CXX) $(CFLAGS) -c libbsc/coder/qlfc/qlfc.cpp qlfc_model.o: libbsc/coder/qlfc/qlfc_model.cpp - $(CC) $(CFLAGS) -c libbsc/coder/qlfc/qlfc_model.cpp + $(CXX) $(CFLAGS) -c libbsc/coder/qlfc/qlfc_model.cpp detectors.o: libbsc/filters/detectors.cpp - $(CC) $(CFLAGS) -c libbsc/filters/detectors.cpp + $(CXX) $(CFLAGS) -c libbsc/filters/detectors.cpp preprocessing.o: libbsc/filters/preprocessing.cpp - $(CC) $(CFLAGS) -c libbsc/filters/preprocessing.cpp + $(CXX) $(CFLAGS) -c libbsc/filters/preprocessing.cpp libbsc.o: libbsc/libbsc/libbsc.cpp - $(CC) $(CFLAGS) -c libbsc/libbsc/libbsc.cpp + $(CXX) $(CFLAGS) -c libbsc/libbsc/libbsc.cpp lzp.o: libbsc/lzp/lzp.cpp - $(CC) $(CFLAGS) -c libbsc/lzp/lzp.cpp + $(CXX) $(CFLAGS) -c libbsc/lzp/lzp.cpp platform.o: libbsc/platform/platform.cpp - $(CC) $(CFLAGS) -c libbsc/platform/platform.cpp + $(CXX) $(CFLAGS) -c libbsc/platform/platform.cpp st.o: libbsc/st/st.cpp - $(CC) $(CFLAGS) -c libbsc/st/st.cpp + $(CXX) $(CFLAGS) -c libbsc/st/st.cpp bwt.o: libbsc/bwt/bwt.cpp - $(CC) $(CFLAGS) -c libbsc/bwt/bwt.cpp + $(CXX) $(CFLAGS) -c libbsc/bwt/bwt.cpp