From 82126eca3cb6f67f06bb406cc6cb0205b424e983 Mon Sep 17 00:00:00 2001 From: jaburns Date: Mon, 19 Oct 2020 17:17:28 -0600 Subject: [PATCH] Makefile reimports when import script changes --- Makefile | 18 +++++++++++------- import-mario-geo.py | 6 ++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 29fcb0e..5325f54 100644 --- a/Makefile +++ b/Makefile @@ -12,20 +12,24 @@ ALL_DIRS := $(addprefix $(BUILD_DIR)/,$(SRC_DIRS)) BIN_FILE := $(DIST_DIR)/libsm64.so LIB_H_FILE := $(DIST_DIR)/include/libsm64.h -C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) +C_IMPORTED := src/mario/geo.inc.c src/mario/model.inc.c +H_IMPORTED := $(C_IMPORTED:.c=.h) +IMPORTED := $(C_IMPORTED) $(H_IMPORTED) + +C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) $(C_IMPORTED) O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) DEP_FILES := $(O_FILES:.o=.d) +DUMMY != mkdir -p src/mario DUMMY != mkdir -p $(ALL_DIRS) DUMMY != mkdir -p $(DIST_DIR)/include -DUMMY != ./import-mario-geo.py >&2 || echo FAIL -ifeq ($(DUMMY),FAIL) - $(error Script import-mario-geo.py failed) -endif +$(filter-out src/mario/geo.inc.c,$(IMPORTED)): src/mario/geo.inc.c +src/mario/geo.inc.c: ./import-mario-geo.py + ./import-mario-geo.py -$(BUILD_DIR)/%.o: %.c - $(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< +$(BUILD_DIR)/%.o: %.c $(IMPORTED) + @$(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< $(CC) -c $(CFLAGS) -o $@ $< $(BIN_FILE): $(O_FILES) diff --git a/import-mario-geo.py b/import-mario-geo.py index 250dfb6..90926c2 100755 --- a/import-mario-geo.py +++ b/import-mario-geo.py @@ -38,6 +38,7 @@ const GeoLayout mario_geo_libsm64[] = { }; void *mario_geo_ptr = (void*)mario_geo_libsm64; + """ geo_inc_h = """ @@ -56,10 +57,6 @@ model_inc_h = """ def main(): global model_inc_h - if os.path.exists("src/mario/geo.inc.c") and os.path.exists("src/mario/model.inc.c") \ - and os.path.exists("src/mario/geo.inc.h") and os.path.exists("src/mario/model.inc.h"): - return; - shutil.rmtree("src/mario", ignore_errors=True) os.makedirs("src/mario", exist_ok=True) @@ -85,6 +82,7 @@ def main(): lines.insert(0, "#include \"../load_tex_data.h\"") model_inc_c = "\n".join(lines) + with open("src/mario/geo.inc.c", "w") as file: file.write(geo_inc_c_header + geo_inc_c + geo_inc_c_footer)