blob: ed22aada004eba50bf73ed539ff14ebcd7da9b5a [file] [log] [blame]
# Flags to fidlbolt server.
PORT ?= 8080
VERBOSE ?= 0
# If 0, use files directly from $FUCHSIA_DIR.
# If 1, use files from ./support (see ./copy_support_files.sh).
SUPPORT ?= 0
# Detect host platform.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
HOST_PLATFORM := linux-x64
else ifeq ($(UNAME_S),Darwin)
HOST_PLATFORM := mac-x64
else
$(error Unsupported platform $(UNAME_S))
endif
# Set paths to external resources used by the server.
ifeq ($(SUPPORT),1)
ifeq ($(wildcard support),)
$(error "No ./support directory found. Run ./copy_support_files.sh")
endif
BIN := ./support/bin
ETC := ./support/etc
FIDL := ./support/sdk/fidl:./support/zircon/system/fidl
else
BUILD_DIR := $(FUCHSIA_DIR)/$(file < $(FUCHSIA_DIR)/.fx-build-dir)
RUST_BIN := $(FUCHSIA_DIR)/prebuilt/third_party/rust/$(HOST_PLATFORM)/bin
BIN := $(BUILD_DIR)/host_x64:$(BUILD_DIR).zircon/tools:$(RUST_BIN)
ETC := $(FUCHSIA_DIR)
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 SUPPORT=1 to use files in ./support instead of"
@echo " \$$FUCHSIA_DIR (see ./copy_support_files.sh)."
@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
./$(SERVER) \
-static=frontend/dist \
-bin=$(BIN) \
-etc=$(ETC) \
-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 support/