Skip to content

Commit fcb2df0

Browse files
committed
make: Fixing default build flags for various OS's in makefiles
Signed-off-by: Tyler Erickson <tyler.erickson@seagate.com>
1 parent ee022d8 commit fcb2df0

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

Make/compiler-flags.mk

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,20 @@ endif
123123
NEWER_WARNINGS := $(foreach flag,$(NEWER_WARNING_CANDIDATES),$(if $(call cc_supports,$(flag)),$(flag)))
124124

125125
#===============================================================================
126-
# Conversion Warnings (commonly supported)
126+
# Conversion Warnings (test for support, some require newer compilers)
127127
#===============================================================================
128128

129+
# Always available conversion warnings
129130
CONVERSION_WARNING_FLAGS := \
130131
-Wint-conversion \
131-
-Wenum-conversion \
132132
-Wfloat-conversion \
133133
-Wint-to-pointer-cast
134134

135+
# Test for -Wenum-conversion (GCC 10+, Clang 3.2+)
136+
ifeq ($(call cc_supports,-Wenum-conversion),yes)
137+
CONVERSION_WARNING_FLAGS += -Wenum-conversion
138+
endif
139+
135140
# GCC 10+ specific: -Wsign-conversion (very noisy, use while debugging)
136141
# NOTE: Intentionally not enabled by default per meson.build comments
137142
# Uncomment if desired:
@@ -243,14 +248,18 @@ endif
243248
# Combined CFLAGS and CXXFLAGS
244249
#===============================================================================
245250

246-
# Initialize if not already set
251+
# Initialize if not already set (allows user to provide CFLAGS/CXXFLAGS from environment)
247252
CFLAGS ?=
248253
CXXFLAGS ?=
254+
LDFLAGS ?=
249255

250-
# Combine all flags
256+
# Prepend our flags (our flags first, then user flags - this allows user to override)
257+
# Use := for one-time expansion to avoid recursive evaluation issues
251258
CFLAGS := $(WARNING_FLAGS) $(OPT_FLAGS) $(DEBUG_FLAGS) $(CFLAGS)
252259
CXXFLAGS := $(WARNING_FLAGS) $(OPT_FLAGS) $(DEBUG_FLAGS) $(CXXFLAGS)
253260

261+
# Note: LDFLAGS is only initialized here, actual flags are added in security-hardening.mk and other files
262+
254263
#===============================================================================
255264
# Save Tested Flags to Cache (for debugging)
256265
#===============================================================================

Make/config.mk

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,23 @@ ifeq ($(filter $(BUILD_TYPE),$(VALID_BUILD_TYPES)),)
177177
endif
178178

179179
# Optimization and debug flags based on build type
180+
# Use ?= so downstream packagers can override (e.g., OPTIMIZATION_FLAGS="-O2" make)
180181
ifeq ($(BUILD_TYPE),debug)
181182
# No optimization, maximum debug information
182-
OPTIMIZATION_FLAGS := -O0 -g3
183-
BUILD_DEFINES := -DDEBUG -D_DEBUG
183+
OPTIMIZATION_FLAGS ?= -O0 -g3
184+
BUILD_DEFINES ?= -DDEBUG -D_DEBUG
184185
else ifeq ($(BUILD_TYPE),release)
185186
# Full optimization, no debug info
186-
OPTIMIZATION_FLAGS := -O3
187-
BUILD_DEFINES := -DNDEBUG -DRELEASE
187+
OPTIMIZATION_FLAGS ?= -O3
188+
BUILD_DEFINES ?= -DNDEBUG -DRELEASE
188189
else ifeq ($(BUILD_TYPE),relwithdebinfo)
189190
# Optimized with debug symbols (for production debugging/profiling)
190-
OPTIMIZATION_FLAGS := -O2 -g
191-
BUILD_DEFINES := -DNDEBUG
191+
OPTIMIZATION_FLAGS ?= -O2 -g
192+
BUILD_DEFINES ?= -DNDEBUG
192193
else ifeq ($(BUILD_TYPE),minsize)
193194
# Optimize for binary size
194-
OPTIMIZATION_FLAGS := -Os
195-
BUILD_DEFINES := -DNDEBUG
195+
OPTIMIZATION_FLAGS ?= -Os
196+
BUILD_DEFINES ?= -DNDEBUG
196197
endif
197198

198199
# Legacy support for static builds (deprecated, use IS_STATIC variable instead)
@@ -255,11 +256,11 @@ $(OBJ_DIR) $(LIB_DIR) $(BIN_DIR) $(OBJ_DIRS):
255256
#===============================================================================
256257

257258
# Compiler and tools
258-
# Note: Make has a built-in default CC=cc, so we override it
259-
ifeq ($(CC),cc)
260-
CC := gcc
261-
endif
262-
CXX ?= g++
259+
# Auto-detect system default compiler (cc points to gcc or clang depending on system)
260+
# FreeBSD/OpenBSD use clang by default, most Linux use gcc
261+
# Only override if CC is unset (not if it's already set to 'cc')
262+
CC ?= cc
263+
CXX ?= c++
263264
AR ?= ar
264265
STRIP ?= strip
265266
INSTALL ?= install

0 commit comments

Comments
 (0)