############################################################################ # # Makefile to build RPMs for the Linux driver for Peak CANBUS controllers. # # (c) Tom Dietel # ############################################################################ # # This Makefile downloads the specified version of the driver, creates # a .spec file, applies a patch to specify the location of the kernel # sources, and builds the RPM. # # The version to download must be specified in this Makefile, because # I do not know of a way to determine it automatically. Please check # the Peak web site http://www.peak-system.com for the latest versions # of the driver. # # The building of the RPM is done by installing the source-, spec- and # patch-files in an RPM top directory, where the package is built with # rpmbuild -ba to create binary and source RPMs. The RPM top dir # should be specified in ~/.rpmmacros, if the packages are built by a # user that does not have write access to the system top dir. # ############################################################################ ############################################################################ # user-defined settings ############################################################################ VERSION=$(shell awk '/^Version: / {print $$2}' pcan.spec) RELEASE=$(shell awk '/^Release: / {print $$2}' pcan.spec) ############################################################################ # automatic settings ############################################################################ KVERSION = $(shell uname -r) RPMTOPDIR = $(shell rpmbuild --eval '%{_topdir}' 2>/dev/null) TARGET = $(shell uname -m) PCAN_RPM = $(RPMTOPDIR)/RPMS/$(TARGET)/pcan-$(VERSION)-$(RELEASE).$(TARGET).rpm KMOD_RPM = $(RPMTOPDIR)/RPMS/$(TARGET)/kmod-pcan-$(VERSION)-$(RELEASE).$(TARGET).rpm DKMS_RPM = $(RPMTOPDIR)/RPMS/$(TARGET)/pcan-dkms-$(VERSION)-$(RELEASE).$(TARGET).rpm SRC_RPM = $(RPMTOPDIR)/SRPMS/pcan-$(VERSION)-$(RELEASE).src.rpm PEAKURL = http://www.peak-system.com/fileadmin/media/linux/files/ PKGREPO = https://alice.physi.uni-heidelberg.de/pkgrepo.cgi OSVERSION = $(shell lsb_release -sir | awk ' \ /CentOS 6\.[0-9]*/ {print "slc6"} \ /SLC 6\.[0-9]*/ {print "slc6"} \ /SLC 5\.[0-9]*/ {print "slc5"} \ ') # try to find something that can format HTML, fall back no formatting VIEWHTML := $(shell \ for i in "elinks -dump" "links -dump" "lynx -dump -stdin" ; do \ if echo "It works" \ | $$i 2>/dev/null | grep -q 'It works'; then \ echo $$i ; exit ;\ fi; \ done; \ echo 'cat -') ############################################################################ # package building ############################################################################ # build the RPM .PHONY: rpm rpm: $(PCAN_RPM) $(DKMS_RPM) $(SRC_RPM) $(PCAN_RPM) $(KMOD_RPM) $(DKMS_RPM) $(SRC_RPM): \ $(RPMTOPDIR)/SOURCES/peak-linux-driver.$(VERSION).tar.gz \ $(RPMTOPDIR)/SOURCES/pcan-redhat-kernel-location.patch \ $(RPMTOPDIR)/SOURCES/pcan-lib-install-symlinks.patch \ $(RPMTOPDIR)/SOURCES/pcan-get-can-dlc.patch \ $(RPMTOPDIR)/SPECS/pcan.spec rpmbuild --target=$(TARGET) \ -ba $(RPMTOPDIR)/SPECS/pcan.spec # install sources and spec file in RPM top dir $(RPMTOPDIR)/SOURCES/%: % mkdir -p $(dir $@) cp $< $@ $(RPMTOPDIR)/SPECS/%: % mkdir -p $(dir $@) cp $< $@ ############################################################################ # upload packages to ALICE TRD yum repository ############################################################################ upload: upload-pcan upload-dkms upload-srpm #@rm -f .pass upload-pcan: $(PCAN_RPM) .pass upload-kmod: $(KMOD_RPM) .pass upload-dkms: $(DKMS_RPM) .pass upload-srpm: $(SRC_RPM) .pass upload-pcan upload-kmod upload-dkms: PKGTYPE=$(OSVERSION)-$(TARGET) upload-srpm: PKGTYPE=$(OSVERSION)-src upload-%: @echo "Uploading $<..." @curl -s -u $(shell cat .pass) \ -F pkgfile=@$< -F pkgtype=$(PKGTYPE) $(PKGREPO) \ | $(VIEWHTML) @echo .pass: @echo "========================================================" @echo "enter credentials for package upload to yum repository" @echo "========================================================" @read -p 'username: ' U ; \ read -p 'password: ' -s P ; \ echo "$$U:$$P" > $@ @echo @chmod 600 $@ ############################################################################ # download upstream sources ############################################################################ .PHONY: download download: peak-linux-driver.$(VERSION).tar.gz peak-linux-driver.$(VERSION).tar.gz: wget -O $@ $(PEAKURL)/peak-linux-driver-$(VERSION).tar.gz ############################################################################ # produce patches # # This has been used once to produce the patch, then the patch is committed # and used to patch future versions of the software. # # This could be more user-friendly, by providing a means to unpack and # the software, ready to be diff'ed. ############################################################################ pcan-redhat-kernel-location.patch: diff -crB --exclude-from=diff.exclude \ peak-linux-driver-7.8.orig/ peak-linux-driver-7.8 \ > $@ || true pcan-lib-install-symlinks.patch: diff -crB --exclude-from=diff.exclude \ peak-linux-driver-7.8.orig/ peak-linux-driver-7.8 \ > $@ || true