forked from mmz-srf/ipam-migrator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
220 lines (158 loc) · 4.81 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/make -f
# -*- makefile -*-
#
# IPAM database migration script
# Makefile - Build system
#
# Copyright (c) 2017 Catalyst.net Ltd
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################
#
# Makefile arguments
# ------------------
#
# Any of the parameters in this Makefile can be overridden on the command line.
# Some variables are designed to be used like this, to provide optional
# parameters.
#
# Use them like so:
# $ make install <KEY>=<VALUE>
#
# Examples:
# - install ipam-migrator to a virtualenv and configuration in /opt,
# with a systemd unit installed to standard directories:
# $ make install systemd-install \
# VIRTUALENV="/opt/venv/ipam-migrator"
#
##############################
#
## Build system parameters.
#
# Parameters that can be changed.
ifdef VIRTUALENV
PREFIX = $(VIRTUALENV)
else
PREFIX = /usr/local
endif
BIN_DIR = $(PREFIX)/bin
TEST_PRESERVE_TMP_DIR = 0
# Template file variable list.
PARAMS = PREFIX ETC_DIR BIN_DIR CONFIG_DIR SERVICE_ETC_DIR SERVICE_VAR_RUN_DIR SERVICE_SYSTEMD_DIR
# Internal Makefile parameters that (normally) should not be changed.
INSTALL_SCRIPTS = $(BIN_DIR)
##############################
#
## setup.py parameters.
#
ifdef PREFIX
SETUP_PY_PREFIX = --prefix=$(PREFIX)
endif
ifdef INSTALL_SCRIPTS
SETUP_PY_INSTALL_SCRIPTS = --install-scripts=$(INSTALL_SCRIPTS)
endif
ifdef INSTALL_DATA
SETUP_PY_INSTALL_DATA = --install-data=$(INSTALL_DATA)
endif
ifdef INSTALL_LIB
SETUP_PY_INSTALL_LIB = --install-lib=$(INSTALL_LIB)
endif
##############################
#
## Build system files and directories.
#
SETUP_PY = setup.py
TEMPLATE_PROCESS_PY = template_process.py
SRC_DIR = src
TEST_SRC_DIR = tests
TEST_TMP_DIR = .tests
##############################
#
## Commands.
#
# Detect usable Python command, if not defined by the user.
ifndef PYTHON
PYTHON_MAJOR_VER = $(shell python3 -V | sed 's:^Python \([0-9][0-9]*\)\..*$$:\1:')
PYTHON_MINOR_VER = $(shell python3 -V | sed 's:^Python [0-9][0-9]*\.\([0-9][0-9]*\)\..*$$:\1:')
ifeq ($(shell test $(PYTHON_MAJOR_VER) -eq 3 -a $(PYTHON_MINOR_VER) -ge 4 && echo true), true)
PYTHON = $(shell which python3)
endif
endif
ifndef PYTHON
PYTHON = $(shell which python3.5)
endif
ifndef PYTHON
PYTHON = $(shell which python3.4)
endif
ifndef PYTHON
$(error ipam-migrator only supports Python >= 3.4.0)
endif
# Python tools.
PYLINT = pylint
PIP = pip3
# An alternative to this if the default doesn't work:
# PIP = $(PYTHON) -m pip
# System commands.
FIND = find
INSTALL = install
RM = rm -f
RMDIR = rm -rf
##############################
#
## Targets.
#
all:
@echo "ipam-migrator make targets:"
@echo " lint - run pylint code quality check"
@echo " test - run unit tests"
@echo
@echo " sdist - build Python source distribution"
@echo " bdist_wheel - build Python binary wheel distribution"
@echo
@echo " install - build and install to local system"
@echo " systemd-install - generate and install a systemd unit file"
@echo " sysv-install - generate and install a SysV init script"
@echo " upstart-install - generate and install an Upstart configuration file"
@echo
@echo " uninstall - uninstall from local system"
@echo " clean - clean build files"
@echo "See 'Makefile' for more details."
lint:
$(PYLINT) $(SRC_DIR)/ipam_migrator --disable=duplicate-code 2>&1 | tee make-lint.log
@echo "pylint output written to make-lint.log"
test:
$(PYTHON) $(TEST_SRC_DIR)/tests/__init__.py
test -z $(TEST_PRESERVE_TMP_DIR) && rm -rf $(TEST_TMP_DIR) || true
test-lint:
$(PYLINT) $(TEST_SRC_DIR)/tests --disable=duplicate-code 2>&1 | tee make-test-lint.log
@echo "pylint output written to make-test-lint.log"
sdist:
$(PYTHON) $(SETUP_PY) sdist
bdist_wheel:
$(PYTHON) $(SETUP_PY) bdist_wheel
install:
$(PYTHON) $(SETUP_PY) install $(SETUP_PY_PREFIX) $(SETUP_PY_INSTALL_LIB) $(SETUP_PY_INSTALL_SCRIPTS) $(SETUP_PY_INSTALL_DATA)
uninstall:
$(PIP) uninstall -y ipam_migrator
clean:
$(RM) make-lint.log
$(RMDIR) .tests
$(RMDIR) build
$(RMDIR) dist
$(RMDIR) src/ipam_migrator.egg-info
for d in $(shell $(FIND) -name '__pycache__'); do \
$(RMDIR) $$d; \
done
.FORCE:
.PHONY: all lint test sdist bdist_wheel install default-install systemd-install sysv-install upstart-install uninstall clean .FORCE