-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
149 lines (110 loc) · 5.3 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Makefile for assisting with some common development activities
PYTHON ?= $(shell pyenv which python 2>/dev/null || echo python)
DOCKER ?= $(shell command -v docker 2>/dev/null || docker)
PREFIX ?= /usr/local
.PHONY: build-deps cbuildwheel check install install-deps libphsh sdist test wheel
#: Quickly generate binary wheel
wheel: install-deps
$(PYTHON) setup.py build bdist_wheel
#: Meta target, will attempt to build all it can
build: sdist
if command -v docker 1>/dev/null; then $(MAKE) cibuildwheel; else $(MAKE) wheel; fi
#: Build a matrix of wheels for different OSs and CPU archs
cibuildwheel: build-deps $(DOCKER)
$(PYTHON) -m cibuildwheel --platform=auto --output-dir=dist .
#: Create source distributions
sdist: build-deps
$(PYTHON) build --sdist --no-isolation --formats=zip,tar
#: Install build dependencies
build-deps:
$(PYTHON) -m pip install build cibuildwheel
#: Install setup_requires dependencies
install-deps:
$(PYTHON) -m pip install wheel numpy setuptools \
'meson; python_version >= "3.5"' ninja pytest scikit-build
#: Install library into current virtualenv
pip-install:
$(PYTHON) -m pip install .
libphsh.cmake:
cmake -S . -B build \
-DPYTHON_INCLUDE_DIR="$$($(PYTHON) -c "import sysconfig; print(sysconfig.get_path('include'))")" \
-DPYTHON_LIBRARY="$$($(PYTHON) -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")"
FFLAGS="-fallow-argument-mismatch -std=f95" \
cmake --build build
#: Build the f2py wrapped libphsh shared library within source tree
libphsh:
$(PYTHON) setup.py build_ext --inplace
#: Perform checks
check: libphsh
$(PYTHON) -m pytest tests/ --verbose
test: check
#: Remove any artifacts
clean:
rm -rf build dist _skbuild \
phaseshifts/lib/libphshmodule.c phaseshifts/lib/libphsh-f2pywrappers.f \
phaseshifts/lib/libphsh*.so phaseshifts/lib/libphsh*.pyd
rm -rf phaseshifts/lib/phshift2007 phaseshifts/lib/phshift2007.zip
#: Build docker image
docker:
export DOCKER_TAG="$${DOCKER_TAG:-$$($(PYTHON) -c 'import phaseshifts; print(phaseshifts.__version__)')}" && \
$(DOCKER) build \
-t "ghcr.io/liam-deacon/phaseshifts:$$DOCKER_TAG" \
-f dockerfiles/phaseshifts-phsh.dockerfile .
PHSHIFT2007_BUILD_ROOT ?= phaseshifts/lib/phshift2007
#: Obtain a copy of the phshift2007 package
phaseshifts/lib/phshift2007.zip:
curl -sL -o "$@" "https://www.icts.hkbu.edu.hk/VanHove_files/leed/phshift2007.zip" || (rm -f "$@" && false)
#: Extract the phshift2007 package
$(PHSHIFT2007_BUILD_ROOT): phaseshifts/lib/phshift2007.zip
unzip -o -d "$@" "$<"
$(PHSHIFT2007_BUILD_ROOT)/psprog.ab3: $(PHSHIFT2007_BUILD_ROOT)
$(PHSHIFT2007_BUILD_ROOT)/psprog.ab4: $(PHSHIFT2007_BUILD_ROOT)
# NOTE: Using awk is crude way of splitting the file as it looses comment lines before the program statement
#: Obtain phsh0.for by splitting psprog.ab3 into separate files
$(PHSHIFT2007_BUILD_ROOT)/phsh0.for: $(PHSHIFT2007_BUILD_ROOT)/psprog.ab3
awk -v dir="$(@D)/" '/C program / {filename = dir tolower($$3)}; filename && NF {if (prev) print prev >filename; print $$0 >filename}' "$<"
#: Obtain phsh1.for by splitting psprog.ab3 into separate files
$(PHSHIFT2007_BUILD_ROOT)/phsh1.for: $(PHSHIFT2007_BUILD_ROOT)/phsh0.for
#: Obtain phsh2cav.for by splitting psprog.ab4 into separate files
$(PHSHIFT2007_BUILD_ROOT)/phsh2cav.for: $(PHSHIFT2007_BUILD_ROOT)/psprog.ab4
awk -v dir="$(@D)/" '/C program / {filename = dir tolower($$3)}; filename && NF {if (prev) print prev >filename; print $$0 >filename}' "$<"
#: Obtain phsh2rel.for by splitting psprog.ab4 into separate files
$(PHSHIFT2007_BUILD_ROOT)/phsh2rel.for: $(PHSHIFT2007_BUILD_ROOT)/phsh2cav.for
#: Obtain phsh2wil.for by splitting psprog.ab4 into separate files
$(PHSHIFT2007_BUILD_ROOT)/phsh2wil.for: $(PHSHIFT2007_BUILD_ROOT)/phsh2cav.for
#: Obtain phsh3.for by splitting psprog.ab4 into separate files
$(PHSHIFT2007_BUILD_ROOT)/phsh3.for: $(PHSHIFT2007_BUILD_ROOT)/phsh2cav.for
# GFortran compiler flags
GFORTRAN_FLAGS ?= -Wall -Wno-unused-label -Wno-tabs -Wno-unused-variable -Wno-unused-dummy-argument -fcheck=bounds -frecursive -std=legacy -pie
GFORTRAN_FLAGS += -static-libgcc -static-libgfortran
GFORTRAN ?= $(shell command -v gfortran 2>/dev/null || echo gfortran)
#: Build the hartfock program
bin/phsh0: $(PHSHIFT2007_BUILD_ROOT)/phsh0.for
@mkdir -p "$(@D)"
$(GFORTRAN) $(GFORTRAN_FLAGS) -o "$@" "$<"
#: Build the cavpot program
bin/phsh1: $(PHSHIFT2007_BUILD_ROOT)/phsh1.for
@mkdir -p "$(@D)"
$(GFORTRAN) $(GFORTRAN_FLAGS) -o "$@" "$<"
#: Build the william's phase shift program
bin/phsh2wil: $(PHSHIFT2007_BUILD_ROOT)/phsh2wil.for
@mkdir -p "$(@D)"
$(GFORTRAN) $(GFORTRAN_FLAGS) -o "$@" "$<"
#: Build the CAVLEED phase shift program
bin/phsh2cav: $(PHSHIFT2007_BUILD_ROOT)/phsh2cav.for
@mkdir -p "$(@D)"
$(GFORTRAN) $(GFORTRAN_FLAGS) -o "$@" "$<"
#: Build the relativistic phase shift program
bin/phsh2rel: $(PHSHIFT2007_BUILD_ROOT)/phsh2rel.for
@mkdir -p "$(@D)"
$(GFORTRAN) $(GFORTRAN_FLAGS) -o "$@" "$<"
#: Build the conphas program
bin/phsh3: $(PHSHIFT2007_BUILD_ROOT)/phsh3.for
@mkdir -p "$(@D)"
$(GFORTRAN) $(GFORTRAN_FLAGS) -o "$@" "$<"
.PHONY: phshift2007
#: Build the phshift2007 package (meta target)
phshift2007: bin/phsh0 bin/phsh1 bin/phsh2wil bin/phsh2cav bin/phsh2rel bin/phsh3
#: Install the phshift2007 programs
install: phshift2007
install -m 755 bin/phsh0 bin/phsh1 bin/phsh2wil bin/phsh2cav bin/phsh2rel bin/phsh3 "$(PREFIX)/bin"