|
| 1 | +.POSIX: |
| 2 | + |
| 3 | +# Recipes for this Makefile |
| 4 | + |
| 5 | +## Build shards |
| 6 | +## $ make -f Makefile.win |
| 7 | +## Build shards in release mode |
| 8 | +## $ make -f Makefile.win release=1 |
| 9 | +## Run tests |
| 10 | +## $ make -f Makefile.win test |
| 11 | +## Run tests without fossil tests |
| 12 | +## $ make -f Makefile.win test skip_fossil=1 |
| 13 | +## Install shards |
| 14 | +## $ make -f Makefile.win install |
| 15 | +## Uninstall shards |
| 16 | +## $ make -f Makefile.win uninstall |
| 17 | +## Build and install shards |
| 18 | +## $ make -f Makefile.win build && sudo make -f Makefile.win install |
| 19 | + |
| 20 | +release ?= ## Compile in release mode |
| 21 | +debug ?= ## Add symbolic debug info |
| 22 | +static ?= ## Enable static linking |
| 23 | +skip_fossil ?= ## Skip fossil tests |
| 24 | +skip_git ?= ## Skip git tests |
| 25 | +skip_hg ?= ## Skip hg tests |
| 26 | + |
| 27 | +MAKEFLAGS += --no-builtin-rules |
| 28 | +.SUFFIXES: |
| 29 | + |
| 30 | +SHELL := cmd.exe |
| 31 | +CXX := cl.exe |
| 32 | + |
| 33 | +GLOB = $(shell dir $1 /B /S 2>NUL) |
| 34 | +MKDIR = if not exist $1 mkdir $1 |
| 35 | +MV = move /Y $1 $2 |
| 36 | +RM = if exist $1 del /F /Q $1 |
| 37 | + |
| 38 | +CRYSTAL ?= crystal.exe |
| 39 | +SHARDS ?= shards.exe |
| 40 | +override FLAGS += $(if $(release),--release )$(if $(debug),-d )$(if $(static),--static ) |
| 41 | + |
| 42 | +SHARDS_SOURCES = $(call GLOB,src\\*.cr) |
| 43 | +MOLINILLO_SOURCES = $(call GLOB,lib\\molinillo\\src\\*.cr) |
| 44 | +SOURCES = $(SHARDS_SOURCES) $(MOLINILLO_SOURCES) |
| 45 | +TEMPLATES = $(call GLOB,src\\templates\\*.ecr) |
| 46 | + |
| 47 | +SHARDS_CONFIG_BUILD_COMMIT := $(shell git rev-parse --short HEAD) |
| 48 | +SOURCE_DATE_EPOCH := $(shell git show -s --format=%ct HEAD) |
| 49 | +export_vars = $(eval export SHARDS_CONFIG_BUILD_COMMIT SOURCE_DATE_EPOCH) |
| 50 | + |
| 51 | +MOLINILLO_VERSION = $(shell $(CRYSTAL) eval 'require "yaml"; puts YAML.parse(File.read("shard.lock"))["shards"]["molinillo"]["version"]') |
| 52 | +MOLINILLO_URL = "https://github.com/crystal-lang/crystal-molinillo/archive/v$(MOLINILLO_VERSION).tar.gz" |
| 53 | + |
| 54 | +prefix ?= $(or $(ProgramW6432),$(ProgramFiles))\crystal## Install path prefix |
| 55 | +BINDIR ?= $(prefix) |
| 56 | + |
| 57 | +.PHONY: all |
| 58 | +all: build |
| 59 | + |
| 60 | +.PHONY: build |
| 61 | +build: bin\shards.exe |
| 62 | + |
| 63 | +.PHONY: clean |
| 64 | +clean: ## Remove build artifacts |
| 65 | +clean: |
| 66 | + $(call RM,"bin\shards.exe") |
| 67 | + |
| 68 | +bin\shards.exe: $(SOURCES) $(TEMPLATES) lib |
| 69 | + @$(call MKDIR,"bin") |
| 70 | + $(call export_vars) |
| 71 | + $(CRYSTAL) build $(FLAGS) -o bin\shards.exe src\shards.cr |
| 72 | + |
| 73 | +.PHONY: install |
| 74 | +install: ## Install shards |
| 75 | +install: bin\shards.exe |
| 76 | + $(call MKDIR,"$(BINDIR)") |
| 77 | + $(call INSTALL,"bin\shards.exe","$(BINDIR)\shards.exe") |
| 78 | + $(call INSTALL,"bin\shards.pdb","$(BINDIR)\shards.pdb") |
| 79 | + |
| 80 | +.PHONY: uninstall |
| 81 | +uninstall: ## Uninstall shards |
| 82 | +uninstall: |
| 83 | + $(call RM,"$(BINDIR)\shards.exe") |
| 84 | + $(call RM,"$(BINDIR)\shards.pdb") |
| 85 | + |
| 86 | +.PHONY: test |
| 87 | +test: ## Run all tests |
| 88 | +test: test_unit test_integration |
| 89 | + |
| 90 | +.PHONY: test_unit |
| 91 | +test_unit: ## Run unit tests |
| 92 | +test_unit: lib |
| 93 | + $(CRYSTAL) spec $(if $(skip_fossil),--tag ~fossil )$(if $(skip_git),--tag ~git )$(if $(skip_hg),--tag ~hg ).\spec\unit |
| 94 | + |
| 95 | +.PHONY: test_integration |
| 96 | +test_integration: ## Run integration tests |
| 97 | +test_integration: bin\shards.exe |
| 98 | + $(CRYSTAL) spec .\spec\integration |
| 99 | + |
| 100 | +lib: shard.lock |
| 101 | + $(call MKDIR,"lib\molinillo") |
| 102 | + $(SHARDS) install || (curl -L $(MOLINILLO_URL) | tar -xzf - -C lib\molinillo --strip-components=1) |
| 103 | + |
| 104 | +shard.lock: shard.yml |
| 105 | + if not "$(SHARDS)" == "false" $(SHARDS) update |
| 106 | + |
| 107 | +.PHONY: help |
| 108 | +help: ## Show this help |
| 109 | + @setlocal EnableDelayedExpansion &\ |
| 110 | + echo. &\ |
| 111 | + echo targets: &\ |
| 112 | + (for /F "usebackq tokens=1* delims=:" %%g in ($(MAKEFILE_LIST)) do (\ |
| 113 | + if not "%%h" == "" (\ |
| 114 | + set "_line=%%g " &\ |
| 115 | + set "_rest=%%h" &\ |
| 116 | + set "_comment=!_rest:* ## =!" &\ |
| 117 | + if not "!_comment!" == "!_rest!"\ |
| 118 | + if "!_line:_rest=!" == "!_line!"\ |
| 119 | + echo !_line:~0,17!!_comment!\ |
| 120 | + )\ |
| 121 | + )) &\ |
| 122 | + echo. &\ |
| 123 | + echo optional variables: &\ |
| 124 | + (for /F "usebackq tokens=1,3 delims=?#" %%g in ($(MAKEFILE_LIST)) do (\ |
| 125 | + if not "%%h" == "" (\ |
| 126 | + set "_var=%%g " &\ |
| 127 | + echo !_var:~0,15! %%h\ |
| 128 | + )\ |
| 129 | + )) &\ |
| 130 | + echo. &\ |
| 131 | + echo recipes: &\ |
| 132 | + (for /F "usebackq tokens=* delims=" %%g in ($(MAKEFILE_LIST)) do (\ |
| 133 | + set "_line=%%g" &\ |
| 134 | + if "!_line:~0,7!" == "## $$ " (\ |
| 135 | + echo !_name! &\ |
| 136 | + echo !_line:~2!\ |
| 137 | + ) else if "!_line:~0,3!" == "## "\ |
| 138 | + set "_name= !_line:~3!"\ |
| 139 | + )) |
0 commit comments