Update Makefile
Fixed edge case in serve target by properly handling frontend process cleanup - Replaced `kill %1` with `kill $$FRONTEND_PID` to ensure correct process termination. - Captures frontend process PID (`$$!`) explicitly for better reliability. - Prevents potential issues when multiple background jobs exist. - Improved Makefile structure for readability and maintainability. Signed-off-by: Yehowshua <yehowshua@joyofhardware.com>
This commit is contained in:
parent
919c1772e7
commit
dafd0ceedf
15
Makefile
15
Makefile
|
@ -9,6 +9,7 @@ ELM_MAKE := elm make
|
||||||
CARGO_BUILD := cargo build
|
CARGO_BUILD := cargo build
|
||||||
CARGO_RUN := cargo run
|
CARGO_RUN := cargo run
|
||||||
|
|
||||||
|
# Ensure exactly one of DEBUG or RELEASE is set
|
||||||
ifeq ($(DEBUG)$(RELEASE),) # Both are empty
|
ifeq ($(DEBUG)$(RELEASE),) # Both are empty
|
||||||
$(error You must set exactly one of DEBUG=1 or RELEASE=1)
|
$(error You must set exactly one of DEBUG=1 or RELEASE=1)
|
||||||
endif
|
endif
|
||||||
|
@ -20,14 +21,15 @@ endif
|
||||||
# Targets
|
# Targets
|
||||||
.PHONY: all frontend backend clean serve
|
.PHONY: all frontend backend clean serve
|
||||||
|
|
||||||
|
# Ensure PUBLIC_DIR exists
|
||||||
$(PUBLIC_DIR):
|
$(PUBLIC_DIR):
|
||||||
mkdir -p $(PUBLIC_DIR)
|
mkdir -p $(PUBLIC_DIR)
|
||||||
|
|
||||||
|
# Copy index.html into PUBLIC_DIR
|
||||||
$(PUBLIC_DIR)/index.html: $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)
|
$(PUBLIC_DIR)/index.html: $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)
|
||||||
cp $< $@
|
cp $< $@
|
||||||
|
|
||||||
.PHONY: frontend backend
|
# Frontend build target
|
||||||
|
|
||||||
frontend: $(PUBLIC_DIR)/index.html $(PUBLIC_DIR)
|
frontend: $(PUBLIC_DIR)/index.html $(PUBLIC_DIR)
|
||||||
mkdir -p $(PUBLIC_DIR)/assets
|
mkdir -p $(PUBLIC_DIR)/assets
|
||||||
make -C $(FRONTEND_DIR)
|
make -C $(FRONTEND_DIR)
|
||||||
|
@ -35,14 +37,21 @@ frontend: $(PUBLIC_DIR)/index.html $(PUBLIC_DIR)
|
||||||
cp $(FRONTEND_DIR)/src/ports.websocket.js $(PUBLIC_DIR)/
|
cp $(FRONTEND_DIR)/src/ports.websocket.js $(PUBLIC_DIR)/
|
||||||
cp $(FRONTEND_DIR)/assets/CourierPrime-Regular.ttf $(PUBLIC_DIR)/assets/
|
cp $(FRONTEND_DIR)/assets/CourierPrime-Regular.ttf $(PUBLIC_DIR)/assets/
|
||||||
|
|
||||||
|
# Backend build target
|
||||||
backend:
|
backend:
|
||||||
$(CARGO_BUILD) --manifest-path=$(BACKEND_DIR)/Cargo.toml
|
$(CARGO_BUILD) --manifest-path=$(BACKEND_DIR)/Cargo.toml
|
||||||
|
|
||||||
|
# Clean target (optional, assuming we want to remove build artifacts)
|
||||||
|
clean:
|
||||||
|
rm -rf $(PUBLIC_DIR)
|
||||||
|
|
||||||
|
# Serve: Runs both frontend and backend
|
||||||
serve: frontend backend
|
serve: frontend backend
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG),1)
|
||||||
$(MAKE) -C $(FRONTEND_DIR) serve DEBUG=1 & \
|
$(MAKE) -C $(FRONTEND_DIR) serve DEBUG=1 & \
|
||||||
|
FRONTEND_PID=$$!; \
|
||||||
RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml; \
|
RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml; \
|
||||||
kill %1
|
kill $$FRONTEND_PID
|
||||||
else ifeq ($(RELEASE),1)
|
else ifeq ($(RELEASE),1)
|
||||||
$(CARGO_RUN) --release --manifest-path=$(BACKEND_DIR)/Cargo.toml
|
$(CARGO_RUN) --release --manifest-path=$(BACKEND_DIR)/Cargo.toml
|
||||||
endif
|
endif
|
||||||
|
|
Loading…
Reference in a new issue