-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
119 lines (102 loc) · 4.38 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
#
# Copyright (c) 2019-2020 TUXEDO Computers GmbH <tux@tuxedocomputers.com>
#
# This file is part of tuxedo-cc-wmi.
#
# tuxedo-cc-wmi 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 software 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 software. If not, see <https://www.gnu.org/licenses/>.
#
obj-m := ./src/tuxedo_cc_wmi.o
PWD := $(shell pwd)
KDIR := /lib/modules/$(shell uname -r)/build
# Module build targets
all:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
# --------------
# Packaging only
# ---------------
# Package version and name from dkms.conf
VER := $(shell sed -n 's/^PACKAGE_VERSION=\([^\n]*\)/\1/p' dkms.conf 2>/dev/null)
MODULE_NAME := $(shell sed -n 's/^PACKAGE_NAME=\([^\n]*\)/\1/p' dkms.conf 2>/dev/null)
DEB_PACKAGE_NAME := $(MODULE_NAME)-$(VER)
# Deb package folder variables
DEB_PACKAGE_BASE := deb/$(DEB_PACKAGE_NAME)
DEB_PACKAGE_SRC := $(DEB_PACKAGE_BASE)/usr/src/$(DEB_PACKAGE_NAME)
DEB_PACKAGE_CTRL := $(DEB_PACKAGE_BASE)/DEBIAN
package: package-deb package-rpm
package-clean: package-deb-clean package-rpm-clean
package-deb:
# Create/complete folder structure according to current version
rm -rf $(DEB_PACKAGE_BASE) || true
cp -rf deb/module-name $(DEB_PACKAGE_BASE)
mv $(DEB_PACKAGE_BASE)/usr/share/doc/module-name $(DEB_PACKAGE_BASE)/usr/share/doc/$(MODULE_NAME)
mkdir -p $(DEB_PACKAGE_BASE)/usr/src || true
mkdir -p $(DEB_PACKAGE_SRC) || true
mkdir -p $(DEB_PACKAGE_BASE)/usr/share/$(MODULE_NAME) || true
# Replace name/version numbers in control/script files
sed -i 's/^Version:[^\n]*/Version: $(VER)/g' $(DEB_PACKAGE_CTRL)/control
sed -i 's/^Package:[^\n]*/Package: $(MODULE_NAME)/g' $(DEB_PACKAGE_CTRL)/control
sed -i 's/^version=[^\n]*/version=$(VER)/g' $(DEB_PACKAGE_CTRL)/postinst
sed -i 's/^module=[^\n]*/module=$(MODULE_NAME)/g' $(DEB_PACKAGE_CTRL)/postinst
sed -i 's/^version=[^\n]*/version=$(VER)/g' $(DEB_PACKAGE_CTRL)/prerm
sed -i 's/^module=[^\n]*/module=$(MODULE_NAME)/g' $(DEB_PACKAGE_CTRL)/prerm
# Copy source
cp -rf dkms.conf $(DEB_PACKAGE_SRC)
cp -rf Makefile $(DEB_PACKAGE_SRC)
cp -rf src $(DEB_PACKAGE_SRC)
cp -rf src_pkg/dkms_postinst $(DEB_PACKAGE_BASE)/usr/share/$(MODULE_NAME)/postinst
# Make sure files and folders have acceptable permissions
chmod -R 755 $(DEB_PACKAGE_CTRL)
chmod 644 $(DEB_PACKAGE_CTRL)/control
find deb/$(DEB_PACKAGE_NAME)/usr -type d -exec chmod 755 {} \;
find deb/$(DEB_PACKAGE_NAME)/usr -type f -exec chmod 644 {} \;
chmod 755 $(DEB_PACKAGE_BASE)/usr/share/$(MODULE_NAME)/postinst
gunzip $(DEB_PACKAGE_BASE)/usr/share/doc/$(MODULE_NAME)/changelog.gz
gzip -n9 $(DEB_PACKAGE_BASE)/usr/share/doc/$(MODULE_NAME)/changelog
# Make deb package
dpkg-deb --root-owner-group -b $(DEB_PACKAGE_BASE) $(DEB_PACKAGE_NAME).deb
package-deb-clean:
rm -rf deb/$(MODULE_NAME)-* > /dev/null 2>&1 || true
rm *.deb > /dev/null 2>&1 || true
RPM_PACKAGE_NAME := $(MODULE_NAME)-$(VER)
RPM_PACKAGE_SRC := rpm/SOURCES/$(RPM_PACKAGE_NAME)
RPM_SPEC := rpm/SPECS/$(MODULE_NAME).spec
RELEASE := 1
package-rpm:
# Create folder source structure according to current version
rm -rf rpm || true
mkdir -p $(RPM_PACKAGE_SRC)
mkdir -p rpm/SPECS
# Copy spec template
cp -rf src_pkg/rpm_pkg.spec $(RPM_SPEC)
# Modify spec file with version etc.
sed -i 's/^%define module[^\n]*/%define module $(MODULE_NAME)/g' $(RPM_SPEC)
sed -i 's/^Version:[^\n]*/Version: $(VER)/g' $(RPM_SPEC)
sed -i 's/^Release:[^\n]*/Release: $(RELEASE)/g' $(RPM_SPEC)
# Copy source
cp -rf dkms.conf $(RPM_PACKAGE_SRC)
cp -rf Makefile $(RPM_PACKAGE_SRC)
cp -rf src $(RPM_PACKAGE_SRC)
cp -rf LICENSE $(RPM_PACKAGE_SRC)
cp -rf src_pkg/dkms_postinst $(RPM_PACKAGE_SRC)/postinst
# Compress/package source
cd rpm/SOURCES && tar cjvf $(RPM_PACKAGE_NAME).tar.bz2 $(RPM_PACKAGE_NAME)
# Make rpm package
rpmbuild --debug -bb --define "_topdir `pwd`/rpm" $(RPM_SPEC)
# Copy built package
cp rpm/RPMS/noarch/*.rpm .
package-rpm-clean:
rm -rf rpm > /dev/null 2>&1 || true
rm *.rpm > /dev/null 2>&1 || true