This patch simplifies the tests makefile by including new modules/common.gmk
which identifies common compiler flags depending on the architecture and
possibly cross-compiler prefix and locates common shared libraries.

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 modules/tests/Makefile | 95 ++++--------------------------------------
 1 file changed, 9 insertions(+), 86 deletions(-)

diff --git a/modules/tests/Makefile b/modules/tests/Makefile
index 2c495ed0..ab6878e6 100644
--- a/modules/tests/Makefile
+++ b/modules/tests/Makefile
@@ -1,16 +1,6 @@
 module: usr.manifest common.manifest fs.manifest build_all_tests
 
-# Paths set by scripts/build
-src := $(OSV_BASE)
-out := $(OSV_BUILD_PATH)
-arch := $(ARCH)
-fs_type := $(fs_type)
-# TODO: consider setting $(out) not to OSV_BUILD_PATH but to ./build/$ARCH.
-# TODO: need to set up CXX, etc., for cross compilation, as in the main
-# Makefile...
-
-aarch64_gccbase = $(src)/build/downloaded_packages/aarch64/gcc/install
-aarch64_boostbase = $(src)/build/downloaded_packages/aarch64/boost/install
+include ../common.gmk
 
 # Ask make to not delete "intermediate" results, such as the .o in the chain
 # .cc -> .o -> .so. Otherwise, during the first build, make considers the .o
@@ -19,73 +9,11 @@ aarch64_boostbase = 
$(src)/build/downloaded_packages/aarch64/boost/install
 # See commit fac05c95 for a longer explanation.
 .SECONDARY:
 
-quiet = $(if $V, $1, @echo " $2"; $1)
-very-quiet = $(if $V, $1, @$1)
-makedir = $(call very-quiet, mkdir -p $(dir $@))
-
-autodepend = -MD -MT $@ -MP
-
-INCLUDES = -I$(src)/arch/$(ARCH) -I$(src) -I$(src)/include \
-       -I$(src)/arch/common -isystem $(src)/include/glibc-compat
-
-ifeq ($(arch),aarch64)
-  CROSS_PREFIX = aarch64-linux-gnu-
-  CXX=$(CROSS_PREFIX)g++
-  CC=$(CROSS_PREFIX)gcc
-  LD=$(CROSS_PREFIX)ld
-  OBJCOPY=$(CROSS_PREFIX)objcopy
-  export STRIP=$(CROSS_PREFIX)strip
-
-  aarch64_libdir := $(dir $(shell find $(aarch64_gccbase)/ -name libstdc++.so))
-  aarch64_libdir2 := $(dir $(shell find $(aarch64_gccbase)/ -name 
libgcc_s.so.1))
-  LDFLAGS = -L$(aarch64_libdir)
-
-  aarch64-gcc-inc-base := $(dir $(shell find $(aarch64_gccbase)/ -name vector 
| grep -v -e debug/vector$$ -e profile/vector$$ -e experimental/vector$$))
-  aarch64-gcc-inc-base3 := $(dir $(shell dirname `find $(aarch64_gccbase)/ 
-name c++config.h | grep -v /32/`))
-  INCLUDES += -isystem $(aarch64-gcc-inc-base)
-  INCLUDES += -isystem $(aarch64-gcc-inc-base3)
-  INCLUDES += -isystem $(aarch64_boostbase)/usr/include
-else
-  INCLUDES += $(shell $(CXX) -E -xc++ - -v </dev/null 2>&1 | awk '/^End/ 
{exit} /^ .*c\+\+/ {print "-isystem" $$0}')
-endif
-
-INCLUDES += -isystem $(src)/include/api -isystem $(src)/include/api/$(ARCH)
-
-ifeq ($(arch),aarch64)
-  aarch64-gcc-inc-base2 := $(dir $(shell find $(aarch64_gccbase)/ -name 
unwind.h))
-  # must be after include/api, since it includes some libc-style headers:
-  INCLUDES += -isystem $(aarch64-gcc-inc-base2)
-endif
-
-INCLUDES += -isystem $(out)/gen/include
-
-ifeq ($(arch),aarch64)
-  post-includes-bsd = -isystem $(src)/bsd/sys
-  # For acessing machine/ in cpp xen drivers
-  post-includes-bsd += -isystem $(src)/bsd/
-  post-includes-bsd += -isystem $(src)/bsd/$(arch)
-  INCLUDES += $(post-includes-bsd)
-endif
-
-COMMON = $(autodepend) $(INCLUDES)
-
-ifeq ($(arch),aarch64)
-  COMMON += --sysroot $(aarch64_gccbase) -DAARCH64_PORT_STUB
-endif
-
 COMMON += -g -O2 -fPIC -DBOOST_TEST_DYN_LINK \
        -U _FORTIFY_SOURCE -D_KERNEL -D__OSV__ -DCONF_debug_memory=0 \
        -Wall -Wno-pointer-arith -Wformat=0 -Wno-format-security
 
-ifeq ($(arch),aarch64)
-  COMMON += -nostdinc
-endif
-
-ifeq ($(arch),aarch64)
-LIBS = $(aarch64_libdir2)/libgcc_s.so.1
-else
-LIBS =
-endif
+LIBS = $(libgcc_s_dir)/libgcc_s.so.1
 
 CXXFLAGS = -std=gnu++11 $(COMMON)
 CFLAGS = -std=gnu99 $(COMMON)
@@ -113,7 +41,7 @@ $(out)/tests/rofs/%.o: $(src)/tests/%.c
 $(out)/%.so: $(out)/%.o
        $(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $< $(LIBS), 
LD $*.so)
 
-$(out)/tests/tst-non-fpic.o: CXXFLAGS:=$(subst 
-fPIC,-mcmodel=large,$(CXXFLAGS))
+$(out)/tests/tst-non-fpic.o: CXXFLAGS:=$(subst -fPIC,-fno-pic 
-mcmodel=large,$(CXXFLAGS))
 
 $(out)/tests/tst-getopt-pie.o: CXXFLAGS:=$(subst -fPIC,-fpie,$(CXXFLAGS))
 $(out)/tests/tst-getopt-pie.o: $(src)/tests/tst-getopt.cc
@@ -240,11 +168,6 @@ $(out)/tests/tst-tls-gold.so: \
        $(makedir)
        $(call quiet, cd $(out); $(CXX) $(CXXFLAGS) $(LDFLAGS) 
-D__SHARED_OBJECT__=1 -shared -o $@ $< tests/libtls_gold.so, CXX 
tests/tst-tls.cc)
 
-ifeq ($(arch),aarch64)
-  aarch64_boost_libdir := $(dir $(shell find $(aarch64_boostbase)/ -name 
libboost_system.so))
-  LDFLAGS += -L$(aarch64_boost_libdir)
-endif
-
 common-boost-tests := tst-vfs.so tst-libc-locking.so misc-fs-stress.so \
        misc-bdev-write.so misc-bdev-wlatency.so misc-bdev-rw.so \
        tst-promise.so tst-dlfcn.so tst-stat.so tst-wait-for.so \
@@ -306,10 +229,10 @@ build_all_tests: $(all_tests:%=$(out)/%)
 usr.manifest: build_all_tests $(lastword $(MAKEFILE_LIST)) usr.manifest.skel 
FORCE
        @echo "  generating modules/tests/usr.manifest"
        @cat $@.skel > $@
-       @if [ "$(arch)" = "x64" ]; then \
-               ldd $(addprefix $(out)/tests/,$(boost-tests)) | grep libboost | 
sed 's/ *[^ ] *\(.*\) => \(.*\) .*/\/usr\/lib\/\1: \2/' | sort | uniq >> $@; \
-       else \
+       @if [ "$(CROSS_PREFIX)" = "aarch64-linux-gnu-" ]; then \
                ./add_aarch64_boost_libraries.sh $(OSV_BASE) >> $@; \
+       else \
+               ldd $(addprefix $(out)/tests/,$(boost-tests)) | grep libboost | 
sed 's/ *[^ ] *\(.*\) => \(.*\) .*/\/usr\/lib\/\1: \2/' | sort | uniq >> $@; \
        fi
        @echo $(all_tests) | tr ' ' '\n' | grep -v "tests/rofs/tst-.*.so" | awk 
'{print "/" $$0 ": ./" $$0}' >> $@
        @echo $(all_tests) | tr ' ' '\n' | grep "tests/rofs/tst-.*.so" | sed 
's/\.so//' | awk 'BEGIN { FS = "/" } ; { print "/tests/" $$3 "-rofs.so: 
./tests/" $$2 "/" $$3 ".so"}' >> $@
@@ -320,10 +243,10 @@ FORCE:
 common.manifest: build_all_tests $(lastword $(MAKEFILE_LIST)) 
usr.manifest.skel FORCE
        @echo "  generating modules/tests/common.manifest"
        @cat usr.manifest.skel > $@
-       @if [ "$(arch)" = "x64" ]; then \
-               ldd $(addprefix $(out)/tests/,$(boost-tests)) | grep libboost | 
sed 's/ *[^ ] *\(.*\) => \(.*\) .*/\/usr\/lib\/\1: \2/' | sort | uniq >> $@; \
-       else \
+       @if [ "$(CROSS_PREFIX)" = "aarch64-linux-gnu-" ]; then \
                ./add_aarch64_boost_libraries.sh $(OSV_BASE) >> $@; \
+       else \
+               ldd $(addprefix $(out)/tests/,$(boost-tests)) | grep libboost | 
sed 's/ *[^ ] *\(.*\) => \(.*\) .*/\/usr\/lib\/\1: \2/' | sort | uniq >> $@; \
        fi
        @echo $(common-tests) $(solaris-tests) | tr ' ' '\n' | awk '{print 
"/tests/" $$0 ": ./tests/" $$0}' >> $@
 
-- 
2.29.2

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20210121234008.682877-2-jwkozaczuk%40gmail.com.

Reply via email to