blob: 5b5ac0bcfc3798bfae340271eb76cdc90341b283 [file] [log] [blame]
# Flags to fidlbolt server.
PORT ?= 8080
VERBOSE ?= 0
# Whether to run the server against copied fuchsia files.
COPY ?= 0
# Paths to FIDL files and binaries (either copies or in-tree paths).
ifeq ($(COPY),1)
BIN := ./fuchsia/bin
FIDL := ./fuchsia/sdk/fidl:fuchsia/zircon/system/fidl
else
BUILD_DIR := $(FUCHSIA_DIR)/$(file < $(FUCHSIA_DIR)/.fx-build-dir)
BIN := $(BUILD_DIR)/host_x64:$(BUILD_DIR).zircon/tools
FIDL := $(FUCHSIA_DIR)/sdk/fidl:$(FUCHSIA_DIR)/zircon/system/fidl
endif
# Path to the server binary.
SERVER := backend/dist/fidlbolt
.PHONY: all help frontend backend run format clean
all: frontend backend
help:
@echo "Targets:"
@echo " all Build everything."
@echo " help Show this help message."
@echo " frontend Build the frontend/dist bundle using webpack."
@echo " For more build options: cd frontend && npm run."
@echo " backend Build the $(SERVER) server binary."
@echo " run Run the fidlbolt server on \$$PORT."
@echo " Set VERBOSE=1 to enable verbose logging."
@echo " Set COPY=1 to use copy_fuchsia_files.sh instead"
@echo " of referencing the fuchsia tree at runtime."
@echo " Note: rebuilds targets only if they do not exist."
@echo " To ensure an up-to-date server: make && make run."
@echo " format Auto-format all code."
@echo " clean Remove all generated files."
frontend: frontend/dist
frontend/node_modules: frontend/package*.json
cd frontend && npm ci
frontend/dist: frontend/node_modules frontend/src/* frontend/src/elm/*
cd frontend && npm run build
backend: $(SERVER)
$(SERVER): backend/go.mod backend/*.go
cd backend && go build -o ../$@
run: $(if $(wildcard frontend/dist),,frontend)
run: $(if $(wildcard $(SERVER)),,backend)
ifndef FUCHSIA_DIR
$(error FUCHSIA_DIR is not defined. Either pass in FUCHSIA_DIR="path" or define the variable.)
endif
ifeq ($(COPY),1)
./copy_fuchsia_files.sh
endif
./$(SERVER) \
-static=frontend/dist \
-bin=$(BIN) \
-fidl=$(FIDL) \
-port=$(PORT) \
-verbose=$(VERBOSE)
format:
cd frontend && npm run fix
cd backend && go fmt
clean:
rm -rf backend/dist/
rm -rf frontend/dist/
rm -rf fuchsia/