Răsfoiți Sursa

Makefile: Parallelize build using all available CPU cores

Nick Peng 1 lună în urmă
părinte
comite
3582bad807
2 a modificat fișierele cu 7 adăugiri și 0 ștergeri
  1. 4 0
      src/Makefile
  2. 3 0
      test/Makefile

+ 4 - 0
src/Makefile

@@ -23,6 +23,10 @@ LINT_OBJS=$(filter-out lib/%.o, $(OBJS))
 TEST_OBJS=$(patsubst %.o,%_test.o,$(OBJS))
 MAIN_OBJ = main.o
 
+ifeq ($(filter -j,$(MAKEFLAGS)),)
+MAKEFLAGS += -j$(shell nproc)
+endif
+
 # cflags
 ifndef CFLAGS
  ifdef DEBUG

+ 3 - 0
test/Makefile

@@ -29,6 +29,9 @@ OBJS += $(TEST_OBJECTS)
 
 SMARTDNS_SRC_FILES := $(wildcard $(SMARTDNS_SRC_DIR)/*.c) $(wildcard $(SMARTDNS_SRC_DIR)/*.h) $(wildcard $(SMARTDNS_SRC_DIR)/lib/*.c)
 
+ifeq ($(filter -j,$(MAKEFLAGS)),)
+MAKEFLAGS += -j$(shell nproc)
+endif
 
 LDFLAGS += -lssl -lcrypto -lpthread -ldl -lgtest -lstdc++ -lm
 LDFLAGS += $(EXTRA_LDFLAGS)