diff --git a/kmod/.gitignore b/kmod/.gitignore index 23820239..2fa4c0bc 100644 --- a/kmod/.gitignore +++ b/kmod/.gitignore @@ -10,3 +10,5 @@ cscope.* *.spec *.sw[po] rpmbuild/ + +scoutfs-*.git*/ diff --git a/kmod/Makefile b/kmod/Makefile index 2963f205..c4a40dc6 100644 --- a/kmod/Makefile +++ b/kmod/Makefile @@ -24,11 +24,59 @@ SCOUTFS_ARGS := SCOUTFS_GIT_DESCRIBE=$(SCOUTFS_GIT_DESCRIBE) \ CONFIG_SCOUTFS_FS=m -C $(SK_KSRC) M=$(CURDIR)/src \ EXTRA_CFLAGS="-Werror" +# move damage locally, this will also help make it easier to cleanup after the build +RPM_DIR = $(shell pwd)/rpmbuild + +# - We use the git describe from tags to set up the RPM versioning +RPM_VERSION := $(shell git describe --long --tags | awk -F '-' '{gsub(/^v/,""); print $$1}') +RPM_RELEASE := $(shell git describe --long --tags | awk -F '-' '{print $$2"."$$3}') +FULL_VERSION := $(RPM_VERSION).$(RPM_RELEASE) +TARFILE = $(RPM_DIR)/SOURCES/scoutfs-kmod-$(FULL_VERSION).tar + +.PHONY: .FORCE + all: module module: make $(SCOUTFS_ARGS) $(SP) make C=2 CF="-D__CHECK_ENDIAN__" $(SCOUTFS_ARGS) + +modules_install: + make $(SCOUTFS_ARGS) modules_install + + +# remake this each time.. +$(RPM_DIR): .FORCE + @echo "## Clean up on isle $(RPM_DIR)..." + rm -frv $(RPM_DIR)/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + mkdir -p $(RPM_DIR)/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + + +%.spec: %.spec.in .FORCE + sed -e 's/@@VERSION@@/$(RPM_VERSION)/g' \ + -e s'/@@TAR_VERSION@@/$(FULL_VERSION)/g' \ + -e s'/@@RELEASE@@/$(RPM_RELEASE)/g' < $< > $@+ + mv $@+ $@ + + +# NOTE: Both tar & rpm are capable of being built natively on Linux, provided +# you have a local install of rpmbuild.sh for the rpm target. +# Normal exection is to use docker, as that pulls our canned image and tooling for the user. +# ./indocker.sh make tar +# ./indocker.sh make rpm +# +tar: $(RPM_DIR) scoutfs-kmod.spec + git archive --format=tar --prefix scoutfs-$(FULL_VERSION)/ HEAD^{tree} > $(TARFILE) + @ tar rf $(TARFILE) --transform="s@\(.*\)@scoutfs-$(FULL_VERSION)/\1@" scoutfs-kmod.spec + gzip -f -9 $(TARFILE) + + +$(TARFILE).gz: tar + +rpm: $(TARFILE).gz scoutfs-kmod.spec + rpmbuild.sh $(TARFILE).gz + + clean: make $(SCOUTFS_ARGS) clean diff --git a/kmod/scoutfs-kmod.spec.in b/kmod/scoutfs-kmod.spec.in new file mode 100644 index 00000000..72ec10ea --- /dev/null +++ b/kmod/scoutfs-kmod.spec.in @@ -0,0 +1,72 @@ +%define kmod_name scoutfs +#%%trace + +%define _tar_version @@TAR_VERSION@@ +# official builds set this to 1, we use 0 for internal/dev-test +%{!?_release: %global _release 0} + +Name: %{kmod_name} +Summary: %{kmod_name} kernel module +Version: @@VERSION@@ +Release: %{_release}.@@RELEASE@@%{?dist} +License: GPLv2 +Group: System/Kernel +URL: http://versity.com + +BuildRequires: %kernel_module_package_buildreqs +ExclusiveArch: x86_64 + +# Sources. +Source0: scoutfs-kmod-%{_tar_version}.tar.gz + +# Build only for standard kernel variant(s); for debug packages, append "debug" +# after "default" (separated by space) +%kernel_module_package default + + +# Disable the building of the debug package(s). +%define debug_package %{nil} + +%description +%{kmod_name} - kernel module + + +%prep + + +%setup -q -n %{kmod_name}-%{_tar_version} +set -- * +mkdir source +mv "$@" source/ +mkdir obj + + +%build +echo "Building for kernel: %{kernel_version} flavors: '%{flavors_to_build}'" +echo "Build var: kmodtool = %{kmodtool}" +echo "Build var: kverrel = %{kverrel}" +for flavor in %flavors_to_build; do + rm -rf obj/$flavor + cp -r source obj/$flavor + make SK_KSRC=%{kernel_source $flavor} -C obj/$flavor module +done + + +%install +export INSTALL_MOD_PATH=$RPM_BUILD_ROOT +export INSTALL_MOD_DIR=extra/%{name} +for flavor in %flavors_to_build ; do + # TODO add Makefile rule + #make SK_KSRC=%{kernel_source $flavor} -C obj/$flavor modules_install + make -C %{kernel_source $flavor} modules_install \ + M=$PWD/obj/$flavor/src +done + + +%clean +rm -rf %{buildroot} + + +%changelog +* Fri Nov 17 2017 Nic Henke - 1.0 +- Initial version.