Add makefiles: some useful debug and build utils.

This commit is contained in:
Philippe Pittoli 2023-02-09 11:34:32 +01:00
parent 75a77440e6
commit b1f19b30d2
5 changed files with 54 additions and 3 deletions

View File

@ -1,15 +1,19 @@
CC ?= cc
USR_LDFLAGS ?=
LDFLAGS ?= -lipc
include makefile.valgrind
LDFLAGS += $(USR_LDFLAGS)
LDFLAGS += $(STATIC_BUILD)
CFLAGS ?= -Wall -Wextra
all: build
include ../mk/makefile.utils
BINS = pong pongd
build: $(BINS)
$(BINS):
$(CC) -o $@ $@.c $(LDFLAGS)
$(CC) -o $@ $@.c $(CFLAGS) $(LDFLAGS)
clean:
rm $(BINS) 2>/dev/null

View File

@ -0,0 +1,17 @@
ifeq ($(SRC),)
test-src:
@echo SRC must be set via command line.
@exit 1
else
test-src:
endif
list-obj-files: test-src
@# List all .o included in a .a archive.
ar t $(SRC)
list-symbols: test-src
@# List all symbols in a .so.
nm -D $(SRC)
list-symbols-alt: test-src
@# Alternative: grep .text section in an objdump output.
objdump -T $(SRC) | grep text

6
mk/makefile.static-build Normal file
View File

@ -0,0 +1,6 @@
ifdef STATIC
STATIC_BUILD ?= -static
endif
# For interactive completion in the shell.
STATIC ?=

3
mk/makefile.utils Normal file
View File

@ -0,0 +1,3 @@
include ../mk/makefile.valgrind
include ../mk/makefile.bin-inspection
include ../mk/makefile.static-build

21
mk/makefile.valgrind Normal file
View File

@ -0,0 +1,21 @@
# Debug with valgrind.
ifdef VG_SUPPRESS_WARNINGS
VALGRIND_SUPPRESS_WARNINGS ?= --suppressions=./valgrind.suppr
endif
ifdef VG_GENERATE_SUPPRESSION
VALGRIND_GEN_SUPPRESSION ?= --gen-suppressions=all
endif
VALGRIND_OPTS ?= -v --leak-check=full --track-origins=yes
ifdef USE_VALGRIND
VALGRIND ?= valgrind $(VALGRIND_SUPPRESS_WARNINGS) \
$(VALGRIND_GEN_SUPPRESSION) \
$(VALGRIND_OPTS)
endif
# Optional parameters (copied here to help with autocompletion).
VG_SUPPRESS_WARNINGS ?=
VG_GENERATE_SUPPRESSION ?=
USE_VALGRIND ?=