Skip to content

Commit

Permalink
Fix caching in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemiii91 committed Oct 21, 2024
1 parent ea7bfac commit bcd092c
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,62 @@ endif
# Function to print status messages
print_status = $(ECHO) "\033[34m--- $1\033[0m"

.PHONY: all build assemble apply-patches copy-submodule update-submodule convert-line-endings init-submodule create-patch clean

.PHONY: all build assemble apply-patches copy-submodule create-patch clean


all: build

## Submodule management

init-submodule:
@$(call print_status, Initializing submodule)
$(BUILD_DIR)/.has_submodule:
@$(call print_status, Copying submodule)
@if [ -d "$(SUBMODULE_DIR)" ] && [ -z "$$(ls -A $(SUBMODULE_DIR))" ]; then \
git submodule update --init --recursive; \
else \
echo "Submodule directory is not empty, skipping initialization"; \
fi

copy-submodule: init-submodule
@$(call print_status, Copying submodule)
mkdir -p $(BUILD_DIR)
cp -r $(SUBMODULE_DIR)/* $(BUILD_DIR)/
@touch $(BUILD_DIR)/.has_submodule

copy-submodule: $(BUILD_DIR)/.has_submodule

## Patch management

convert-line-endings:
$(BUILD_DIR)/.is_patched: $(BUILD_DIR)/.has_submodule
@$(call print_status, Converting line endings)
find $(BUILD_DIR) -type f \( -name '*.c' -o -name '*.h' \) -exec sed -i "s/\r\$$//" {} +

apply-patches: copy-submodule convert-line-endings
@for patch in $(sort $(wildcard $(PATCH_DIR)/*.patch)); do \
$(call print_status, Applying $$patch); \
patch -d $(BUILD_DIR) -p1 < $$patch; \
done
@touch $(BUILD_DIR)/.is_patched

apply-patches: $(BUILD_DIR)/.is_patched

create-patch:
@$(call print_status, Creating patch)
./scripts/create_patch.sh

assemble: apply-patches
## Source management

$(BUILD_DIR)/.is_assembled: $(BUILD_DIR)/.is_patched
@$(call print_status, Assembling source)
cp -r $(SRC_DIR)/* $(BUILD_DIR)/
@touch $(BUILD_DIR)/.is_assembled

assemble: $(BUILD_DIR)/.is_assembled

## Build targets

$(BUILD_DIR)/retroarch:
$(BUILD_DIR)/retroarch: $(BUILD_DIR)/.is_assembled
@$(call print_status, Building for Miyoo Mini)
@cd $(BUILD_DIR) && make -f Makefile.miyoomini PACKAGE_NAME=retroarch

$(BUILD_DIR)/retroarch_miyoo354:
$(BUILD_DIR)/retroarch_miyoo354: $(BUILD_DIR)/.is_assembled
@$(call print_status, Building for Miyoo 354)
@cd $(BUILD_DIR) && make -f Makefile.miyoomini MIYOO354=1 PACKAGE_NAME=retroarch_miyoo354

build: assemble $(BUILD_DIR)/retroarch $(BUILD_DIR)/retroarch_miyoo354
build: $(BUILD_DIR)/retroarch $(BUILD_DIR)/retroarch_miyoo354
@$(call print_status, Copying binaries)
mkdir -p bin
cp $(BUILD_DIR)/retroarch bin/
Expand Down

0 comments on commit bcd092c

Please sign in to comment.