example-spa-elm-app/Makefile

57 lines
1.5 KiB
Makefile
Raw Normal View History

2025-01-01 01:50:26 +00:00
# Directories
FRONTEND_DIR := ./frontend
BACKEND_DIR := ./backend
PUBLIC_DIR := ./public
ASSET_DIR := ./assets
2024-12-29 02:09:53 +00:00
2025-01-01 01:50:26 +00:00
# Commands
ELM_MAKE := elm make
CARGO_BUILD := cargo build
CARGO_RUN := cargo run
# Ensure exactly one of DEBUG or RELEASE is set
2025-01-03 13:07:44 +00:00
ifeq ($(DEBUG)$(RELEASE),) # Both are empty
$(error You must set exactly one of DEBUG=1 or RELEASE=1)
endif
ifeq ($(DEBUG)$(RELEASE),11) # Both are set
$(error Both DEBUG and RELEASE cannot be set at the same time)
endif
2025-01-01 01:50:26 +00:00
# Targets
.PHONY: all frontend backend clean serve
# Ensure PUBLIC_DIR exists
2025-01-03 13:07:44 +00:00
$(PUBLIC_DIR):
mkdir -p $(PUBLIC_DIR)
# Copy index.html into PUBLIC_DIR
2025-01-03 13:07:44 +00:00
$(PUBLIC_DIR)/index.html: $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)
cp $< $@
2025-01-01 01:50:26 +00:00
# Frontend build target
2025-01-03 15:58:40 +00:00
frontend: $(PUBLIC_DIR)/index.html $(PUBLIC_DIR)
mkdir -p $(PUBLIC_DIR)/assets
make -C $(FRONTEND_DIR)
2025-01-01 01:50:26 +00:00
cp $(FRONTEND_DIR)/elm.min.js $(PUBLIC_DIR)/
cp $(FRONTEND_DIR)/src/ports.websocket.js $(PUBLIC_DIR)/
cp $(FRONTEND_DIR)/assets/CourierPrime-Regular.ttf $(PUBLIC_DIR)/assets/
2025-01-01 01:50:26 +00:00
# Backend build target
2025-01-01 01:50:26 +00:00
backend:
ifeq ($(DEBUG),1)
2025-01-01 01:50:26 +00:00
$(CARGO_BUILD) --manifest-path=$(BACKEND_DIR)/Cargo.toml
else ifeq ($(RELEASE),1)
$(CARGO_BUILD) --release --manifest-path=$(BACKEND_DIR)/Cargo.toml
endif
2024-12-29 02:09:53 +00:00
# Clean target (optional, assuming we want to remove build artifacts)
clean:
rm -rf $(PUBLIC_DIR)
# Serve: Runs both frontend and backend
2025-01-03 13:07:44 +00:00
serve: frontend backend
$(MAKE) -C $(FRONTEND_DIR) watch DEBUG=1 & \
FRONTEND_PID=$$!; \
2025-01-30 17:39:22 +00:00
RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml; \
kill $$FRONTEND_PID