diff --git a/Makefile.am b/Makefile.am index a843f1d..5788ca8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,6 +18,7 @@ unit_tests_extra= perf_tests_extra= examples= other_tests= +lsrc_x86_64= lsrc32= unit_tests32= perf_tests32= @@ -37,6 +38,19 @@ LIBISAL_AGE=0 lib_LTLIBRARIES = libisal.la pkginclude_HEADERS += $(sort ${extern_hdrs}) libisal_la_SOURCES = ${lsrc} + +if CPU_X86_64 +libisal_la_SOURCES += ${lsrc_x86_64} +endif + +if CPU_X86_32 +libisal_la_SOURCES += ${lsrc_x86_32} +endif + +if CPU_UNDEFINED +libisal_la_SOURCES += ${lsrc_base_aliases} +endif + nobase_include_HEADERS = isa-l.h libisal_la_LDFLAGS = $(AM_LDFLAGS) \ -version-info $(LIBISAL_CURRENT):$(LIBISAL_REVISION):$(LIBISAL_AGE) diff --git a/configure.ac b/configure.ac index 531320d..a4abbfe 100644 --- a/configure.ac +++ b/configure.ac @@ -22,6 +22,17 @@ AM_INIT_AUTOMAKE([ ]) AM_PROG_AS +AC_CANONICAL_HOST +CPU="" +AS_CASE([$host_cpu], + [x86_64], [CPU="x86_64"], + [amd64], [CPU="x86_64"], + [i?86], [CPU="x86_32"], +) +AM_CONDITIONAL([CPU_X86_64], [test "$CPU" = "x86_64"]) +AM_CONDITIONAL([CPU_X86_32], [test "$CPU" = "x86_32"]) +AM_CONDITIONAL([CPU_UNDEFINED], [test "x$CPU" = "x"]) + # Check for programs AC_PROG_CC_STDC AC_USE_SYSTEM_EXTENSIONS @@ -114,7 +125,7 @@ AM_CONDITIONAL(USE_NASM, test x"$AS" = x"nasm") AM_CONDITIONAL(WITH_AVX512, test x"$have_as_knows_avx512" = x"yes") -case $target in +case $host_os in *linux*) arch=linux yasm_args="-f elf64";; *darwin*) arch=darwin yasm_args="-f macho64 --prefix=_ ";; *netbsd*) arch=netbsd yasm_args="-f elf64";; diff --git a/make.inc b/make.inc index d1689cd..0f791a3 100644 --- a/make.inc +++ b/make.inc @@ -40,6 +40,8 @@ # clean - remove object files version ?= 2.17.0 +host_cpu ?= $(shell uname -m | sed -e 's/amd/x86_/') +arch ?= $(shell uname | grep -v -e Linux -e BSD ) CC = gcc AS = yasm @@ -51,7 +53,7 @@ DEBUG_yasm = -g dwarf2 DEBUG_nasm = -g # Default arch= build options -CFLAGS_gcc = -Wall +CFLAGS_ = -Wall ASFLAGS_ = -f elf64 ARFLAGS_ = cr $@ STRIP_gcc = strip -d -R .comment $@ @@ -69,22 +71,18 @@ ARFLAGS_win64 = -out:$@ # arch=mingw build options ASFLAGS_mingw = -f win64 ARFLAGS_mingw = cr $@ -lsrcmingw = $(lsrc) -unit_testsmingw = $(unit_tests) -examplesmingw = $(examples) -perf_testsmingw = $(perf_tests) +LDFLAGS_mingw = -Wl,--force-exe-suffix LDFLAGS_so = -Wl,-soname,$(soname) ifeq ($(arch),mingw) CC=x86_64-w64-mingw32-gcc AR=x86_64-w64-mingw32-ar - LDFLAGS = -Wl,--force-exe-suffix endif -ifeq ($(shell uname),Darwin) - ASFLAGS_ = -f macho64 --prefix=_ - ARFLAGS_ = -r $@ +ASFLAGS_Darwin = -f macho64 --prefix=_ +ARFLAGS_Darwin = -r $@ +ifeq ($(arch),Darwin) LDFLAGS_so = STRIP_gcc = endif @@ -95,8 +93,9 @@ ASFLAGS = $(ASFLAGS_$(arch)) $(ASFLAGS_$(CC)) $(DEBUG_$(AS)) $(DEFINES) $(INCLU ARFLAGS = $(ARFLAGS_$(arch)) DEFINES += $(addprefix -D , $D) +lsrc += $(lsrc_$(host_cpu)) O = bin -lobj += $(patsubst %.c,%.o,$(patsubst %.asm,%.o,$(lsrc$(arch)) $(lsrc_intrinsic))) +lobj += $(patsubst %.c,%.o,$(patsubst %.asm,%.o,$(lsrc) $(lsrc_intrinsic))) objs = $(addprefix $(O)/,$(notdir $(lobj))) @@ -117,20 +116,20 @@ exampleswin64 = $(examples) perf_testswin64 = $(perf_tests) # Build and run unit tests, performance tests, etc. -all_tests = $(notdir $(sort $(perf_tests$(arch)) $(check_tests$(arch)) $(unit_tests$(arch)) $(examples$(arch)) $(other_tests))) -all_unit_tests = $(notdir $(sort $(check_tests$(arch)) $(unit_tests$(arch)))) -all_perf_tests = $(notdir $(sort $(perf_tests$(arch)))) -all_check_tests = $(notdir $(sort $(check_tests$(arch)))) +all_tests = $(notdir $(sort $(perf_tests) $(check_tests) $(unit_tests) $(examples) $(other_tests))) +all_unit_tests = $(notdir $(sort $(check_tests) $(unit_tests))) +all_perf_tests = $(notdir $(sort $(perf_tests))) +all_check_tests = $(notdir $(sort $(check_tests))) $(all_unit_tests): % : %.c $(lib_name) $(all_perf_tests): % : %.c $(lib_name) -$(sort $(notdir $(examples$(arch)))): % : %.c $(lib_name) +$(sort $(notdir $(examples))): % : %.c $(lib_name) $(sort $(notdir $(other_tests))): % : %.c $(lib_name) sim test trace: $(addsuffix .run,$(all_unit_tests)) perf: $(addsuffix .run,$(all_perf_tests)) check: $(addsuffix .run,$(all_check_tests)) -ex: $(notdir $(examples$(arch))) +ex: $(notdir $(examples)) all: lib $(all_tests) other: $(notdir $(other_tests)) tests: $(all_unit_tests) @@ -150,7 +149,7 @@ $(addsuffix .run,$(all_tests)): %.run : % @echo Completed run: $< # Other build rules -msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(arch)) $D +msg = $(if $(DEBUG),DEBUG) $(patsubst 32,32-bit,$(host_cpu)) $D $(O)/%.o: %.asm @echo " ---> Building $< $(msg)" @@ -190,8 +189,8 @@ so_lib_ver = $(so_lib_inst).$(version) soname = $(so_lib_inst).$(word 1, $(subst ., ,$(version))) slib: $(so_lib_name) -aobjs += $(addprefix $(O)/,$(patsubst %.asm,%.o,$(filter %.asm,$(notdir $(lsrc$(arch)) $(lsrc_intrinsic))))) -shared_objs += $(addprefix $(O)/shared_ver_,$(patsubst %.c,%.o,$(filter %.c,$(notdir $(lsrc$(arch)) $(lsrc_intrinsic))))) +aobjs += $(addprefix $(O)/,$(patsubst %.asm,%.o,$(filter %.asm,$(notdir $(lsrc) $(lsrc_intrinsic))))) +shared_objs += $(addprefix $(O)/shared_ver_,$(patsubst %.c,%.o,$(filter %.c,$(notdir $(lsrc) $(lsrc_intrinsic))))) $(O)/shared_ver_%.o: %.c @echo " ---> Building shared $< $(msg)"