|
| 1 | +# Copyright (C) 2020 The SymbiFlow Authors. |
| 2 | +# |
| 3 | +# Use of this source code is governed by a ISC-style |
| 4 | +# license that can be found in the LICENSE file or at |
| 5 | +# https://opensource.org/licenses/ISC |
| 6 | +# |
| 7 | +# SPDX-License-Identifier: ISC |
| 8 | + |
| 9 | +.SUFFIXES: |
| 10 | + |
| 11 | +MAKE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) |
| 12 | + |
| 13 | +SHELL := bash |
| 14 | + |
| 15 | +# Makefile for downloading and creating environments (with tools like conda). |
| 16 | + |
| 17 | +# Usage |
| 18 | +# - Set TOP_DIR to the top directory where environment will be created. |
| 19 | +# - Set REQUIREMENTS_FILE to a pip `requirements.txt` file. |
| 20 | +# - Set ENVIRONMENT_FILE to a conda `environment.yml` file. |
| 21 | +# - Put $(IN_ENV) before commands which should run inside the |
| 22 | +# environment. |
| 23 | + |
| 24 | +# Configuration |
| 25 | +ifeq (,$(TOP_DIR)) |
| 26 | +$(error "Set TOP_DIR value before including 'env.mk'.") |
| 27 | +endif |
| 28 | + |
| 29 | +ifeq (,$(REQUIREMENTS_FILE)) |
| 30 | +$(error "Set REQUIREMENTS_FILE value before including 'conda.mk'.") |
| 31 | +else |
| 32 | +REQUIREMENTS_FILE := $(abspath $(REQUIREMENTS_FILE)) |
| 33 | +endif |
| 34 | +ifeq (,$(wildcard $(REQUIREMENTS_FILE))) |
| 35 | +$(error "REQUIREMENTS_FILE ($(REQUIREMENTS_FILE)) does not exist!?") |
| 36 | +endif |
| 37 | + |
| 38 | +ifeq (,$(ENVIRONMENT_FILE)) |
| 39 | +$(error "Set ENVIRONMENT_FILE value before including 'conda.mk'.") |
| 40 | +ENVIRONMENT_FILE := $(abspath $(ENVIRONMENT_FILE)) |
| 41 | +endif |
| 42 | +ifeq (,$(wildcard $(ENVIRONMENT_FILE))) |
| 43 | +$(error "ENVIRONMENT_FILE ($(ENVIRONMENT_FILE)) does not exist!?") |
| 44 | +endif |
| 45 | + |
| 46 | +# Default to conda if no other option is provided. |
| 47 | +ifeq (,$(ENV)) |
| 48 | +ENV := conda |
| 49 | +endif |
| 50 | + |
| 51 | +ifeq (,$(wildcard $(MAKE_DIR)/$(ENV).mk)) |
| 52 | +$(error Unknown environment provider (ENV='$(ENV)')?) |
| 53 | +endif |
| 54 | + |
| 55 | +export ENV |
| 56 | +UENV := $(shell echo $${ENV^^}) |
| 57 | + |
| 58 | +include $(MAKE_DIR)/$(ENV).mk |
| 59 | + |
| 60 | +ENV_PYTHON := $($(UENV)_ENV_PYTHON) |
| 61 | +IN_ENV := $(IN_$(UENV)_ENV) |
| 62 | + |
| 63 | +clean:: |
| 64 | + true |
| 65 | + |
| 66 | +.PHONY: clean |
| 67 | + |
| 68 | +dist-clean:: |
| 69 | + true |
| 70 | + |
| 71 | +.PHONY: dist-clean |
| 72 | + |
| 73 | +enter: | $(ENV_PYTHON) |
| 74 | + $(IN_ENV) bash |
| 75 | + |
| 76 | +.PHONY: enter |
| 77 | + |
| 78 | +info: | $(ENV_PYTHON) |
| 79 | + @$(IN_ENV) $(MAKE) --no-print-directory env-info |
| 80 | + |
| 81 | +.PHONY: info |
0 commit comments