-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
80 lines (58 loc) · 2.07 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
release ?= ## Compile in release mode
stats ?= ## Enable statistics output
threads ?= ## Maximum number of threads to use
debug ?= ## Add symbolic debug info
no-debug ?= ## No symbolic debug info
verbose ?= ## Run specs in verbose mode
link-flags ?= ## Additional flags to pass to the linker
# OS := $(shell uname -s | tr '[:upper:@]' '[:lower:]')
O := build
FLAGS := $(if $(release),--release )$(if $(stats),--stats )$(if $(threads),--threads $(threads) )$(if $(debug),-d )$(if $(no-debug),--no-debug )$(if $(link-flags),--link-flags "$(link-flags)" )
VERBOSE := $(if $(verbose),-v )
SHELL = bash
## Use mpicc wrapper rather than the system C compiler.
CC = mpicc
CFLAGS += -fPIC
CFLAGS += $(if $(debug),-g -O0)
CFLAGS += $(if $(release),-O2)
LIB_CRMPI = src/ext/crmpi.c
LIB_CRMPI_OBJ = $(subst .c,.o,$(LIB_CRMPI))
LIB_CRMPI_TARGET = src/ext/libcrmpi.a
BIN_CRMPI = src/ext/mpi_vendor.c
BIN_CRMPI_OBJ = $(BIN_CRMPI:.c=.o)
BIN_CRMPI_TARGET = src/ext/mpi_vendor
DEPS = $(LIB_CRMPI_TARGET) $(BIN_CRMPI_TARGET)
EXAMPLES_SOURCES := $(shell find examples -name '*.cr')
EXAMPLES_TARGETS := $(subst examples, $(O), $(patsubst %.cr, %, $(EXAMPLES_SOURCES)))
.PHONY: all
all: deps
.PHONY: deps libcrmpi mpivendor
deps: $(DEPS) ## Build dependencies
libcrmpi: $(LIB_CRMPI_TARGET)
$(LIB_CRMPI_TARGET): $(LIB_CRMPI_OBJ)
$(AR) -rcs $@ $^
mpivendor: $(BIN_CRMPI_TARGET)
$(BIN_CRMPI_OBJ): $(BIN_CRMPI)
$(CC) -o $@ -c $< $(CFLAGS)
$(BIN_CRMPI_TARGET): $(BIN_CRMPI_OBJ)
$(CC) -o $@ $^
$(EXAMPLES_TARGETS):
@mkdir -p $(O)
$(BUILD_PATH) crystal build $(FLAGS) $(addsuffix .cr, $(subst build, examples, $@)) -o $@
.PHONY: doc
doc: deps ## Generate mpi.cr library documentation
@echo "Building documentation..."
$(BUILD_PATH) crystal doc src/mpi.cr
.PHONY: examples
examples: $(DEPS) $(EXAMPLES_TARGETS)
.PHONY: spec ## Run specs
spec: examples
$(BUILD_PATH) crystal spec $(FLAGS)
sh ci/run-examples.sh
.PHONY: clean
clean: ## Clean up built directories and files
@echo "Cleaning..."
rm -rf $(O)
rm -rf ./doc
rm -rf $(LIB_CRMPI_OBJ) $(LIB_CRMPI_TARGET)
rm -rf $(BIN_CRMPI_OBJ) $(BIN_CRMPI_TARGET)