From 08f1483b0a4e685c2211f3ca24a9e505502dc333 Mon Sep 17 00:00:00 2001 From: Takayuki Matsuoka Date: Wed, 9 Nov 2022 23:42:03 +0900 Subject: Add environment check for freestanding test Freestanding test is intended to run on only Linux x86_64 platform. Because it uses Linux x86_64 syscall directly to avoid any dependency to the standard library. This changeset adds platform checking code to tests/Makefile to avoid unintended error in non-Linux x86_64 platforms. This changeset resolves issue #1186 --- tests/Makefile | 37 ++++++++++++++++++++++++++++++++++--- tests/freestanding.c | 1 - 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index b446e4e..cebb0d1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -115,9 +115,6 @@ decompress-partial: lz4.o decompress-partial.c decompress-partial-usingDict: lz4.o decompress-partial-usingDict.c $(CC) $(FLAGS) $^ -o $@$(EXT) -freestanding: freestanding.c - $(CC) -ffreestanding -nostdlib $^ -o $@$(EXT) - .PHONY: clean clean: @$(MAKE) -C $(LZ4DIR) $@ > $(VOID) @@ -353,10 +350,44 @@ test-decompress-partial : decompress-partial decompress-partial-usingDict @echo "\n ---- test decompress-partial-usingDict ----" ./decompress-partial-usingDict$(EXT) + +#----------------------------------------------------------------------------- +# freestanding test only for Linux x86_64 +#----------------------------------------------------------------------------- +ifeq ($(OS),Windows_NT) + UNAME_S := Windows +else + UNAME_S := $(shell uname -s) +endif + +ifeq ($(OS),Windows_NT) + UNAME_P := Unknown +else + UNAME_P := $(shell uname -p) +endif + +FREESTANDING_CFLAGS := -ffreestanding -nostdlib + +ifneq ($(UNAME_S), Linux) + FREESTANDING_CFLAGS := +endif + +ifneq ($(UNAME_P), x86_64) + FREESTANDING_CFLAGS := +endif + +freestanding: freestanding.c + $(CC) $(FREESTANDING_CFLAGS) $^ -o $@$(EXT) + test-freestanding: freestanding @echo "\n ---- test freestanding ----" +ifeq ($(FREESTANDING_CFLAGS),) + @echo "\n (skip)" +else ./freestanding$(EXT) -strace ./freestanding$(EXT) -ltrace ./freestanding$(EXT) +endif + endif diff --git a/tests/freestanding.c b/tests/freestanding.c index ceff4c5..6109aa7 100644 --- a/tests/freestanding.c +++ b/tests/freestanding.c @@ -30,7 +30,6 @@ #if !defined(__x86_64__) || !defined(__linux__) -EXTERN_C void _start(void) { } int main(int argc, char** argv) { return 0; } #else -- cgit v0.12