Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading