This repository has been archived by the owner on Nov 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
185 lines (152 loc) · 5.54 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
#
# Copyright (c) 2018 Google LLC.
# Copyright (c) 2016-2017 Nest Labs, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Binaries used by this makefile
DPKG ?= $(shell which dpkg 2> /dev/null)
MAKE ?= make
PEP8_LINT ?= pep8
PEP8_LINT_ARGS ?= --max-line-length=132
PYTHON ?= python3
PYTHON_VERSION ?= $(shell $(PYTHON) -c "import sys; sys.stdout.write(sys.version[:3])")
SUDO ?= sudo
# The list of Debian packages on which Happy depends which must be
# installed before Happy may be used.
DPKG_PREREQUISITES := \
bridge-utils \
net-tools \
python3-lockfile \
python3-pip \
python3-psutil \
python3-setuptools \
$(NULL)
# check-dpkg-prequisite <package>
#
# Determines and verbosely reports whether the specified Debian
# package is installed or not, exiting with the appropriate status.
define check-dpkg-prerequisite
@echo -n "Checking for $(1)...";
@if `$(DPKG) -s $(1) > /dev/null 2>&1`; then \
echo "ok"; \
else \
echo "failed"; \
echo "The package '$(1)' is required and is not installed. Please run 'sudo apt-get install $(1)' to install it."; \
exit 1; \
fi
endef
check_TARGETS = $(addprefix check-dpkg-,$(DPKG_PREREQUISITES))
check-dpkg-%: $(DPKG)
$(call check-dpkg-prerequisite,$(*))
all: install
check-prerequisites: $(check_TARGETS)
# If HAPPY_PATH defined, install or uninstall the specific, $HAPPY_PATH,
# location of the Happy package. If HAPPY_PATH is not defined, by default
# install Happy into Python's system with install-system.
install: check-prerequisites
ifeq ($(HAPPY_PATH),)
$(MAKE) install-system
else
$(MAKE) install-path
endif
uninstall:
ifeq ($(HAPPY_PATH),)
$(MAKE) uninstall-system
else
$(MAKE) uninstall-path
endif
# Install Happy into Python's shared library in a developed version.
# Develop version instead of copying Happy package into /usr/local/lib ...,
# creates a reference to the Happy source directory. This allows a developer
# to modify Happy modules and test them without reinstalling Happpy.
install-develop: check-prerequisites
# Installing Happy for development
$(SUDO) $(PYTHON) setup.py develop
$(MAKE) link
uninstall-develop:
$(SUDO) $(PYTHON) setup.py develop --uninstall
$(MAKE) unlink
$(MAKE) clean
# Install Happy into a user's home directory (~/.local). This allows a user
# to install Happy without requiring root privilages. The installed Happy
# package is only visible to the user that installed it; other same system's
# users cannot find Happy package unless they install it as well.
install-user: check-prerequisites
# Installing Happy into user home directory
$(PYTHON) setup.py install --user
@echo
@echo "Happy package installed into users ~/.local/lib/*"
@echo "Happy shell scripts are not installed into the system."
@echo "To use happy shell scripts, add happy bin/ into PATH."
@echo
uninstall-user:
rm -rf ~/.local/lib/python$(PYTHON_VERSION)/site-packages/happy*.egg
# Install Happy into Python system-wide distribution packages. This installation
# requires root privilages. After installation every user in the system can
# use Happy package.
install-system: check-prerequisites
# Installing Happy
$(SUDO) $(PYTHON) setup.py install
$(SUDO) chmod o+r `find /usr/local/lib -name main_config.json`
$(SUDO) chmod o+r `find /usr/local/lib -name log_config.json`
$(MAKE) link
uninstall-system:
$(MAKE) unlink
$(MAKE) clean
$(SUDO) rm -rf /usr/local/lib/python$(PYTHON_VERSION)/dist-packages/happy-*egg
# Install Happy package into non-standard location. Because the installed package
# location is not know to Python, the package path must be passed to PYTHON through
# PYTHONPATH environment variable. To install Happy under /some/path run:
# make HAPPY_PATH=/some/path
# This will create /some/path/lib/pythonX.X/site-packages location and install
# the happy package over there.
install-path: check-prerequisites
ifeq ($(HAPPY_PATH),)
@echo Variable HAPPY_PATH not set. && false
endif
mkdir -p $(HAPPY_PATH)/lib/python$(PYTHON_VERSION)/site-packages/; \
export PYTHONPATH="$(HAPPY_PATH)/lib/python$(PYTHON_VERSION)/site-packages/" ;\
$(PYTHON) setup.py install --prefix=$(HAPPY_PATH)
@echo
@echo "Using custom path for a Python package is unusual."
@echo "Remember to update PYTHONPATH for every environment that will use this package, thus run"
@echo "export PYTHONPATH=$$PYTHONPATH:"$(HAPPY_PATH)/lib/python$(PYTHON_VERSION)/site-packages/""
@echo
$(MAKE) link
uninstall-path:
ifeq ($(HAPPY_PATH),)
@echo Variable HAPPY_PATH not set. && false
endif
$(MAKE) unlink
rm -rf $(HAPPY_PATH)
distribution-build: clean
# creates a built distribution
$(PYTHON) setup.py bdist
distribution-source: clean
# creates a source distribution
$(PYTHON) setup.py sdist
distribution: distribution-build distribution-source
release: distribution
link:
$(MAKE) link -C bin
unlink:
$(MAKE) unlink -C bin
clean:
$(MAKE) clean -C happy
$(SUDO) rm -rf *.egg*
$(SUDO) rm -rf dist
$(SUDO) rm -rf build
pretty-check:
$(PEP8_LINT) $(PEP8_LINT_ARGS) .