Merge pull request #743 from robertbaldyga/makefile-fix-uninstall

Fix Makefile error handling
This commit is contained in:
Robert Baldyga 2021-03-19 18:43:57 +01:00 committed by GitHub
commit 94dc9048c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 71 additions and 44 deletions

View File

@ -27,16 +27,16 @@ endif
endif
archives:
@utils/pckgen $(PWD) tar zip
@tools/pckgen $(PWD) tar zip
rpm:
@utils/pckgen $(PWD) rpm --debug
@tools/pckgen $(PWD) rpm --debug
srpm:
@utils/pckgen $(PWD) srpm --debug
@tools/pckgen $(PWD) srpm --debug
deb:
@utils/pckgen $(PWD) deb
@tools/pckgen $(PWD) deb
dsc:
@utils/pckgen $(PWD) dsc
@tools/pckgen $(PWD) dsc

View File

@ -3,9 +3,10 @@
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
include ../tools/helpers.mk
PWD:=$(shell pwd)
MODULESDIR:=$(PWD)/../modules
UTILS_DIR:=$(PWD)/../utils
METADATA_DIR:=$(PWD)/../.metadata
BINARY_PATH = /sbin
@ -135,28 +136,12 @@ install_files:
@mkdir -p $(DESTDIR)$(BINARY_PATH)
@install -m 755 $(TARGET) $(DESTDIR)$(BINARY_PATH)/$(TARGET)
@mkdir -p $(DESTDIR)/usr/share/man/man8
@install -m 644 $(UTILS_DIR)/$(TARGET).8 $(DESTDIR)/usr/share/man/man8/$(TARGET).8
@install -m 755 -d $(DESTDIR)/etc/opencas
@install -m 644 $(UTILS_DIR)/opencas.conf $(DESTDIR)/etc/opencas/opencas.conf
@install -m 444 $(UTILS_DIR)/ioclass-config.csv $(DESTDIR)/etc/opencas/ioclass-config.csv
@install -m 755 -d $(DESTDIR)/var/lib/opencas
@install -m 644 $(METADATA_DIR)/cas_version $(DESTDIR)/var/lib/opencas/cas_version
@install -m 644 $(TARGET).8 $(DESTDIR)/usr/share/man/man8/$(TARGET).8
@mkdir -p $(DESTDIR)/usr/share/man/man5
@install -m 644 $(UTILS_DIR)/opencas.conf.5 $(DESTDIR)/usr/share/man/man5/opencas.conf.5
uninstall:
@echo "Uninstalling casadm"
@rm $(DESTDIR)$(BINARY_PATH)/$(TARGET)
@rm $(DESTDIR)/usr/share/man/man8/$(TARGET).8
@rm $(DESTDIR)/etc/opencas/opencas.conf
@rm $(DESTDIR)/etc/opencas/ioclass-config.csv
@rm -rf $(DESTDIR)/etc/opencas
@rm $(DESTDIR)/var/lib/opencas/cas_version
@rm -rf $(DESTDIR)/var/lib/opencas
@rm $(DESTDIR)/usr/share/man/man5/opencas.conf.5
$(call remove-file,$(DESTDIR)$(BINARY_PATH)/$(TARGET))
$(call remove-file,$(DESTDIR)/usr/share/man/man8/$(TARGET).8)
.PHONY: clean distclean all sync build install uninstall

2
configure vendored
View File

@ -79,7 +79,7 @@ fi
# Run version generator with 'build' flag to
# indicate that we are in the build process
(cd utils && ./cas_version_gen build)
(cd tools && ./cas_version_gen build)
if [ $? -ne 0 ]; then
echo "Error: failed to obtain CAS version" >&2
exit 1

View File

@ -15,6 +15,13 @@ obj-y += cas_disk/
# line; invoke the kernel build system.
else
include ../tools/helpers.mk
define remove-module
@if (lsmod | grep -q ${1}); then rmmod ${1}; \
else echo "WARNING: Module ${1} is not loaded"; fi
endef
OCFDIR=$(PWD)/../ocf
PWD=$(shell pwd)
KERNEL_VERSION ?= "$(shell uname -r)"
@ -57,11 +64,11 @@ install_files:
uninstall:
@echo "Uninstalling Open-CAS modules"
@$(RMMOD) $(CACHE_MODULE)
@$(RMMOD) $(DISK_MODULE)
$(call remove-module,$(CACHE_MODULE))
$(call remove-module,$(DISK_MODULE))
@rm $(DESTDIR)$(MODULES_DIR)/$(CACHE_MODULE).ko
@rm $(DESTDIR)$(MODULES_DIR)/$(DISK_MODULE).ko
$(call remove-file,$(DESTDIR)$(MODULES_DIR)/$(CACHE_MODULE).ko)
$(call remove-file,$(DESTDIR)$(MODULES_DIR)/$(DISK_MODULE).ko)
@$(DEPMOD)

15
tools/helpers.mk Normal file
View File

@ -0,0 +1,15 @@
#
# Copyright(c) 2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
define remove-file
@if [ -f ${1} ] || [ -L ${1} ]; then rm -rf ${1}; \
else echo "WARNING: Cannot find file ${1}"; fi
endef
define remove-directory
@if [ -d ${1} ]; then rm -rf ${1}; \
else echo "WARNING: Cannot find directory ${1}"; fi
endef

View File

@ -515,7 +515,7 @@ DEB_BUILD_DIR="$TEMP_DIR/debuild"
# Version file location:
VERSION_FILE="$SOURCES_DIR/.metadata/cas_version"
# CAS version generator location:
CAS_VERSION_GEN="$SOURCES_DIR/utils/cas_version_gen"
CAS_VERSION_GEN="$SOURCES_DIR/tools/cas_version_gen"
check_version

View File

@ -3,8 +3,12 @@
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
include ../tools/helpers.mk
CASCTL_DIR = /lib/opencas
UDEVRULES_DIR = /lib/udev/rules.d
METADATA_DIR:=$(PWD)/../.metadata
UTILS_DIR:=$(PWD)/../utils
UDEV:=$(shell which udevadm)
SYSTEMCTL := $(shell which systemctl)
PYTHON3 := $(shell which python3)
@ -30,6 +34,14 @@ else
install_files:
@echo "Installing Open-CAS utils"
@install -m 755 -d $(DESTDIR)/etc/opencas
@install -m 644 $(UTILS_DIR)/opencas.conf $(DESTDIR)/etc/opencas/opencas.conf
@install -m 444 $(UTILS_DIR)/ioclass-config.csv $(DESTDIR)/etc/opencas/ioclass-config.csv
@install -m 755 -d $(DESTDIR)/var/lib/opencas
@install -m 644 $(METADATA_DIR)/cas_version $(DESTDIR)/var/lib/opencas/cas_version
@mkdir -p $(DESTDIR)/usr/share/man/man5
@install -m 644 $(UTILS_DIR)/opencas.conf.5 $(DESTDIR)/usr/share/man/man5/opencas.conf.5
@install -m 755 -d $(DESTDIR)$(CASCTL_DIR)
@install -m 644 opencas.py $(DESTDIR)$(CASCTL_DIR)/opencas.py
@install -m 755 casctl $(DESTDIR)$(CASCTL_DIR)/casctl
@ -58,28 +70,36 @@ install_files:
endif
uninstall:
@rm $(DESTDIR)$(CASCTL_DIR)/opencas.py
@rm $(DESTDIR)$(CASCTL_DIR)/casctl
@rm $(DESTDIR)$(CASCTL_DIR)/open-cas-loader
@rm -rf $(DESTDIR)$(CASCTL_DIR)
@echo "Uninstalling Open-CAS utils"
@rm $(DESTDIR)/etc/dracut.conf.d/opencas.conf
$(call remove-file,$(DESTDIR)/etc/opencas/opencas.conf)
$(call remove-file,$(DESTDIR)/etc/opencas/ioclass-config.csv)
$(call remove-directory,$(DESTDIR)/etc/opencas)
$(call remove-file,$(DESTDIR)/var/lib/opencas/cas_version)
$(call remove-directory,$(DESTDIR)/var/lib/opencas)
$(call remove-file,$(DESTDIR)/usr/share/man/man5/opencas.conf.5)
@rm $(DESTDIR)/sbin/casctl
$(call remove-file,$(DESTDIR)$(CASCTL_DIR)/opencas.py)
$(call remove-file,$(DESTDIR)$(CASCTL_DIR)/casctl)
$(call remove-file,$(DESTDIR)$(CASCTL_DIR)/open-cas-loader)
$(call remove-directory,$(DESTDIR)$(CASCTL_DIR))
@rm $(DESTDIR)/usr/share/man/man8/casctl.8
$(call remove-file,$(DESTDIR)/etc/dracut.conf.d/opencas.conf)
@rm $(DESTDIR)$(UDEVRULES_DIR)/60-persistent-storage-cas-load.rules
@rm $(DESTDIR)$(UDEVRULES_DIR)/60-persistent-storage-cas.rules
$(call remove-file,$(DESTDIR)/sbin/casctl)
$(call remove-file,$(DESTDIR)/usr/share/man/man8/casctl.8)
$(call remove-file,$(DESTDIR)$(UDEVRULES_DIR)/60-persistent-storage-cas-load.rules)
$(call remove-file,$(DESTDIR)$(UDEVRULES_DIR)/60-persistent-storage-cas.rules)
@$(UDEV) control --reload-rules
@$(SYSTEMCTL) -q disable open-cas-shutdown
@$(SYSTEMCTL) -q disable open-cas
@$(SYSTEMCTL) daemon-reload
@rm $(DESTDIR)$(SYSTEMD_DIR)/open-cas-shutdown.service
@rm $(DESTDIR)$(SYSTEMD_DIR)/open-cas.service
@rm $(DESTDIR)$(SYSTEMD_DIR)/../system-shutdown/open-cas.shutdown
$(call remove-file,$(DESTDIR)$(SYSTEMD_DIR)/open-cas-shutdown.service)
$(call remove-file,$(DESTDIR)$(SYSTEMD_DIR)/open-cas.service)
$(call remove-file,$(DESTDIR)$(SYSTEMD_DIR)/../system-shutdown/open-cas.shutdown)
.PHONY: install uninstall clean distclean