example-spa-elm-app/Makefile
2025-02-02 17:39:04 -05:00

57 lines
1.5 KiB
Makefile

# Directories
FRONTEND_DIR := ./frontend
BACKEND_DIR := ./backend
PUBLIC_DIR := ./public
ASSET_DIR := ./assets
# Commands
ELM_MAKE := elm make
CARGO_BUILD := cargo build
CARGO_RUN := cargo run
# Ensure exactly one of DEBUG or RELEASE is set
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
# Targets
.PHONY: all frontend backend clean serve
# Ensure PUBLIC_DIR exists
$(PUBLIC_DIR):
mkdir -p $(PUBLIC_DIR)
# Copy index.html into PUBLIC_DIR
$(PUBLIC_DIR)/index.html: $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)
cp $< $@
# Frontend build target
frontend: $(PUBLIC_DIR)/index.html $(PUBLIC_DIR)
mkdir -p $(PUBLIC_DIR)/assets
make -C $(FRONTEND_DIR)
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/
# Backend build target
backend:
ifeq ($(DEBUG),1)
$(CARGO_BUILD) --manifest-path=$(BACKEND_DIR)/Cargo.toml
else ifeq ($(RELEASE),1)
$(CARGO_BUILD) --release --manifest-path=$(BACKEND_DIR)/Cargo.toml
endif
# Clean target (optional, assuming we want to remove build artifacts)
clean:
rm -rf $(PUBLIC_DIR)
# Serve: Runs both frontend and backend
serve: frontend backend
$(MAKE) -C $(FRONTEND_DIR) watch DEBUG=1 & \
FRONTEND_PID=$$!; \
RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml; \
kill $$FRONTEND_PID