diff --git a/src/Makefile b/src/Makefile index 73815ac2bcf..7c22cdb9b15 100644 --- a/src/Makefile +++ b/src/Makefile @@ -99,6 +99,9 @@ ifeq ($(USE_JEMALLOC),no) MALLOC=libc endif +# Export MALLOC so sub-makes (like unit tests) can see it +export MALLOC + ifdef SANITIZER ifeq ($(SANITIZER),address) MALLOC=libc @@ -267,8 +270,9 @@ else ifeq ($(uname_S),Darwin) FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib FINAL_LDFLAGS+= -Wl,-rpath,$(current_dir)/modules/lua + FINAL_LDFLAGS+= -Wl,-rpath,@loader_path/../lib else - FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib:$(current_dir)/modules/lua -Wl,--disable-new-dtags + FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib:$(current_dir)/modules/lua:$$ORIGIN/../lib -Wl,--disable-new-dtags endif endif @@ -674,18 +678,12 @@ persist-settings: distclean .PHONY: persist-settings # Prerequisites target -.make-prerequisites: +# Marker file to track that dependencies have been built +# Use order-only prerequisite to avoid unnecessary rebuilds +.make-deps-built: + @(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS)) @touch $@ -# Clean everything, persist settings and build dependencies if anything changed -ifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS))) -.make-prerequisites: persist-settings -endif - -ifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS))) -.make-prerequisites: persist-settings -endif - # valkey-server $(SERVER_NAME): $(ENGINE_SERVER_OBJ) $(LUA_MODULE) $(SERVER_LD) -o $@ $(ENGINE_SERVER_OBJ) ../deps/libvalkey/lib/libvalkey.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS) @@ -715,7 +713,7 @@ $(RDMA_MODULE_NAME): $(SERVER_NAME) $(QUIET_CC)$(CC) $(LDFLAGS) -o $@ rdma.c -shared -fPIC $(RDMA_MODULE_CFLAGS) # engine_lua.so -$(LUA_MODULE_NAME): .make-prerequisites +$(LUA_MODULE_NAME): | .make-deps-built cd modules/lua && $(MAKE) OPTIMIZATION="$(OPTIMIZATION)" # valkey-cli @@ -732,10 +730,11 @@ DEP = $(ENGINE_SERVER_OBJ:%.o=%.d) $(ENGINE_CLI_OBJ:%.o=%.d) $(ENGINE_BENCHMARK_ # Because the jemalloc.h header is generated as a part of the jemalloc build, # building it should complete before building any other object. Instead of # depending on a single artifact, build all dependencies first. -%.o: %.c .make-prerequisites +# Use order-only prerequisite (|) so marker timestamp doesn't trigger rebuilds +%.o: %.c | .make-deps-built $(SERVER_CC) -MMD -o $@ -c $< -trace/%.o: trace/%.c .make-prerequisites +trace/%.o: trace/%.c | .make-deps-built $(SERVER_CC) -Itrace -MMD -o $@ -c $< # The following files are checked in and don't normally need to be rebuilt. They diff --git a/src/unit/Makefile b/src/unit/Makefile index 47fcab4fbf8..c989b946523 100644 --- a/src/unit/Makefile +++ b/src/unit/Makefile @@ -135,13 +135,13 @@ $(VALKEY_SERVER_WRAP_LIB): $(VALKEY_SERVER_LIB) $(ENGINE_SERVER_WRAP_OBJ) genera endif # Ensure Valkey server library is built -$(VALKEY_SERVER_LIB): make-prerequisites +$(VALKEY_SERVER_LIB): make-deps-built cd .. && $(MAKE) libvalkey.a -# Ensure parent prerequisites are built -.PHONY: make-prerequisites -make-prerequisites: - cd .. && $(MAKE) .make-prerequisites +# Ensure parent dependencies are built +.PHONY: make-deps-built +make-deps-built: + cd .. && $(MAKE) .make-deps-built # Read MALLOC / USE_JEMALLOC setting from parent Makefile JEMALLOC_CFLAGS := -DUSE_JEMALLOC -isystem../../deps/jemalloc/include @@ -191,7 +191,7 @@ else endif # Generate a new set of wrappers every time our header changes. -generated_wrappers.cpp: make-prerequisites wrappers.h generate-wrappers.py +generated_wrappers.cpp: make-deps-built wrappers.h generate-wrappers.py ./generate-wrappers.py generated_wrappers.o: generated_wrappers.cpp