Makefile 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. BIN := venv/bin/activate
  2. PYTHON := /opt/tools/python/bin/python3.12
  3. all: $(BIN)
  4. # Create the virtual environment and install dependencies
  5. $(BIN): requirements.txt
  6. @echo "Installing dependencies..."
  7. @if [ ! -d venv ]; then \
  8. $(PYTHON) -m venv venv; \
  9. fi; \
  10. . venv/bin/activate && pip install -r requirements.txt
  11. # Start the Flask server for the specified network (localnet, testnet, mainnet)
  12. start-%: all
  13. @if [ "$*" != "localnet" ] && [ "$*" != "testnet" ] && [ "$*" != "mainnet" ]; then \
  14. echo "Error: Unsupported environment '$*'. Supported values are 'localnet', 'testnet', and 'mainnet'."; \
  15. exit 1; \
  16. fi
  17. @if [ -f flask.pid ]; then \
  18. echo "Flask server is already running (PID=$$(cat flask.pid)). Stop it first before starting."; \
  19. exit 1; \
  20. fi
  21. @. venv/bin/activate && \
  22. FLASK_ENV=$* python -m flask run & PID=$$!; \
  23. echo $$PID > flask.pid; \
  24. echo "Started flask server on $* network (PID=$$PID)"
  25. # Stop the Flask server if running
  26. stop-server:
  27. @if [ -f flask.pid ]; then \
  28. PID=$$(cat flask.pid); \
  29. kill $$PID; \
  30. rm -f flask.pid; \
  31. echo "Stopped Flask server"; \
  32. else \
  33. echo "Flask server is not running, nothing to stop."; \
  34. fi
  35. # Install dependencies (alias for 'all')
  36. install: all
  37. # Remove virtual environment
  38. clean:
  39. @rm -rf venv
  40. @echo "Cleaned the virtual environment!"
  41. # Declare PHONY targets
  42. .PHONY: all start-% install clean stop-server