Makefile 8.39 KB
Newer Older
1
NAME = tuned
2 3 4 5
# set to devel for nightly GIT snapshot
BUILD = release
# which config to use in mock-build target
MOCK_CONFIG = rhel-7-x86_64
6
# scratch-build for triggering Jenkins
7
SCRATCH_BUILD_TARGET = rhel-7.5-candidate
8
VERSION = $(shell awk '/^Version:/ {print $$2}' tuned.spec)
9
GIT_DATE = $(shell date +'%Y%m%d')
10 11 12 13 14 15 16 17 18 19 20 21
ifeq ($(BUILD), release)
	RPM_ARGS += --without snapshot
	MOCK_ARGS += --without=snapshot
	RPM_VERSION = $(NAME)-$(VERSION)-1
else
	RPM_ARGS += --with snapshot
	MOCK_ARGS += --with=snapshot
	GIT_SHORT_COMMIT = $(shell git rev-parse --short=8 --verify HEAD)
	GIT_SUFFIX = $(GIT_DATE)git$(GIT_SHORT_COMMIT)
	GIT_PSUFFIX = .$(GIT_SUFFIX)
	RPM_VERSION = $(NAME)-$(VERSION)-1$(GIT_PSUFFIX)
endif
22
UNITDIR_FALLBACK = /usr/lib/systemd/system
23
UNITDIR_DETECT = $(shell pkg-config systemd --variable systemdsystemunitdir || rpm --eval '%{_unitdir}' 2>/dev/null || echo $(UNITDIR_FALLBACK))
24 25
UNITDIR = $(UNITDIR_DETECT:%{_unitdir}=$(UNITDIR_FALLBACK))
TMPFILESDIR_FALLBACK = /usr/lib/tmpfiles.d
26
TMPFILESDIR_DETECT = $(shell pkg-config systemd --variable tmpfilesdir || rpm --eval '%{_tmpfilesdir}' 2>/dev/null || echo $(TMPFILESDIR_FALLBACK))
27
TMPFILESDIR = $(TMPFILESDIR_DETECT:%{_tmpfilesdir}=$(TMPFILESDIR_FALLBACK))
28
VERSIONED_NAME = $(NAME)-$(VERSION)$(GIT_PSUFFIX)
29

30
SYSCONFDIR = /etc
31 32
DATADIR = /usr/share
DOCDIR = $(DATADIR)/doc/$(NAME)
33
PYTHON = python3
34
PYLINT = pylint-3
35 36
ifeq ($(PYTHON),python2)
PYLINT = pylint-2
37 38 39 40 41 42
endif
SHEBANG_REWRITE_REGEX= '1s/^(\#!\/usr\/bin\/)\<python\>/\1$(PYTHON)/'
PYTHON_SITELIB = $(shell $(PYTHON) -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib());')
ifeq ($(PYTHON_SITELIB),)
$(error Failed to determine python library directory)
endif
43
TUNED_PROFILESDIR = /usr/lib/tuned
44
TUNED_RECOMMEND_DIR = $(TUNED_PROFILESDIR)/recommend.d
45
TUNED_USER_RECOMMEND_DIR = $(SYSCONFDIR)/tuned/recommend.d
46
BASH_COMPLETIONS = $(DATADIR)/bash-completion/completions
47

Ondřej Lysoněk's avatar
Ondřej Lysoněk committed
48 49 50 51 52 53
copy_executable = install -Dm 0755 $(1) $(2)
rewrite_shebang = sed -i -r -e $(SHEBANG_REWRITE_REGEX) $(1)
restore_timestamp = touch -r $(1) $(2)
install_python_script = $(call copy_executable,$(1),$(2)) \
	&& $(call rewrite_shebang,$(2)) && $(call restore_timestamp,$(1),$(2));

54
release-dir:
55 56
	mkdir -p $(VERSIONED_NAME)

57 58
release-cp: release-dir
	cp -a AUTHORS COPYING INSTALL README $(VERSIONED_NAME)
59

60
	cp -a tuned.py tuned.spec tuned.service tuned.tmpfiles Makefile tuned-adm.py \
61
		tuned-adm.bash dbus.conf recommend.conf tuned-main.conf 00_tuned \
62 63 64
		bootcmdline modules.conf com.redhat.tuned.policy \
		com.redhat.tuned.gui.policy tuned-gui.py tuned-gui.glade \
		tuned-gui.desktop $(VERSIONED_NAME)
65
	cp -a doc experiments libexec man profiles systemtap tuned contrib icons \
66
		$(VERSIONED_NAME)
67

68
archive: clean release-cp
69
	tar czf $(VERSIONED_NAME).tar.gz $(VERSIONED_NAME)
70

71
rpm-build-dir:
72
	mkdir rpm-build-dir
73

74
srpm: archive rpm-build-dir
75
	rpmbuild --define "_sourcedir `pwd`/rpm-build-dir" --define "_srcrpmdir `pwd`/rpm-build-dir" \
76
		--define "_specdir `pwd`/rpm-build-dir" --nodeps $(RPM_ARGS) -ts $(VERSIONED_NAME).tar.gz
77

78
rpm: archive rpm-build-dir
79
	rpmbuild --define "_sourcedir `pwd`/rpm-build-dir" --define "_srcrpmdir `pwd`/rpm-build-dir" \
80
		--define "_specdir `pwd`/rpm-build-dir" --nodeps $(RPM_ARGS) -tb $(VERSIONED_NAME).tar.gz
81

82 83 84
clean-mock-result-dir:
	rm -f mock-result-dir/*

85
mock-result-dir:
86 87
	mkdir mock-result-dir

88 89 90 91 92 93
# delete RPM files older than cca. one week if total space occupied is more than 5 MB
tidy-mock-result-dir: mock-result-dir
	if [ `du -bs mock-result-dir | tail -n 1 | cut -f1` -gt 5000000 ]; then \
		rm -f `find mock-result-dir -name '*.rpm' -mtime +7`; \
	fi

94 95 96 97 98
mock-build: srpm
	mock -r $(MOCK_CONFIG) $(MOCK_ARGS) --resultdir=`pwd`/mock-result-dir `ls rpm-build-dir/*$(RPM_VERSION).*.src.rpm | head -n 1`&& \
	rm -f mock-result-dir/*.log

mock-devel-build: srpm
99 100 101
	mock -r $(MOCK_CONFIG) --with=snapshot \
		--define "git_short_commit `if [ -n \"$(GIT_SHORT_COMMIT)\" ]; then echo $(GIT_SHORT_COMMIT); else git rev-parse --short=8 --verify HEAD; fi`" \
		--resultdir=`pwd`/mock-result-dir `ls rpm-build-dir/*$(RPM_VERSION).*.src.rpm | head -n 1` && \
102 103 104 105 106
	rm -f mock-result-dir/*.log

createrepo: mock-devel-build
	createrepo mock-result-dir

107 108
# scratch build to triggering Jenkins
scratch-build: mock-devel-build
109
	brew build --scratch --nowait $(SCRATCH_BUILD_TARGET) `ls mock-result-dir/*$(GIT_DATE)git*.*.src.rpm | head -n 1`
110

111
nightly: tidy-mock-result-dir createrepo scratch-build
112
	rsync -ave ssh --delete --progress mock-result-dir/ jskarvad@fedorapeople.org:/home/fedora/jskarvad/public_html/tuned/devel/repo/
113 114

install-dirs:
115
	mkdir -p $(DESTDIR)$(PYTHON_SITELIB)
116
	mkdir -p $(DESTDIR)$(TUNED_PROFILESDIR)
117
	mkdir -p $(DESTDIR)/var/lib/tuned
118 119 120
	mkdir -p $(DESTDIR)/var/log/tuned
	mkdir -p $(DESTDIR)/run/tuned
	mkdir -p $(DESTDIR)$(DOCDIR)
121
	mkdir -p $(DESTDIR)$(SYSCONFDIR)
122
	mkdir -p $(DESTDIR)$(TUNED_RECOMMEND_DIR)
123
	mkdir -p $(DESTDIR)$(TUNED_USER_RECOMMEND_DIR)
124 125 126

install: install-dirs
	# library
127
	cp -a tuned $(DESTDIR)$(PYTHON_SITELIB)
128 129

	# binaries
Ondřej Lysoněk's avatar
Ondřej Lysoněk committed
130 131 132 133 134 135 136 137
	$(call install_python_script,tuned.py,$(DESTDIR)/usr/sbin/tuned)
	$(call install_python_script,tuned-adm.py,$(DESTDIR)/usr/sbin/tuned-adm)
	$(call install_python_script,tuned-gui.py,$(DESTDIR)/usr/sbin/tuned-gui)

	$(foreach file, diskdevstat netdevstat scomes, \
		install -Dpm 0755 systemtap/$(file) $(DESTDIR)/usr/sbin/$(notdir $(file));)
	$(call install_python_script, \
		systemtap/varnetload, $(DESTDIR)/usr/sbin/varnetload)
138

Jaroslav Škarvada's avatar
Jaroslav Škarvada committed
139
	# glade
140
	install -Dpm 0644 tuned-gui.glade $(DESTDIR)$(DATADIR)/tuned/ui/tuned-gui.glade
Jaroslav Škarvada's avatar
Jaroslav Škarvada committed
141

142
	# tools
Ondřej Lysoněk's avatar
Ondřej Lysoněk committed
143 144
	$(call install_python_script, \
		 experiments/powertop2tuned.py, $(DESTDIR)/usr/bin/powertop2tuned)
145

146
	# configuration files
147
	install -Dpm 0644 tuned-main.conf $(DESTDIR)$(SYSCONFDIR)/tuned/tuned-main.conf
148
	# None profile in the moment, autodetection will be used
149 150 151 152
	echo -n > $(DESTDIR)$(SYSCONFDIR)/tuned/active_profile
	echo -n > $(DESTDIR)$(SYSCONFDIR)/tuned/profile_mode
	install -Dpm 0644 bootcmdline $(DESTDIR)$(SYSCONFDIR)/tuned/bootcmdline
	install -Dpm 0644 modules.conf $(DESTDIR)$(SYSCONFDIR)/modprobe.d/tuned.conf
153

154
	# profiles & system config
155
	cp -a profiles/* $(DESTDIR)$(TUNED_PROFILESDIR)/
156
	mv $(DESTDIR)$(TUNED_PROFILESDIR)/realtime/realtime-variables.conf \
157
		$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-variables.conf
158
	mv $(DESTDIR)$(TUNED_PROFILESDIR)/realtime-virtual-guest/realtime-virtual-guest-variables.conf \
159
		$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-virtual-guest-variables.conf
160
	mv $(DESTDIR)$(TUNED_PROFILESDIR)/realtime-virtual-host/realtime-virtual-host-variables.conf \
161
		$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-virtual-host-variables.conf
162
	mv $(DESTDIR)$(TUNED_PROFILESDIR)/cpu-partitioning/cpu-partitioning-variables.conf \
163
		$(DESTDIR)$(SYSCONFDIR)/tuned/cpu-partitioning-variables.conf
164
	mv $(DESTDIR)$(TUNED_PROFILESDIR)/sap-hana-vmware/sap-hana-vmware-variables.conf \
165
		$(DESTDIR)$(SYSCONFDIR)/tuned/sap-hana-vmware-variables.conf
166
	install -pm 0644 recommend.conf $(DESTDIR)$(TUNED_RECOMMEND_DIR)/50-tuned.conf
167

168 169
	# bash completion
	install -Dpm 0644 tuned-adm.bash $(DESTDIR)$(BASH_COMPLETIONS)/tuned-adm
170

171
	# runtime directory
172
	install -Dpm 0644 tuned.tmpfiles $(DESTDIR)$(TMPFILESDIR)/tuned.conf
173 174

	# systemd units
175
	install -Dpm 0644 tuned.service $(DESTDIR)$(UNITDIR)/tuned.service
176

Jan Vcelak's avatar
Jan Vcelak committed
177
	# dbus configuration
178
	install -Dpm 0644 dbus.conf $(DESTDIR)$(SYSCONFDIR)/dbus-1/system.d/com.redhat.tuned.conf
Jan Vcelak's avatar
Jan Vcelak committed
179

180
	# grub template
181
	install -Dpm 0755 00_tuned $(DESTDIR)$(SYSCONFDIR)/grub.d/00_tuned
182

Jaroslav Škarvada's avatar
Jaroslav Škarvada committed
183
	# polkit configuration
184
	install -Dpm 0644 com.redhat.tuned.policy $(DESTDIR)$(DATADIR)/polkit-1/actions/com.redhat.tuned.policy
185
	install -Dpm 0644 com.redhat.tuned.gui.policy $(DESTDIR)$(DATADIR)/polkit-1/actions/com.redhat.tuned.gui.policy
Jaroslav Škarvada's avatar
Jaroslav Škarvada committed
186

187
	# manual pages
188
	$(foreach man_section, 5 7 8, $(foreach file, $(wildcard man/*.$(man_section)), \
189
		install -Dpm 0644 $(file) $(DESTDIR)$(DATADIR)/man/man$(man_section)/$(notdir $(file));))
Jan Kaluza's avatar
Jan Kaluza committed
190

191
	# documentation
192 193
	cp -a doc/* $(DESTDIR)$(DOCDIR)
	cp AUTHORS COPYING README $(DESTDIR)$(DOCDIR)
194

195
	# libexec scripts
196
	$(foreach file, $(wildcard libexec/*), \
Ondřej Lysoněk's avatar
Ondřej Lysoněk committed
197 198
		$(call install_python_script, \
			$(file), $(DESTDIR)/usr/libexec/tuned/$(notdir $(file))))
199

200 201 202 203 204 205 206
	# icon
	install -Dpm 0644 icons/tuned.svg $(DESTDIR)$(DATADIR)/icons/hicolor/scalable/apps/tuned.svg

	# desktop file
	install -dD $(DESTDIR)$(DATADIR)/applications
	desktop-file-install --dir=$(DESTDIR)$(DATADIR)/applications tuned-gui.desktop

207 208 209 210
clean:
	find -name "*.pyc" | xargs rm -f
	rm -rf $(VERSIONED_NAME) rpm-build-dir

211
test:
212
	$(PYTHON) -m unittest discover tests
213

214
lint:
215
	$(PYLINT) -E -f parseable tuned *.py
216 217

.PHONY: clean archive srpm tag test lint