From b75d90704f3951f4afb9ee44f25cbea4db8d7567 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Thu, 5 Mar 2026 11:10:11 +0100 Subject: [PATCH 1/4] make clang the default compiler for make and cmake builds --- CMakeLists.txt | 11 +++++++++-- Makefile | 15 ++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f1659d6fb..aaaafd529e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ set(CMAKE_C_STANDARD 99) if(UNIX) set(TARGET_PLATFORM "" CACHE STRING "i686 / x86_64") set(CLANG "" CACHE STRING "1=msan / 2=asan / 3=usan") + set(GCC "" CACHE STRING "1=use gcc instead of default (clang)") set(GCOV OFF CACHE BOOL "enable GCOV") set(STRIP OFF CACHE BOOL "enable STRIP") @@ -62,10 +63,16 @@ if(UNIX) # to be uncommented in CI # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + # set C compiler + if(GCC OR GCOV) + find_program(cc NAMES gcc-13 gcc REQUIRED) + else() + find_program(cc NAMES clang-18 clang REQUIRED) + endif() + set(CMAKE_C_COMPILER "${cc}" CACHE STRING "") + # CLANG if(CLANG) - find_program(clangBin NAMES /home/amm-archiv/soft/Linux/clang/current/bin/clang clang REQUIRED) - set(CMAKE_C_COMPILER "${clangBin}" CACHE STRING "") if("${CLANG}" MATCHES "1" OR "${CLANG}" MATCHES "msan") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory") diff --git a/Makefile b/Makefile index b2b5979898..a5e4c6e391 100644 --- a/Makefile +++ b/Makefile @@ -32,8 +32,11 @@ LIB_LC3PLUS ?= liblc3plus.a LIB_LIBUTIL ?= libivasutil.a +CCCLANG = clang +CCGCC = gcc + # Default tool settings -CC ?= gcc +CC ?= $(CCCLANG) RM ?= rm -f AR ?= ar @@ -71,10 +74,6 @@ CFLAGS += -std=c99 -pedantic -Wcast-qual -Wall -W -Wextra -Wno-long-long \ LDLIBS += -lm # Clang sanitizer compiler options -CCCLANG = clang -ifeq "$(CLANG)" "0" -CC = $(CCCLANG) -endif ifeq "$(CLANG)" "1" CC = $(CCCLANG) CFLAGS += -fsanitize=memory @@ -95,6 +94,11 @@ LDFLAGS += -fsanitize=$(usan_checks) LDFLAGS += -fsanitize-recover=$(usan_checks) endif +# check if explicitly gcc is mandated +ifneq "$(GCC)" "" +CC = $(CCGCC) +endif + ifeq "$(RELEASE)" "1" CFLAGS += -DRELEASE OPTIM ?= 2 @@ -106,6 +110,7 @@ LDFLAGS += -g3 endif ifeq "$(GCOV)" "1" +CC = "$(CCGCC)" CFLAGS += -fprofile-arcs -ftest-coverage -fprofile-update=atomic LDFLAGS += -fprofile-arcs -ftest-coverage -fprofile-update=atomic endif -- GitLab From 1b343c863e7dfd981439dfef13a4ac5bab083e6d Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Thu, 5 Mar 2026 11:38:25 +0100 Subject: [PATCH 2/4] default to cc in Makefile in case there is no clang --- Makefile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index a5e4c6e391..621509c508 100644 --- a/Makefile +++ b/Makefile @@ -31,12 +31,8 @@ LIB_LIBISAR ?= libisar.a LIB_LC3PLUS ?= liblc3plus.a LIB_LIBUTIL ?= libivasutil.a - -CCCLANG = clang -CCGCC = gcc - # Default tool settings -CC ?= $(CCCLANG) +CC ?= cc RM ?= rm -f AR ?= ar @@ -73,6 +69,13 @@ CFLAGS += -std=c99 -pedantic -Wcast-qual -Wall -W -Wextra -Wno-long-long \ # libs to link LDLIBS += -lm +# check if clang is available on system and use it if it is there +CLANG_EXISTS := $(shell which clang) + +ifneq "$(CLANG_EXISTS)" "" +CC = clang +endif + # Clang sanitizer compiler options ifeq "$(CLANG)" "1" CC = $(CCCLANG) @@ -96,7 +99,7 @@ endif # check if explicitly gcc is mandated ifneq "$(GCC)" "" -CC = $(CCGCC) +CC = gcc endif ifeq "$(RELEASE)" "1" @@ -110,7 +113,7 @@ LDFLAGS += -g3 endif ifeq "$(GCOV)" "1" -CC = "$(CCGCC)" +CC = gcc CFLAGS += -fprofile-arcs -ftest-coverage -fprofile-update=atomic LDFLAGS += -fprofile-arcs -ftest-coverage -fprofile-update=atomic endif -- GitLab From dc4df340acd7dd26e952548d35ad94eb1e284285 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Thu, 5 Mar 2026 11:59:36 +0100 Subject: [PATCH 3/4] fix sanitizer build --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 621509c508..adbabf7be0 100644 --- a/Makefile +++ b/Makefile @@ -78,17 +78,17 @@ endif # Clang sanitizer compiler options ifeq "$(CLANG)" "1" -CC = $(CCCLANG) +CC = clang CFLAGS += -fsanitize=memory LDFLAGS += -fsanitize=memory endif ifeq "$(CLANG)" "2" -CC = $(CCCLANG) +CC = clang CFLAGS += -fsanitize=address LDFLAGS += -fsanitize=address endif ifeq "$(CLANG)" "3" -CC = $(CCCLANG) +CC = clang # NOTE: keep in sync with list in CMakeLists.txt usan_checks = undefined,float-divide-by-zero,implicit-conversion,local-bounds CFLAGS += -fsanitize=$(usan_checks) -- GitLab From 49330c52033f3ca242d50d5f09b45e0d0e4589e2 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Thu, 5 Mar 2026 17:11:52 +0100 Subject: [PATCH 4/4] add warning if clang compiler is not found --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index adbabf7be0..15002c5ece 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,8 @@ CLANG_EXISTS := $(shell which clang) ifneq "$(CLANG_EXISTS)" "" CC = clang +else +$(warning clang compiler not found - falling back to cc) endif # Clang sanitizer compiler options -- GitLab