Added builder for RPMs

This commit is contained in:
Mark Feit 2020-12-08 21:09:18 +00:00 committed by Phil Olynyk
parent d357c37edd
commit 35aec29910
7 changed files with 414 additions and 0 deletions

6
Building/Linux/rpm/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.ccache
# This is ignored in a parent directory
!Makefile*
*~

View File

@ -0,0 +1,38 @@
# Front end for second-stage Makefile
include Makefile.common
# Second-stage make, which does the actual work.
MAKE2 := $(MAKE) -f Makefile-stage2
default: build
%: $(SPEC)
$(MAKE2) $@
# Build the spec with a valid version.
VERSION_FILE := VERSION
VERSION_SOURCE := $(TOP)/oscar/VERSION
VERSION := $(shell egrep -e '\#define\s+VERSION\s+' '$(VERSION_SOURCE)' \
| sed -e 's/^.* //g' \
| tr -d '"' \
| tr -- - . \
)
SPEC=$(NAME).spec
$(SPEC): $(SPEC).raw Makefile
sed -e 's/__VERSION__/$(VERSION)/g' $< > $@
TO_CLEAN += $(SPEC)
build: $(SPEC)
$(MAKE2)
clean:: $(SPEC)
$(MAKE2) $@
rm -f $(TO_CLEAN)

View File

@ -0,0 +1,21 @@
#
# Makefile for Most Packages
#
AUTO_TARBALL=1
include generic-rpm.make
# Build a copy of the Git repository so it can be built into a tarball
TOP := $(shell git rev-parse --show-toplevel)
WHEREAMI = $(shell cd $(PWD) && pwd)
EXCLUDE := $(echo "$(WHEREAMI)" | sed -e 's|^$(TOP)/||')
GIT_DIR := $(notdir $(TOP))
$(GIT_DIR):
mkdir -p "$@"
(cd $(TOP) && tar cf - --exclude Building/Linux/rpm .) \
| (cd "$@" && tar xpf -)
TO_CLEAN += $(GIT_DIR)

View File

@ -0,0 +1,9 @@
#
# Common Makefile values
#
NAME := OSCAR
TOP := $(shell git rev-parse --show-toplevel)
WHEREAMI := $(shell cd $(PWD) && pwd)
EXCLUDE := $(echo "$(WHEREAMI)" | sed -e 's|^$(TOP)/||')

View File

@ -0,0 +1,102 @@
#
# RPM Spec for OSCAR
#
%define short OSCAR
%define long %{short}-code
Name: OSCAR
Version: __VERSION__
Release: 1%{?dist}
Summary: Open-Source CPAP Analyser and Reporter
BuildArch: %(uname -m)
License: GNU GPL v3
Vendor: Phil Olynyk
Group: Unspecified
Source0: %{long}-%{version}.tar.gz
Provides: %{name} = %{version}-%{release}
# RPM requires definitions be at least three characters. Go figure.
%define q_t qt5
%define qmake qmake-%{q_t}
%define icons %{_datadir}/icons/hicolor
Requires: %{q_t}
BuildRequires: dnf-utils
BuildRequires: %{q_t}-devel
%description
OSCAR is a cross-platform, open-source sleep tracking program for
reviewing CPAP and oximetry data, which are devices used in the
treatment of Sleep Disorders like Obstructive Sleep Apnea.
# Don't build a debug package.
%define debug_package %{nil}
%prep
%setup -q -n %{long}-%{version}
%build
%{qmake} OSCAR_QT.pro
make -j
%install
# Binary
install -D -m 555 ./oscar/%{short} "${RPM_BUILD_ROOT}/%{_bindir}/%{short}"
# Icons
for SIZE in 32 48 64 128 256 512 1024
do
echo "SIZE $SIZE"
install -D -m 555 \
"./Building/Icons/Full-${SIZE}.png" \
"${RPM_BUILD_ROOT}/%{icons}/${SIZE}x${SIZE}/apps/%{name}.png"
done
# Desktop
install -D -m 555 "Building/Linux/%{short}.desktop" \
"${RPM_BUILD_ROOT}/%{_datadir}/applications/%{short}.desktop"
%post
touch --no-create %{icons} &>/dev/null || true
update-desktop-database &> /dev/null || true
if [ $1 -eq 0 ] ; then
touch --no-create %{icons} &>/dev/null
gtk-update-icon-cache %{icons} &>/dev/null || true
fi
%postun
update-desktop-database &> /dev/null || true
if [ $1 -eq 0 ] ; then
touch --no-create %{icons} &>/dev/null
gtk-update-icon-cache %{icons} &>/dev/null || true
fi
%posttrans
gtk-update-icon-cache %{icons} &>/dev/null || true
%files
%defattr(-,root,root,-)
%license COPYING
%{_bindir}/*
%{icons}/*/apps/*
%{_datadir}/applications/*

View File

@ -0,0 +1,20 @@
# RPM Builder for Linux
The Makefile in this directory builds OSCAR as an RPM.
## Build Process
* Clone this repository
* `cd Building/Linux/rpm`
* `sudo make`
Build by-products can be removed with `sudo make clean`.
## Assumptions
`git rev-parse` is used to determine the top-level directory, ergo
this tree must have been cloned from GitLab and `git` must be
installed.

View File

@ -0,0 +1,218 @@
#
# Generic Makefile for RPMs
#
# Original source: https://github.com/perfsonar/pscheduler/tree/master/make-generic-rpm
# Licensed Apache Software License Version 2.0
#
# To use this file, create a Makefile containing the following:
#
# inclulde make/generic-rpm.make
#
# Targets (Shortcuts in Parentheses):
#
# build (b) - Build the RPM. This is the default target.
# clean (c) - Remove build by-products
# install (i) - Install the RPM forcibly. Must be run as a user
# that can do this.
# rpmdump (r) - Dump contents of built RPMs.
#
# Other useful shortcut targets:
#
# cb - Clean and build
# cbr - Clean, build and rpmdump
# cbi - Clean, build and install
# cbic - Clean, build and install and forced re-clean
# cbrc - Clean, build, rpmdump and forced re-clean
#
#
# To construct a tarball of your sources automatically:
#
# - Name a subdirectory with the name of the product (e.g, foomatic)
# - Specify a tarball in the source (e.g., Source0: foomatic-1.3.tar.gz)
# - Set AUTO_TARBALL=1 in your makefile
#
# NOTE: The version number in the spec may not contain hyphens.
#
#
# NO USER-SERVICEABLE PARTS BELOW THIS LINE
#
default: build
#
# Spec file and things derived from it
#
# Do this in a POSIX-y way, which precludes mindepth.
SPEC := $(shell find . -name '*.spec' | sed -e '/^\.\/[^/]*$$/!d; s/^\.\///')
ifeq "$(words $(SPEC))" "0"
$(error No spec in this directory)
endif
ifneq "$(words $(SPEC))" "1"
$(error This directory contains more than one spec file)
endif
NAME := $(shell echo "$(SPEC)" | sed -e 's/\.spec$$//')
VERSION := $(shell rpmspec -P "$(SPEC)" | awk '$$1 == "Version:" { print $$2 }')
SOURCE_FILES := $(shell spectool -S $(SPEC) | awk '{ print $$2 }')
PATCH_FILES := $(shell spectool -P $(SPEC) | awk '{ print $$2 }')
#
# Automagic source tarball construction
#
ifdef AUTO_TARBALL
ifeq "$(words $(SOURCE_FILES))" "0"
$(error No need to set AUTO_TARBALL with no sources in spec file)
endif
ifeq "$(shell [ $(words $(SOURCE_FILES)) -gt 1 ]; echo $$?)" "0"
$(error Cannot automatically build a tarball from multiple sources)
endif
ifneq "$(findstring -, $(VERSION))" ""
$(error The version number in the spec may not contain hyphens.)
endif
TARBALL_SOURCE=$(shell echo $(SOURCE_FILES) | sed -e 's/-[^-]*\.tar\.gz$$//')
TARBALL_NAME=$(TARBALL_SOURCE)-$(VERSION)
TARBALL=$(TARBALL_NAME).tar.gz
ALL_TARBALLS=$(TARBALL_SOURCE)-*.tar.gz
$(TARBALL): $(TARBALL_SOURCE)
cp -r $(TARBALL_SOURCE) $(TARBALL_NAME)
tar czf $@ $(TARBALL_NAME)
rm -rf $(TARBALL_NAME)
BUILD_DEPS += $(TARBALL)
TO_CLEAN += $(TARBALL) $(TARBALL_NAME) $(ALL_TARBALLS)
endif
#
# RPM Build Directory
#
BUILD_DIR=./rpmbuild
BUILD_BUILD=$(BUILD_DIR)/BUILD
BUILD_RPMS=$(BUILD_DIR)/RPMS
BUILD_SOURCES=$(BUILD_DIR)/SOURCES
BUILD_SPECS=$(BUILD_DIR)/SPECS
BUILD_SRPMS=$(BUILD_DIR)/SRPMS
BUILD_SUBS=\
$(BUILD_BUILD) \
$(BUILD_RPMS) \
$(BUILD_SOURCES) \
$(BUILD_SPECS) \
$(BUILD_SRPMS) \
$(BUILD_DIR): $(SPEC) $(SOURCE_FILES)
rm -rf $@
mkdir -p $(BUILD_SUBS)
cp $(SPEC) $(BUILD_SPECS)
ifneq "$(words $(SOURCE_FILES))" "0"
cp $(SOURCE_FILES) $(BUILD_SOURCES)
endif
ifneq "$(words $(PATCH_FILES))" "0"
cp $(PATCH_FILES) $(BUILD_SOURCES)
endif
TO_CLEAN += $(BUILD_DIR)
BUILD_ROOT=./BUILD-ROOT
$(BUILD_ROOT):
mkdir -p $@
TO_CLEAN += $(BUILD_ROOT)
RPM=rpm
RPMBUILD=rpmbuild
#
# Useful Targets
#
build:: $(BUILD_DEPS) $(BUILD_DIR) $(BUILD_ROOT)
set -o pipefail \
&& dnf builddep $(SPEC) \
&& HOME=$(shell pwd) \
$(RPMBUILD) -ba \
--buildroot $(shell cd $(BUILD_ROOT) && pwd) \
$(SPEC) 2>&1 \
| tee build.log
find $(BUILD_DIR) -name '*.rpm' | xargs -I{} cp {} .
TO_CLEAN += build.log
TO_CLEAN += *.rpm
srpm:: $(BUILD_DEPS) $(BUILD_DIR)
HOME=$(shell pwd) rpmbuild -v -bs $(RPMBUILD_OPTS) $(SPEC)
find $(BUILD_DIR) -name '*.src.rpm' | xargs -I{} cp {} .
TO_CLEAN += *.src.rpm
rpmdump::
@if [ -d "$(BUILD_RPMS)" ] ; then \
for RPM in `find $(BUILD_RPMS) -name '*.rpm'` ; do \
echo `basename $${RPM}`: ; \
rpm -qpl $$RPM 2>&1 | sed -e 's/^/\t/' ; \
echo ; \
done ; \
else \
echo "RPMs are not built." ; \
false ; \
fi
install::
find $(BUILD_RPMS) -name '*.rpm' | xargs $(RPM) -Uvh --force
clean::
rm -rf $(TO_CLEAN)
find . -name '*~' | xargs rm -rf
find . -depth -name Makefile \
-exec /bin/sh -c \
'[ "{}" != "./Makefile" ] && make -C `dirname {}` clean' \;
# Placeholder for running unit tests.
test::
@true
#
# Convenient shorthands
#
b: build
c: clean
i: install
r: rpmdump
cb: c b
cbr: c b r
cbi: c b i
# CBI with forced clean afterward
cbic: cbi
$(MAKE) clean
# CBR with forced clean afterward
cbrc: cbr
$(MAKE) clean