Description: Create libbdsg build directories explicitly
 The bundled libbdsg Makefile relies on the "-include .pre-build" trick to
 create bdsg/obj, lib and bin before anything is built.  That trick only works
 while .pre-build is NOT a phony target: GNU make >= 4.4 no longer remakes
 included makefiles that are listed in .PHONY, and libbdsg declares
 ".PHONY: .pre-build all clean install docs".  Since the top-level vg Makefile
 runs "make clean && make" inside deps/libbdsg (clean removes bdsg/obj, lib and
 bin), every object compilation then dies with
   fatal error: opening dependency file bdsg/obj/<name>.d: No such file or
   directory
 Add a real directory rule and hook it up as an order-only prerequisite of the
 object, library and test-binary targets, so the directories are always created
 (also safe under parallel make).
Author: tangxiaofeng <tangxiaofeng@kylinos.cn>
Origin: vendor
Forwarded: not-needed
Last-Update: 2026-09-16

--- a/deps/libbdsg/Makefile
+++ b/deps/libbdsg/Makefile
@@ -41,6 +41,16 @@
 
 all: $(LIB_DIR)/libbdsg.a
 
+# GNU make never re-runs the .pre-build recipe below, because .pre-build is
+# listed in .PHONY and make does not remake included makefiles that are phony
+# targets.  After "make clean" removed them, $(OBJ_DIR)/$(LIB_DIR)/$(BIN_DIR)
+# are therefore missing and every compile aborts with
+#   fatal error: opening dependency file bdsg/obj/<name>.d: No such file or directory
+# Create the directories explicitly and hook them up as order-only prerequisites
+# so that they exist before any object/library is built (parallel-make safe).
+$(OBJ_DIR) $(LIB_DIR) $(BIN_DIR):
+	mkdir -p $@
+
 test: all $(BIN_DIR)/test_libbdsg
 	./$(BIN_DIR)/test_libbdsg
 
@@ -69,16 +79,16 @@
 # Make sure to touch the .o file after the compiler finishes so it is always newer than the .d file
 # Use static pattern rules so the dependency files will not be ignored if the output exists
 # See <https://stackoverflow.com/a/34983297>
-$(OBJS): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.cpp $(OBJ_DIR)/%.d
+$(OBJS): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.cpp $(OBJ_DIR)/%.d | $(OBJ_DIR)
 	$(CXX) $(LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
 	@touch $@
 
 
-$(LIB_DIR)/libbdsg.a: $(OBJS)
+$(LIB_DIR)/libbdsg.a: $(OBJS) | $(LIB_DIR)
 	rm -f $@
 	ar rs $@ $(OBJS)
 
-$(BIN_DIR)/test_libbdsg: $(LIB_DIR)/libbdsg.a $(SRC_DIR)/test_libbdsg.cpp
+$(BIN_DIR)/test_libbdsg: $(LIB_DIR)/libbdsg.a $(SRC_DIR)/test_libbdsg.cpp | $(BIN_DIR)
 	mkdir -p $(BIN_DIR)
 	$(CXX) $(LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) -L $(LIB_DIR) $(SRC_DIR)/test_libbdsg.cpp -o $(BIN_DIR)/test_libbdsg $(LIB_FLAGS)
 	chmod +x $(BIN_DIR)/test_libbdsg
