Commit fabd0a32 authored by Federico Vaga's avatar Federico Vaga

dst: replace DKMS with RPM spec file

Prepare this product to be delivered as RPM package. This is a
perliminary work.
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 66da64be
HDL_DIR ?= $(TOP_DIR)/hdl
SW_DIR ?= $(TOP_DIR)/software
HDR_DIR ?= $(SW_DIR)/include
DST_DIR ?= $(TOP_DIR)/distribution
IS_GIT_TREE = $(shell git rev-parse --is-inside-work-tree 2> /dev/null)
ifeq ($(IS_GIT_TREE), true)
VERSION = $(shell git describe --abbrev=0 | tr -d 'v')
GIT_VERSION = $(shell git describe --dirty --long --tags)
else
ifndef VERSION
$(error "Missing VERSION")
endif
ifndef GIT_VERSION
$(error "Missing GIT_VERSION")
endif
endif
......@@ -2,6 +2,4 @@
#
# SPDX-License-Identifier: CC0-1.0
build
rpmbuild
sources
*rpmbuild*
......@@ -3,57 +3,93 @@
# SPDX-License-Identifier: CC0-1.0
TOP_DIR ?= $(shell pwd)/../
HDL_DIR ?= $(TOP_DIR)/hdl
include $(TOP_DIR)/common.mk
NAME := spec-fmc-carrier
VERSION := $(shell git describe --abbrev=0 | tr -d 'v')
GIT_VERSION := $(shell git describe --always --dirty --long --tags)
DIR_NAME := $(NAME)-$(VERSION)
# temporary RPMBUILD directory
RPMBUILD_NAME := $(NAME)-$(VERSION)-rpmbuild
RPMBUILD := $(DST_DIR)/$(RPMBUILD_NAME)
# SOURCES
SOURCES ?= $(RPMBUILD)/SOURCES
TARGZ := $(SOURCES)/$(DIR_NAME).tar.gz
CHANGELOG := $(SOURCES)/CHANGELOG
# SPEC files
SPECS_DIR ?= $(RPMBUILD)/SPECS
SPEC_NAME := $(NAME).spec
SPEC ?= $(SPECS_DIR)/$(SPEC_NAME)
DRIVER_NAME := spec-fmc-carrier
VERSION := $(shell git describe --abbrev=0)
DIR_NAME := $(DRIVER_NAME)-$(VERSION)
KEEP_TEMP ?= n
BUILD ?= $(abspath build)
BUILD_DKMS := $(BUILD)/dkms
BUILD_DKMSSOURCE := $(BUILD_DKMS)/source
BUILD_DKMSTREE := $(BUILD_DKMS)/tree
DKMS_OPT := --dkmstree $(BUILD_DKMSTREE) -m $(DRIVER_NAME)/$(VERSION)
CHEBY ?= cheby
GIT ?= git
all: kernel
ifeq (,$(shell which $(GIT)))
$(error "Missing git")
endif
CHEBY ?= cheby
ifeq (,$(shell which $(CHEBY)))
$(error "Missing cheby")
endif
spec-core-fpga.h:
$(CHEBY) --gen-c -i $(HDL_DIR)/rtl/spec_base_regs.cheby > /tmp/$@
kernel: dkms-tar dkms-rpm
all: rpm
dkms-tree:
@mkdir -p $(BUILD_DKMSSOURCE)
@mkdir -p $(BUILD_DKMSTREE)
#
# Build compressed sources tarball
#
targz: $(TARGZ)
$(TARGZ):
@mkdir -p $(SOURCES)
@GIT_DIR=$(TOP_DIR)/.git git archive --format=tar.gz -o $@ --prefix=$(DIR_NAME)/ HEAD
dkms-src: dkms-tree spec-core-fpga.h
$(eval $@_src := $(addprefix $(TOP_DIR), $(shell cd $(TOP_DIR) && git ls-tree -r --name-only HEAD software/kernel | grep -v -E "\/\." | tr '\n' ' ')))
$(eval $@_dir := $(BUILD_DKMSSOURCE)/$(DRIVER_NAME)-$(VERSION))
#
# CHANGE LOG needs to be converted into RPM format
#
CHANGELOG: $(CHANGELOG)
$(CHANGELOG): $(TOP_DIR)/CHANGELOG.rst
@mkdir -p $(SOURCES)
@cp $< $@
$(eval $@_pattern := ^([0-9.]+)\s-\s([0-9]{4}-[0-9]{2}-[0-9]{2})$)
$(eval $@_replace := echo -e "\n"\\* `date --date="\2" "+%a %b %d %Y"` "\1")
sed -r -i -e "/^[.]{2}/d" -e "/^\s{2}.*$$/d" $@
sed -r -i -e "/Change Log/d" -e "/^(=|-|\s)*$$/d" $@
sed -r -i -e 's,$($@_pattern),$($@_replace),e' $@
@mkdir -p $($@_dir)/platform_data
@mv /tmp/spec-core-fpga.h $($@_dir)
@cp -a $($@_src) $(TOP_DIR)/distribution/dkms.conf $($@_dir)
@mv $($@_dir)/gn412x-gpio.h $($@_dir)/platform_data
@cp -a $(TOP_DIR)/LICENSES/GPL-2.0-or-later.txt $($@_dir)/LICENSE
@sed -r -i -e "s/^VERSION\s=\s.*/VERSION = $(VERSION)/" $($@_dir)/Makefile
@sed -r -i -e "s/@PKGNAME@/$(DRIVER_NAME)/" $($@_dir)/dkms.conf
@sed -r -i -e "s/@PKGVER@/$(VERSION)/" $($@_dir)/dkms.conf
#
# The .spec file is good when we can define variables. With tools like
# koji it is not possible, so we need to create a .spec file without using
# package-specific variables.
#
$(SPEC): $(SPEC_NAME)
@mkdir -p $(SPECS_DIR)
cp $< $@
@sed -i -e "s/%{?_version}/$(VERSION)/" $@
@sed -i -e "s/%{?_git_version}/$(GIT_VERSION)/" $@
sources: $(TARGZ) $(CHANGELOG)
dkms-add: dkms-src
@dkms add $(DKMS_OPT) --sourcetree $(BUILD_DKMSSOURCE)
srpm: $(SPEC) sources
@rpmbuild -bs \
--define "_topdir $(RPMBUILD)" \
--define '_sourcedir $(SOURCES)' \
$<
dkms-tar: dkms-add
@dkms mktarball $(DKMS_OPT) --source-only
dkms-rpm: dkms-add
@dkms mkrpm $(DKMS_OPT) --source-only
#
# Build binary packages
#
rpm: $(SPEC) sources
ifdef LINUX
rpmbuild -bb --define "_topdir $(RPMBUILD)" \
--define "_sourcedir $(SOURCES)" \
--define "with_linux $(LINUX)" \
$<
else
rpmbuild -bb --define "_topdir $(RPMBUILD)" --define '_sourcedir $(SOURCES)' $<
endif
clean:
@rm -rf $(BUILD)
.PHONY: dkmstree dkms-add kernel-dkms-tar
@rm -rf $(RPMBUILD_NAME)*
# SPDX-FileCopyrightText: 2020 CERN (home.cern)
#
# SPDX-License-Identifier: CC0-1.0
PACKAGE_NAME="@PKGNAME@"
PACKAGE_VERSION="@PKGVER@"
CLEAN="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 clean"
MAKE[0]="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 all"
MAKE[1]="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 all"
MAKE[2]="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 all"
MAKE[3]="make KVERSION=$kernelver DKMSTREE=$dkms_tree DKMS=1 all"
BUILT_MODULE_NAME[0]="@PKGNAME@"
BUILT_MODULE_NAME[1]="gn412x-gpio"
BUILT_MODULE_NAME[2]="gn412x-fcl"
BUILT_MODULE_NAME[3]="spec-gn412x-dma"
DEST_MODULE_LOCATION[0]="/updates"
DEST_MODULE_LOCATION[1]="/updates"
DEST_MODULE_LOCATION[2]="/updates"
DEST_MODULE_LOCATION[3]="/updates"
BUILD_DEPENDS[0]="fmc"
BUILD_DEPENDS[1]="fpga_mgr"
BUILD_DEPENDS[2]="i2c-ocores"
AUTOINSTALL="yes"
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2022 CERN
# Path to the kernel sources
%{?!with_linux: %global with_linux /usr/src/kernels/`uname -r`}
%global kver %(basename %{with_linux})
#
# General Pacakge Information
#
Summary: Simple PCIe Carrier (SPEC)
Name: spec-fmc-carrier
Version: %{?_version}
License: GPL-3.0-or-later
Release: 1%{?dist}
URL: https://www.ohwr.org/projects/spec
ExclusiveArch: x86_64
BuildRequires: make
BuildRequires: gcc
BuildRequires: git
#BuildRequires: cheby
#
# Meta Pacakge
#
Requires: %{name}-kmod
Requires: %{name}-tools
Requires: %{name}-firmware
Source0: %{name}-%{version}.tar.gz
Source1: CHANGELOG
%description
This package is a meta package installing the SPEC driver and its reference firmware
#
# Preparation
#
%prep
%autosetup -n %{name}-%{version}
#
# Build
#
%build
export VERSION=%{version}
export GIT_VERSION=%{?_git_version}
export LINUX=%{with_linux}
%make_build -C software
#
# Install
#
%install
export VERSION=%{version}
export GIT_VERSION=%{?_git_version}
export DESTDIR=%{buildroot}/%{_exec_prefix}
%make_build -C software/include install
%make_build -C software/tools install
# Install manually to avoid running depmod at this stage
%{__install} -d %{buildroot}/lib/modules/%{kver}/extra/cern/%{name}
%{__install} -t %{buildroot}/lib/modules/%{kver}/extra/cern/%{name} software/kernel/*.ko
# Set the module(s) to be executable, so that they will be stripped when packaged.
find %{buildroot} -type f -name \*.ko -exec %{__chmod} u+x \{\} \;
#
# Clean
#
%clean
%{__rm} -rf %{buildroot}
#
# Changelog
#
%changelog
%include %{SOURCE1}
#
# Kmod
#
%package kmod
Summary: Simple PCIe Carrier (SPEC) Kmod
%description kmod
The SPEC kmod
%files kmod
%license LICENSES/GPL-3.0-or-later.txt
/lib/modules/%{kver}/extra/cern/%{name}/*.ko
#
# Python Class
#
# %package -n python-%{name}
# Summary: Simple PCIe Carrier (SPEC) Python Class
# Requires: Python3
# %description -n python3-%{name}
# The SPEC python class
# %files -n python3-%{name}
# %license LICENSES/GPL-3.0-or-later.txt
# %{python3_sitelib}/%{name}/
#
# Tools
#
%package tools
Summary: Simple PCIe Carrier (SPEC) Tools
%description tools
The SPEC tools
%files tools
%license LICENSES/GPL-3.0-or-later.txt
/usr/bin/spec-firmware-version
#
# Devel
#
%package devel
Summary: Simple PCIe Carrier (SPEC) Devel
%description devel
The SPEC development header files
%files devel
%license LICENSES/GPL-3.0-or-later.txt
/usr/include/linux/spec.h
/usr/include/linux/spec-core-fpga.h
#
# Firmware
#
%package firmware
Summary: Simple PCIe Carrier (SPEC) Firmware
%description firmware
The SPEC reference firmware supporing basic features
%files firmware
%license LICENSES/CERN-OHL-W-2.0+.txt
#/lib/firmware/spec-fmc-carrier-golden.bin
......@@ -5,17 +5,17 @@
-include Makefile.specific
-include $(REPO_PARENT)/parent_common.mk
DIRS = kernel tools
DIRS = include kernel tools
.PHONY: all clean modules install modules_install coccicheck cppcheck $(DIRS)
all : $(DIRS)
install modules_install coccicheck modules: kernel
all install modules_install coccicheck modules: $(DIRS)
modules: TARGET = modules
coccicheck: TARGET = coccicheck
install: TARGET = install
modules_install: TARGET = modules_install
cppcheck:
$(MAKE) -C tools $@
......
......@@ -5,12 +5,13 @@
-include Makefile.specific
-include $(REPO_PARENT)/parent_common.mk
TOP_DIR ?= $(shell pwd)/../..
include $(TOP_DIR)/common.mk
KVERSION ?= $(shell uname -r)
LINUX ?= /lib/modules/$(KVERSION)/build
TOP_DIR ?= $(shell pwd)/../..
HDL_DIR ?= $(TOP_DIR)/hdl
DKMS ?= 0
INSTALL_MOD_PATH ?=
INSTALL_MOD_DIR ?= extra/cern/spec-fmc-carrier
ifndef (CONFIG_FPGA_MGR_BACKPORT)
......@@ -21,18 +22,6 @@ CONFIG_FPGA_MGR_BACKPORT := y
endif
endif
ifeq ($(DKMS), 1)
FPGA_MGR_VERSION ?= $(shell basename $(shell ls -d $(DKMSTREE)/fpga_mgr/* | grep -E "\/[0-9]+\.[0-9]+\.[0-9]+" | sort -V | tail -n 1))
FMC_VERSION ?= $(shell basename $(shell ls -d $(DKMSTREE)/fmc/* | grep -E "\/[0-9]+\.[0-9]+\.[0-9]+" | sort -V | tail -n 1))
I2C_VERSION ?= $(shell basename $(shell ls -d $(DKMSTREE)/i2c-ocores/* | grep -E "\/[0-9]+\.[0-9]+\.[0-9]+" | sort -V | tail -n 1))
SPI_VERSION ?= $(shell basename $(shell ls -d $(DKMSTREE)/spi-ocores/* | grep -E "\/[0-9]+\.[0-9]+\.[0-9]+" | sort -V | tail -n 1))
FPGA_MGR ?= $(DKMSTREE)/fpga_mgr/$(FPGA_MGR_VERSION)/source
FMC ?= $(DKMSTREE)/fmc/$(FMC_VERSION)/source
I2C ?= $(DKMSTREE)/i2c-ocores/$(I2C_VERSION)/source
SPI ?= $(DKMSTREE)/spi-ocores/$(SPI_VERSION)/source
endif
ifdef REPO_PARENT
FPGA_MGR ?= $(REPO_PARENT)/fpga-mgr-backport/
FMC ?= $(REPO_PARENT)/fmc-sw/
......@@ -58,7 +47,6 @@ FMC_ABS ?= $(abspath $(FMC))
I2C_ABS ?= $(abspath $(I2C))
SPI_ABS ?= $(abspath $(SPI))
VERSION = $(shell git describe --dirty --long --tags)
CPPCHECK ?= cppcheck
all: modules
......@@ -73,7 +61,7 @@ headers:
modules: headers
$(MAKE) -C $(LINUX) M=$(shell pwd) \
VERSION=$(VERSION) \
VERSION=$(GIT_VERSION) \
FPGA_MGR_ABS=$(FPGA_MGR_ABS) \
CONFIG_FPGA_MGR_BACKPORT=$(CONFIG_FPGA_MGR_BACKPORT) \
FMC_ABS=$(FMC_ABS) \
......@@ -81,6 +69,18 @@ modules: headers
SPI_ABS=$(SPI_ABS) \
$@
install: modules_install
modules_install: modules
@$(MAKE) -C $(LINUX) M=$(shell pwd) \
INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) \
INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \
$@
clean:
@rm -f spec-core-fpga.h
@$(MAKE) -C $(LINUX) M=$(shell pwd) $@
INCLUDE := -I./
cppcheck:
$(CPPCHECK) -q $(INCLUDE) --suppress=missingIncludeSystem --enable=all *.c *.h --error-exitcode=1
......@@ -6,11 +6,14 @@
# specific Makefile code that you want to run before this. For example,
# build a particular environment.
-include Makefile.specific
TOP_DIR ?= $(shell pwd)/../..
include $(TOP_DIR)/common.mk
#
# Install variable
#
DESTDIR ?= /usr/local/
BINDIR ?= $(DESTDIR)/bin
TOOLS = spec-firmware-version
......@@ -19,7 +22,6 @@ TOOLS = spec-firmware-version
#
INCLUDE := -I. -I../kernel -I../include/uapi
CFLAGS = -ggdb $(INCLUDE) -Wall -Werror $(EXTRACFLAGS)
GIT_VERSION := $(shell git describe --dirty --long --tags)
CFLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\""
CPPCHECK ?= cppcheck
......@@ -37,8 +39,8 @@ clean:
rm -f $(TOOLS)
install:
install -d $(DESTDIR)/bin
install -D $(TOOLS) $(DESTDIR)/bin
install -d $(BINDIR)
install -D $(TOOLS) $(BINDIR)
cppcheck:
$(CPPCHECK) -q $(INCLUDE) --suppress=missingIncludeSystem --enable=all *.c *.h --error-exitcode=1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment