Skip to content

Commit b4d76b3

Browse files
committed
refactor: improve verbose output and remove redundant code in Makefiles
1 parent 4f21d46 commit b4d76b3

3 files changed

Lines changed: 60 additions & 114 deletions

File tree

examples/ImGui/makefile

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,9 @@ endif
215215
# 0 = Silent Mode; 1 = Color & Details Mode
216216
VERBOSE ?= 1
217217

218-
# Optional: if the user passes -s (--silent), force VERBOSE=0
218+
# Pass -s (--silent) to force VERBOSE=0
219219
ifneq ($(findstring s,$(MAKEFLAGS)),)
220220
VERBOSE := 0
221-
else ifneq ($(filter -j%,$(MAKEFLAGS)),)
222-
VERBOSE := 0
223221
endif
224222

225223
# ─── Color Codes ──────────────────────────────────────────────────────────────
@@ -311,7 +309,7 @@ DEPFLAGS = -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.d
311309

312310
.PHONY: all dirs debug release relwithdebinfo analyze docs asm disassemble \
313311
benchmark run run-debug clean clean-all \
314-
clean-docs clean-bench help info deps graph-deps
312+
clean-docs clean-bench help info
315313

316314
# ─── Build rules ──────────────────────────────────────────────────────────────
317315

@@ -340,13 +338,13 @@ $(BIN_DIR)/$(TARGET): $(OBJECTS)
340338
@printf " %-14s : %s\n" "Target" "$(TARGET)"
341339
@printf " %-14s : %s object(s)\n" "Objects" "$(words $(OBJECTS))"
342340
@$(CXX) $(OPTFLAGS) $(SANITIZE_FLAGS) $^ -o $@ $(LDFLAGS) \
343-
&& printf " $(OK_COLOR)[OK]$(NO_COLOR) %-12s : $(OK_COLOR)%s$(NO_COLOR)\n" "Status" "Success" \
344-
|| printf " $(ERROR_COLOR)[FAIL]$(NO_COLOR) %-12s : $(ERROR_COLOR)%s$(NO_COLOR)\n" "Status" "FAILED"
341+
&& printf " %-14s : $(OK_COLOR)%s$(NO_COLOR)\n" "Status" "Success" \
342+
|| printf " %-14s : $(ERROR_COLOR)%s$(NO_COLOR)\n" "Status" "FAILED"
345343
@printf "$(LINES_COLOR)────────────────────────────────────────────$(NO_COLOR)\n"
346344

347345
$(OBJ_DIR)/%.o : %.$(SRC_EXT)
348346
ifeq ($(VERBOSE),1)
349-
@printf " $(OK_COLOR)[OK]$(NO_COLOR) $(OK_COLOR)Compiling$(NO_COLOR) %-40s " "$<"
347+
@printf " $(OK_COLOR)Compiling$(NO_COLOR) %-40s " "$<"
350348
else
351349
@printf "[Compiling] %s\n" "$<"
352350
endif
@@ -368,26 +366,26 @@ endif
368366

369367
debug: BUILD_TYPE=debug
370368
debug: clean-banner all
371-
@printf "\n$(OK_COLOR)[OK] Debug build complete$(NO_COLOR)\n"
369+
@printf "\n$(OK_COLOR)Debug build complete$(NO_COLOR)\n"
372370
@printf "$(WARN_COLOR)Note: Debug builds are not optimized and may run slower than release builds.$(NO_COLOR)\n"
373371

374372
release: BUILD_TYPE=release
375373
release: clean-banner all
376-
@printf "\n$(OK_COLOR)[OK] Release build complete$(NO_COLOR)\n"
374+
@printf "\n$(OK_COLOR)Release build complete$(NO_COLOR)\n"
377375
@printf "$(WARN_COLOR)Note: Release builds are optimized for performance and may be harder to debug.$(NO_COLOR)\n"
378376

379377

380378
relwithdebinfo: BUILD_TYPE=relwithdebinfo
381379
relwithdebinfo: clean-banner all
382-
@printf "\n$(OK_COLOR)[OK] Release with debug info build complete$(NO_COLOR)\n"
380+
@printf "\n$(OK_COLOR)Release with debug info build complete$(NO_COLOR)\n"
383381
@printf "$(WARN_COLOR)Note: This build type includes optimizations and debug symbols, making it suitable for profiling and debugging optimized code.$(NO_COLOR)\n"
384382

385383
analyze: ANALYZE=true
386384
analyze: USE_LTO=false
387385
analyze: BUILD_TYPE=debug
388386
analyze: OPT_DEBUG=-O0
389387
analyze: clean-banner all
390-
@printf "\n$(WARN_COLOR)[WARN] Static analysis enabled - Review output above$(NO_COLOR)\n\n"
388+
@printf "\n$(WARN_COLOR)Static analysis enabled - Review output above$(NO_COLOR)\n\n"
391389

392390
# ─── Documentation Generation ─────────────────────────────────────────────────
393391

@@ -397,14 +395,14 @@ HAS_DOXYGEN := $(shell command -v doxygen 2>/dev/null)
397395
# ─── Documentation ────────────────────────────────────────────────────────────
398396

399397
docs: $(DOC_BUILD)/html/index.html
400-
@printf "$(OK_COLOR)[OK] Documentation generated$(NO_COLOR)\n"
398+
@printf "$(OK_COLOR)Documentation generated$(NO_COLOR)\n"
401399

402400
$(DOC_BUILD)/html/index.html: $(DOXYGEN_CONFIG) | dirs
403401
ifdef HAS_DOXYGEN
404402
@printf "$(INFO_COLOR)[Doxygen]$(NO_COLOR) Generating documentation...\n"
405403
@doxygen $(DOXYGEN_CONFIG)
406404
else
407-
@printf "$(ERROR_COLOR)[FAIL] Doxygen not found$(NO_COLOR)\n"
405+
@printf "$(ERROR_COLOR)Doxygen not found$(NO_COLOR)\n"
408406
@exit 1
409407
endif
410408

@@ -426,15 +424,15 @@ asm: clean-banner dirs
426424
@$(foreach src,$(SOURCES), \
427425
$(CXX) -S -masm=intel -O2 $(INCLUDES) -o $(ASM_DIR)/$(notdir $(basename $(src))).s $(src); \
428426
)
429-
@printf " $(OK_COLOR)[OK]$(NO_COLOR) %-10s : %s\n" "Output" "$(ASM_DIR)"
427+
@printf " %-12s : %s\n" "Output" "$(ASM_DIR)"
430428
@printf "$(LINES_COLOR)────────────────────────────────────────────$(NO_COLOR)\n\n"
431429

432430
disassemble: clean-banner all
433431
@printf "\n$(LINES_COLOR)───────$(NO_COLOR) $(TITLE_COLOR)Disassembly$(NO_COLOR)\n"
434432
@printf " %-12s : %s\n" "Target" "$(TARGET)"
435433
@$(OBJDUMP) -d -Mintel -C "$(call FIXPATH,$(BIN_DIR)/$(TARGET))" > "$(ASM_DIR)/$(APP_NAME)_disasm.txt"
436434
@$(OBJDUMP) -S -wC "$(call FIXPATH,$(BIN_DIR)/$(TARGET))" > "$(ASM_DIR)/$(APP_NAME)_source.txt"
437-
@printf " $(OK_COLOR)[OK]$(NO_COLOR) %-10s : %s\n" "Output:" "$(ASM_DIR)"
435+
@printf " %-12s : %s\n" "Output:" "$(ASM_DIR)"
438436
@printf "$(LINES_COLOR)────────────────────────────────────────────$(NO_COLOR)\n\n"
439437

440438
# ─── Benchmarking ─────────────────────────────────────────────────────────────
@@ -503,40 +501,26 @@ else
503501
@printf "OS: $(OS_NAME) | Build: $(BUILD_TYPE) | TARGET arch: $(TARGET_ARCH)\n\n"
504502
endif
505503

506-
# ─── Dependency Analysis ──────────────────────────────────────────────────────
507-
508-
deps:
509-
@printf "$(INFO_COLOR)[Dependencies]$(NO_COLOR)\n"
510-
@printf " Sources: %d files\n" $(words $(SOURCES))
511-
@printf " Objects: %d files\n" $(words $(OBJECTS))
512-
@printf " Dependencies: %d files\n\n" $(words $(DEPENDENCIES))
513-
514-
graph-deps:
515-
@printf "$(INFO_COLOR)[Dependency Graph]$(NO_COLOR)\n"
516-
@for dep in $(DEPENDENCIES); do \
517-
echo "=== $$dep ===" && cat $$dep 2>/dev/null | head -5; \
518-
done | head -100
519-
520504
# ─── Clean Rules ──────────────────────────────────────────────────────────────
521505

522506
clean:
523507
@printf "$(LINES_COLOR)───────$(NO_COLOR) $(TITLE_COLOR)Clean$(NO_COLOR)\n"
524508
@printf " %-12s : %s\n" "Removing" "OBJ, DEP, ASM, Binary"
525509
@$(RM) "$(call FIXPATH,$(OBJ_DIR))" "$(call FIXPATH,$(DEP_DIR))" "$(call FIXPATH,$(ASM_DIR))" "$(call FIXPATH,$(BIN_DIR)/$(TARGET))" "$(call FIXPATH,$(DOC_BUILD))" "$(call FIXPATH,$(BENCH_DIR))" 2>/dev/null || true
526-
@printf " $(OK_COLOR)[OK]$(NO_COLOR) %-10s : %s\n" "Done" "$(OBJ_DIR) $(DEP_DIR) $(ASM_DIR) $(BIN_DIR) $(DOC_BUILD) $(BENCH_DIR)"
510+
@printf " $(OK_COLOR)%-12s : %s$(NO_COLOR)\n" "Done" "$(OBJ_DIR) $(DEP_DIR) $(ASM_DIR) $(BIN_DIR) $(DOC_BUILD) $(BENCH_DIR)"
527511
@printf "$(LINES_COLOR)────────────────────────────────────────────$(NO_COLOR)\n\n"
528512

529513
clean-all:
530514
@printf "$(LINES_COLOR)───────$(NO_COLOR) $(TITLE_COLOR)Full Clean$(NO_COLOR)\n"
531515
@printf " %-12s \n" " Removing all build artifacts..."
532516
@$(RM) "$(call FIXPATH,$(BUILD_BASE))" 2>/dev/null || true
533-
@printf " $(OK_COLOR)[OK]$(NO_COLOR) %-10s : %s\n" "Done" "$(BUILD_BASE)"
517+
@printf " $(OK_COLOR)%-12s : %s$(NO_COLOR)\n" "Done" "$(BUILD_BASE)"
534518
@printf "$(LINES_COLOR)────────────────────────────────────────────$(NO_COLOR)\n\n"
535519

536520
clean-docs:
537521
@printf "$(WARN_COLOR)[Cleaning]$(NO_COLOR) Removing documentation...\n"
538522
@$(RM) "$(call FIXPATH,$(DOC_BUILD))" 2>/dev/null || true
539-
@printf " $(OK_COLOR)[OK] Docs cleaned$(NO_COLOR)\n"
523+
@printf " $(OK_COLOR)Docs cleaned$(NO_COLOR)\n"
540524

541525
clean-bench:
542526
@$(RM) "$(call FIXPATH,$(BENCH_DIR))" 2>/dev/null || true
@@ -549,19 +533,16 @@ help:
549533
@printf "$(BOLD)Build Targets:$(NO_COLOR)\n"
550534
@printf " $(OK_COLOR)all$(NO_COLOR) - Build application (default)\n"
551535
@printf " $(OK_COLOR)release$(NO_COLOR) - Release build (-O3 -march=native -flto)\n"
552-
@printf " $(OK_COLOR)debug$(NO_COLOR) - Debug build with sanitizers\n"
553-
@printf " $(OK_COLOR)sanitize$(NO_COLOR) - Address & undefined behavior sanitizers\n"
554-
@printf " $(OK_COLOR)analyze$(NO_COLOR) - GCC static analysis\n"
536+
@printf " $(OK_COLOR)debug$(NO_COLOR) - Debug build with sanitizers (ASan+UBSan)\n"
537+
@printf " $(OK_COLOR)analyze$(NO_COLOR) - GCC static analysis (-fanalyzer)\n"
555538
@printf " $(OK_COLOR)relwithdebinfo$(NO_COLOR) - Release with debug info\n\n"
556539

557540
@printf "$(BOLD)Build Benchmarks:$(NO_COLOR)\n"
558541
@printf " $(OK_COLOR)benchmark$(NO_COLOR) - Run benchmarks with current settings\n"
559542

560543
@printf "$(BOLD)Code Analysis:$(NO_COLOR)\n"
561544
@printf " $(OK_COLOR)asm$(NO_COLOR) - Generate assembly files\n"
562-
@printf " $(OK_COLOR)disassemble$(NO_COLOR) - Disassemble binary\n"
563-
@printf " $(OK_COLOR)deps$(NO_COLOR) - List source dependencies\n"
564-
@printf " $(OK_COLOR)graph-deps$(NO_COLOR) - Show dependency graph\n\n"
545+
@printf " $(OK_COLOR)disassemble$(NO_COLOR) - Disassemble binary\n\n"
565546

566547
@printf "$(BOLD)Documentation:$(NO_COLOR)\n"
567548
@printf " $(OK_COLOR)docs$(NO_COLOR) - Generate Doxygen documentation\n"
@@ -593,6 +574,7 @@ info:
593574
@printf "\n$(LINES_COLOR)───────$(NO_COLOR) $(TITLE_COLOR)Project Info$(NO_COLOR)\n"
594575
@printf " %-20s : %s\n" "Project" "$(APP_NAME)"
595576
@printf " %-20s : %s file(s)\n" "Sources" "$(words $(SOURCES))"
577+
@printf " %-20s : %s file(s)\n" "Objects" "$(words $(OBJECTS))"
596578
@printf " %-20s : %s\n" "Target" "$(BIN_DIR)/$(TARGET)"
597579
@printf " %-20s : %s\n" "Compiler" "$(CXX)"
598580
@printf " %-20s : %s\n" "C++ Standard" "$(CXX_STD)"

0 commit comments

Comments
 (0)