From 3850f371a385c17b56201c6403f51d7d5d731cd5 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sat, 29 Jun 2024 17:29:45 +0200 Subject: [PATCH] Makefile: parallel by default --- Makefile | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index de22701..3a9f4d4 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ .DELETE_ON_ERROR: $(BINDIR)/Getting_Started_with_GTK .DEFAULT_GOAL: all -NTHREADS= $(shell nproc) +CPUS ?= $(shell (nproc --all || sysctl -n hw.ncpu) 2>/dev/null || echo 1) +MAKEFLAGS += --jobs=$(CPUS) CC=gcc CFLAGS=`pkg-config --cflags gtk4 gl glib-2.0 libxml-2.0` @@ -27,10 +28,12 @@ all: $(BINDIR)/gem-graph-client # Directories # $(BUILDDIR): - mkdir -p $@ + @mkdir -p $@ + @echo " MKDIR $@" $(BINDIR): - mkdir -p $@ + @mkdir -p $@ + @echo " MKDIR $@" # # Dependencies @@ -38,34 +41,39 @@ $(BINDIR): -include $(DEPENDENCIES) $(BUILDDIR)/%.d: %.c Makefile | $(BUILDDIR) - mkdir -p $(shell dirname $@) - $(CC) $(CFLAGS) -MM -MT $(@:%.d=%.o) -MF $@ $< + @mkdir -p $(shell dirname $@) + @$(CC) $(CFLAGS) -MM -MT $(@:%.d=%.o) -MF $@ $< + @echo " DEP $@" # # Main program # $(BINDIR)/gem-graph-client: $(OBJECTS) | $(BINDIR) - $(CC) $(LDFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) $^ -o $@ + @$(CC) $(LDFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) $^ -o $@ + @echo " LD $@" # # Objects # $(BUILDDIR)/%.o: %.c Makefile | $(BUILDDIR) - mkdir -p $(shell dirname $@) - $(CC) $(CFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) -c $< -o $@ + @mkdir -p $(shell dirname $@) + @$(CC) $(CFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) -c $< -o $@ + @echo " CC $@" # # Virtual recipes # install: - echo "Installing is not supported" + @echo "Installing is not supported" run: $(BINDIR)/gem-graph-client $(BINDIR)/gem-graph-client clean: - rm -rf $(BINDIR) - rm -rf $(BUILDDIR) + @rm -rf $(BINDIR) + @echo " RM $(BINDIR)" + @rm -rf $(BUILDDIR) + @echo " RM $(BUILDDIR)" # More docs :