example-spa-elm-app/Makefile

57 lines
1.3 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
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
2025-01-03 13:07:44 +00:00
$(PUBLIC_DIR):
mkdir -p $(PUBLIC_DIR)
$(PUBLIC_DIR)/index.html: $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)
cp $< $@
2025-01-01 01:50:26 +00:00
2025-01-03 13:07:44 +00:00
$(FRONTEND_DIR)/elm.min.js:
ifeq ($(DEBUG),1)
make -C $(FRONTEND_DIR) DEBUG=1
else ifeq ($(RELEASE),1)
make -C $(FRONTEND_DIR) RELEASE=1
endif
.PHONY: frontend backend
frontend: $(PUBLIC_DIR)/index.html $(FRONTEND_DIR)/elm.min.js $(PUBLIC_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)/
mkdir -p $(PUBLIC_DIR)/assets
backend:
$(CARGO_BUILD) --manifest-path=$(BACKEND_DIR)/Cargo.toml
2024-12-29 02:09:53 +00:00
2025-01-03 13:07:44 +00:00
serve: frontend backend
ifeq ($(DEBUG),1)
2025-01-01 01:50:26 +00:00
RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml
2025-01-03 13:07:44 +00:00
else ifeq ($(RELEASE),1)
$(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml
endif
2025-01-01 01:50:26 +00:00
clean:
rm -rf $(PUBLIC_DIR)/*
rm -rf $(BACKEND_DIR)/target
2024-12-29 02:09:53 +00:00