-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
317 lines (277 loc) · 12.2 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#
# Copyright 2017 by Kvaser AB, Molndal, Sweden
# http://www.kvaser.com
#
# This software is dual licensed under the following two licenses:
# BSD-new and GPLv2. You may use either one. See the included
# COPYING file for details.
#
# License: BSD-new
# ==============================================================================
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the <organization> nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
# License: GPLv2
# ==============================================================================
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
#
# IMPORTANT NOTICE:
# ==============================================================================
# This source code is made available for free, as an open license, by Kvaser AB,
# for use with its applications. Kvaser AB does not accept any liability
# whatsoever for any third party patent or other immaterial property rights
# violations that may result from any usage of this source code, regardless of
# the combination of source code and various applications that it can be used
# in, or with.
#
# -----------------------------------------------------------------------------
#
# Main Makefile for the Kvaser linuxcan.
#----------------------------------------
# included in build
#----------------------------------------
USERLIBS += canlib
USERLIBS += linlib
DRIVERS += common
DRIVERS += leaf
DRIVERS += mhydra
DRIVERS += usbcanII
DRIVERS += virtualcan
# KV_NO_PCI should be set on targets that do not have PCI, such as RaspberryPi.
ifndef KV_NO_PCI
DRIVERS += pcican
DRIVERS += pcican2
DRIVERS += pciefd
endif
#---------------------------------
# Debug levels are defined in config.mak
KV_DEBUG_ON ?= 0
export KV_DEBUG_ON
#---------------------------------
SUBDIRS = $(USERLIBS) $(DRIVERS)
reverse=$(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
KV_KERNEL_VERSION ?= `uname -r`
KDIR ?= /lib/modules/$(KV_KERNEL_VERSION)/build
this-makefile := $(lastword $(MAKEFILE_LIST))
abs_srctree := $(realpath $(dir $(this-makefile)))
define print_versions
echo '$1 building linuxcan v'`sed -n 's/^version=//g; s/_/./g; s/\([[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\).\(beta\)\?/\1 \2/p' moduleinfo.txt`
echo ' User : '$(USER)
echo ' System : '`uname -a`
echo ' CC : '$(CC)
echo ' CC ver. : '`$(CC) -dumpfullversion -dumpversion`
echo ' KDIR : '$(KDIR)
echo ' Kernel : '$(KV_KERNEL_VERSION)
echo ''
endef
KV_DKMS_MODULE = $(shell sed -n 's/^PACKAGE_NAME="\(.*\)"/\1/p' dkms/dkms.conf)
KV_DKMS_VERSION = $(shell sed -n 's/^PACKAGE_VERSION="\(.*\)"/\1/p' dkms/dkms.conf)
KV_DKMS_TARBALL = $(KV_DKMS_MODULE)-$(KV_DKMS_VERSION)-source-only.dkms.tar.gz
KV_DKMS_TMP = kv_dkms_tmp
KV_DKMS_TMP_SRC = $(KV_DKMS_TMP)/src_tmp
KV_DKMS_TMP_SRC_LINUXCAN = $(KV_DKMS_TMP_SRC)/$(KV_DKMS_MODULE)-$(KV_DKMS_VERSION)
KV_DKMS_TMP_DKMSTREE = $(KV_DKMS_TMP)/dkmstree_tmp
# Select if the kernel modules should only be installed or both installed and loaded:
KV_DKMS_INSTALL_TARGET = load
# KV_DKMS_INSTALL_TARGET = install
#---------------------------------------------------------------------------
# RULES
.PHONY: print_versions_start canlib linlib common leaf mhydra pcican pcican2 usbcanII virtualcan pciefd kvflash install uninstall clean check load dkms dkms_install dkms_load
all: print_versions_start $(SUBDIRS)
@echo
@$(call print_versions, Done)
@$(call check_for_kvaser_usb_devices)
@$(call check_for_secure_boot)
print_versions_start:
@$(call print_versions, Start)
@$(call check_for_kvaser_usb_devices)
@$(call check_for_secure_boot)
check_srctree_path:
@$(call check_space_or_colon_in_abs_srctree)
canlib:
$(MAKE) -C canlib
linlib: canlib
$(MAKE) -C linlib
common: check_srctree_path
@cd ./common; $(MAKE) kv_module
pcican: common
@cd ./pcican; $(MAKE) kv_module
pcican2: common
@cd ./pcican2; $(MAKE) kv_module
usbcanII: common
@cd ./usbcanII; $(MAKE) kv_module
leaf: common
@cd ./leaf; $(MAKE) kv_module
mhydra: common
@cd ./mhydra; $(MAKE) kv_module
virtualcan: common
@cd ./virtualcan; $(MAKE) kv_module
pciefd: common
@cd ./pciefd; $(MAKE) kv_module
kvflash: canlib
$(MAKE) -C kvflash
install:
@for dir in $(DRIVERS) ; do cd $$dir; echo Installing $$dir;./installscript.sh || exit 1; cd ..; done
$(MAKE) -C canlib install
$(MAKE) -C linlib install
uninstall:
@for dir in $(call reverse,$(DRIVERS)) ; do cd $$dir; echo Uninstalling $$dir;./uninstallscript.sh || exit 1; cd ..; done
$(MAKE) -C canlib uninstall
$(MAKE) -C linlib uninstall
rm -f /etc/udev/rules.d/10-kvaser.rules
rm -f /etc/modules-load.d/kvaser.conf
purge:
@for dir in $(call reverse,$(DRIVERS)) ; do cd $$dir; echo Uninstalling $$dir;./uninstallscript.sh -p || exit 1; cd ..; done
$(MAKE) -C canlib uninstall
$(MAKE) -C linlib uninstall
rm -f /etc/udev/rules.d/10-kvaser.rules
rm -f /etc/modules-load.d/kvaser.conf
load:
@for dir in $(DRIVERS) ; do cd $$dir; echo Installing $$dir;./installscript.sh load || exit 1; cd ..; done
$(MAKE) -C canlib install
$(MAKE) -C linlib install
check:
$(MAKE) -C canlib check
@for dir in $(DRIVERS) ; do cd $$dir; $(MAKE) check; cd ..; done
clean:
@for dir in $(SUBDIRS) ; do cd $$dir; $(MAKE) clean; cd ..; done
rm -f modules.order Module.symvers $(KV_DKMS_TARBALL)
rm -rf .tmp_versions $(KV_DKMS_TMP)
find . -name "checklog.txt"|xargs rm -f
define check_space_or_colon_in_abs_srctree
if test $(words $(subst :, ,$(abs_srctree))) -ne 1 ; then \
echo ''; \
echo 'Error: Source directory cannot contain spaces or colons: "$(abs_srctree)"'; \
exit 1; \
fi
endef
define check_for_kvaser_usb_devices
if lsusb -d 0bfd: > /dev/null ; then \
echo '*****************************************************'; \
echo 'WARNING: Found connected Kvaser USB device(s)!'; \
echo ' Unplug them before installing the drivers.'; \
echo '*****************************************************'; \
echo ''; \
fi
endef
HOSTNAME ?= $(shell uname -n)
EFI_SYS_PATH ?= /sys/firmware/efi
EFI_SECUREBOOT_PATH ?= $(EFI_SYS_PATH)/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c
define check_for_secure_boot
if test -d $(EFI_SYS_PATH) ; then \
if which mokutil > /dev/null 2>&1 ; then \
if mokutil --sb-state | grep --silent 'SecureBoot enabled' ; then \
echo '*****************************************************'; \
echo 'WARNING: Secure Boot is enabled on <$(HOSTNAME)>!'; \
echo ' When Secure Boot is enabled, driver modules'; \
echo ' need to be signed with a valid private key' ; \
echo ' in order to be loaded by the kernel.'; \
echo '*****************************************************'; \
echo ''; \
fi \
elif test -f $(EFI_SECUREBOOT_PATH) ; then \
if od --skip-bytes=4 --read-bytes=1 -An -t u1 $(EFI_SECUREBOOT_PATH) | grep --silent 1 ; then \
echo '*****************************************************'; \
echo 'WARNING: EFI is used on <$(HOSTNAME)>!'; \
echo ' It looks like Secure Boot is enabled!'; \
echo ' When Secure Boot is enabled, driver modules'; \
echo ' need to be signed with a valid private key' ; \
echo ' in order to be loaded by the kernel.'; \
echo '*****************************************************'; \
echo ''; \
else \
echo '*****************************************************'; \
echo 'WARNING: EFI is used on <$(HOSTNAME)>!'; \
echo ' It looks like Secure Boot is disabled.'; \
echo ' When Secure Boot is enabled, driver modules'; \
echo ' need to be signed with a valid private key' ; \
echo ' in order to be loaded by the kernel.'; \
echo '*****************************************************'; \
echo ''; \
fi \
else \
echo '*****************************************************'; \
echo 'WARNING: EFI is used on <$(HOSTNAME)>!'; \
echo ' Not able to determine whether Secure Boot is'; \
echo ' enabled or disabled.'; \
echo ' When Secure Boot is enabled, driver modules'; \
echo ' need to be signed with a valid private key' ; \
echo ' in order to be loaded by the kernel.'; \
echo '*****************************************************'; \
echo ''; \
fi \
fi
endef
$(KV_DKMS_TARBALL):
@echo Build DKMS tarball, with install target: $(KV_DKMS_INSTALL_TARGET)
rm -rf $(KV_DKMS_TMP)
mkdir -p $(KV_DKMS_TMP)/src_tmp/$(KV_DKMS_MODULE)-$(KV_DKMS_VERSION)
mkdir -p $(KV_DKMS_TMP_DKMSTREE)
@for dir in $(DRIVERS) ; do cp -r $$dir $(KV_DKMS_TMP_SRC_LINUXCAN)/. ; done
ifdef KV_NO_PCI
# make the non-pci dkms.conf
cp dkms/dkms-no-pci.conf $(KV_DKMS_TMP_SRC_LINUXCAN)/dkms.conf
else
cp dkms/dkms.conf $(KV_DKMS_TMP_SRC_LINUXCAN)/dkms.conf
endif
cp dkms/Makefile 10-kvaser.rules dkms/kv_dkms_script.sh moduleinfo.txt config.mak README COPYING COPYING.BSD COPYING.GPL $(KV_DKMS_TMP_SRC_LINUXCAN)/.
cp -r include common $(KV_DKMS_TMP_SRC_LINUXCAN)/.
sed -i 's/^KV_INSTALL_TARGET=none/KV_INSTALL_TARGET=$(KV_DKMS_INSTALL_TARGET)/g' $(KV_DKMS_TMP_SRC_LINUXCAN)/dkms.conf
fakeroot dkms add --verbose --sourcetree "$(CURDIR)/$(KV_DKMS_TMP_SRC)" --dkmstree "$(CURDIR)/$(KV_DKMS_TMP_DKMSTREE)" $(KV_DKMS_MODULE)/$(KV_DKMS_VERSION)
dkms mktarball --verbose --dkmstree $(KV_DKMS_TMP_DKMSTREE) --source-only $(KV_DKMS_MODULE)/$(KV_DKMS_VERSION)
cp $(KV_DKMS_TMP_DKMSTREE)/$(KV_DKMS_MODULE)/$(KV_DKMS_VERSION)/tarball/$(KV_DKMS_TARBALL) .
rm -rf $(KV_DKMS_TMP)
dkms: print_versions_start $(USERLIBS) $(KV_DKMS_TARBALL)
@$(call print_versions, Done)
@$(call check_for_kvaser_usb_devices)
@$(call check_for_secure_boot)
dkms_install dkms_load: $(KV_DKMS_TARBALL)
$(MAKE) -C canlib install
$(MAKE) -C linlib install
dkms status $(KV_DKMS_MODULE) | cut -d',' -f 2 | cut -d':' -f 1 | xargs -I theversion dkms remove $(KV_DKMS_MODULE)/theversion --all
dkms add $(KV_DKMS_TARBALL)
dkms install $(KV_DKMS_MODULE)/$(KV_DKMS_VERSION) -k $(KV_KERNEL_VERSION)
dkms status
dkms_uninstall:
$(MAKE) -C canlib uninstall
$(MAKE) -C linlib uninstall
dkms status
-dkms remove $(KV_DKMS_MODULE)/$(KV_DKMS_VERSION) --all
rm -f /etc/udev/rules.d/10-kvaser.rules
rm -f /etc/modules-load.d/kvaser.conf
rm -rf /usr/src/$(KV_DKMS_MODULE)-$(KV_DKMS_VERSION)
dkms status