forked from aristanetworks/sonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
163 lines (125 loc) · 3.62 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
# tools
PYTHON2 ?= python2
PYTHON3 ?= python3
MKDIR ?= mkdir
CP ?= cp
# envs
KVERSION ?= $(shell uname -r)
KERNEL_SRC ?= /lib/modules/$(KVERSION)/build
KERNEL_DST := /lib/modules/$(KVERSION)
BASE_DIR ?= $(CURDIR)
MODULE_SRC := $(BASE_DIR)/src
TEST_DIR := $(BASE_DIR)/tests
BUILD_DIR := $(BASE_DIR)/build
# sources
BIN_SRC := $(wildcard $(BASE_DIR)/utils/*)
RULE_SRC := $(wildcard $(BASE_DIR)/udev/*)
SERVICE_SRC := $(wildcard $(BASE_DIR)/systemd/*)
# packaging
PACKAGE_NAME ?= arista
PY2_PACKAGE_NAME ?= $(PACKAGE_NAME)
PY3_PACKAGE_NAME ?= $(PACKAGE_NAME)
DESTDIR ?= $(CURDIR)/install
BIN_DESTDIR ?= $(DESTDIR)/usr/bin
DRV_DESTDIR ?= $(DESTDIR)/$(KERNEL_DST)/$(INSTALL_MOD_DIR)
PY2_DESTDIR ?= $(DESTDIR)
PY3_DESTDIR ?= $(DESTDIR)
RULE_DESTDIR ?= $(DESTDIR)/etc/udev/rules.d
SYSTEMD_DESTDIR ?= $(DESTDIR)/lib/systemd/system
# build
PY_BUILD_ARGS ?=
PY2_BUILD_ARGS ?= $(PY_BUILD_ARGS) --build-base=$(BUILD_DIR)/python2
PY3_BUILD_ARGS ?= $(PY_BUILD_ARGS) --build-base=$(BUILD_DIR)/python3
PYLINTRC ?= $(BASE_DIR)/.pylintrc
PYLINT_BLACKLIST ?= $(shell "cat $(BASE_DIR)/.pylint_blacklist | tr '\n' ','")
PYLINT_JOBS ?= 4
# scd
ARISTA_SCD_DRIVER_CONFIG ?= m
export ARISTA_SCD_DRIVER_CONFIG
EXTRA_SYMBOLS := /lib/modules/$(KVERSION)/extra/scd-Module.symvers
export EXTRA_SYMBOLS
# dev
PY2_VENV_PATH ?= venv2
PY3_VENV_PATH ?= venv3
all:
@echo "Nothing to do."
#
# build targets
#
build-drivers:
EXTRA_SYMBOLS=$(EXTRA_SYMBOLS) $(MAKE) -C $(KERNEL_SRC) M=$(MODULE_SRC)
build-py2:
$(PYTHON2) setup.py build $(PY2_BUILD_ARGS)
build-py3:
$(PYTHON3) setup.py build $(PY3_BUILD_ARGS)
build: build-drivers build-py2 build-py3
#
# clean targets
#
clean-drivers:
$(RM) $(MODULE_SRC)/*.o $(MODULE_SRC)/*.ko $(MODULE_SRC)/*.mod.c $(MODULE_SRC)/.*.cmd
$(RM) $(MODULE_SRC)/Module.markers $(MODULE_SRC)/Module.symvers $(MODULE_SRC)/modules.order
$(RM) -r $(MODULE_SRC)/.tmp_versions
clean-py2:
$(PYTHON2) setup.py clean $(PY2_BUILD_ARGS)
find $(BASE_DIR)/arista -name '*.pyc' -delete
clean-py3:
$(PYTHON3) setup.py clean $(PY3_BUILD_ARGS)
find $(BASE_DIR)/arista -name '__pycache__' -exec rm -rf {} +
clean: clean-py2 clean-py3 clean-drivers
distclean: clean
$(RM) -r $(BASE_DIR)/*.egg-info $(BASE_DIR)/build $(BASE_DIR)/install
#
# install targets
#
install-py2:
$(MKDIR) -p $(PY2_DESTDIR)
$(PYTHON2) setup.py install --root=$(PY2_DESTDIR) $(PY_INSTALL_ARGS)
install-py3:
$(MKDIR) -p $(PY3_DESTDIR)
$(PYTHON3) setup.py install --root=$(PY3_DESTDIR) $(PY_INSTALL_ARGS)
install-drivers:
$(MKDIR) -p $(DRV_DESTDIR)
$(CP) $(MODULE_SRC)/*.ko $(DRV_DESTDIR)
install-bin:
$(MKDIR) -p $(BIN_DESTDIR)
$(CP) $(BIN_SRC) $(BIN_DESTDIR)
install-systemd:
$(MKDIR) -p $(SYSTEMD_DESTDIR)
$(CP) $(SERVICE_SRC) $(SYSTEMD_DESTDIR)
install-udev:
$(MKDIR) -p $(RULE_DESTDIR)
$(CP) $(RULE_SRC) $(RULE_DESTDIR)
install-fs: install-bin install-systemd install-udev
install: install-py2 install-py3 install-drivers install-fs
#
# test targets
#
test-py: test-py3
test-py2:
python2 setup.py test
test-py3:
python3 setup.py test
pylint:
# NOTE: for now we only check py2/py3 compatibility.
# once these are solved we should enable the more generic pylint.
# FIXME: make this fatal as soon as possible
-pylint --py3k \
--jobs=$(PYLINT_JOBS) \
--rcfile=$(PYLINTRC) \
--ignore=$(PYLINT_BLACKLIST) \
$(PACKAGE_NAME)
test: test-py2 test-py3 pylint
#
# dev tools
#
$(PY2_VENV_PATH):
virtualenv $@
@echo "source $@/bin/activate"
@echo "python setup.py develop"
$(PY3_VENV_PATH):
$(PYTHON3) -m venv $@
@echo "source $@/bin/activate"
@echo "python setup.py develop"
print-%:
@echo $($*)