Fix kernel version detection
[profile/ivi/OpenAVB.git] / packaging / openavb.spec
1 %{!?_with_debug:%{!?_without_debug:%define _without_debug 0}}
2
3 %define kernel "%(/bin/rpm -q --whatprovides kernel-profile-ivi)"
4 %define kernel_relstr "%(/bin/rpm -q --queryformat '%{VERSION}-%{RELEASE}' %{kernel})"
5 %define kernel_release %(echo %{kernel_relstr})
6 %define kernel_modstr "%(/bin/rpm -ql %{kernel} | sort | grep /lib/modules/%{kernel_release} | head -1 | sed 's#/*$##g')"
7 %define kernel_modpath %(echo %{kernel_modstr})
8 %define kernel_moddir  %(echo %{kernel_modstr} | sed 's#.*/##g')
9
10 Summary: OpenAVB
11 Name: openavb
12 Version: 20140731
13 Release: 1
14 License: Intel and GPL-2.0
15 Group: Automotive/Ethernet AVB
16 URL: https://github.com/intel-ethernet/Open-AVB
17 Source0: %{name}-%{version}.tar.gz
18 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
19 Requires: openavb-kmod-igb
20 ExclusiveArch:  %ix86 x86_64
21
22 %ifarch %ix86
23 # Temporary to address "have choice for kernel-devel"
24 BuildRequires: kernel-ivi-i386-default-devel
25 %else
26 BuildRequires: kernel-devel
27 %endif
28 BuildRequires: libstdc++-devel
29 BuildRequires: pkgconfig(libpci)
30 BuildRequires: pkgconfig(zlib)
31
32 %package kmod-igb
33 Summary: kernel module for Intel ethernet cards
34 Group: System/Kernel
35 Requires: kernel-profile-ivi = %{kernel_release}
36
37 %package libigb
38 Summary: IGB runtime library
39 Group: System/Libraries
40
41 %package examples
42 Summary: Example clients
43 Group: Applications/System
44 Requires: openavb-libigb = %{version}
45
46 %package devel
47 Summary: Headers and libraries
48 Group: Development/Libraries
49 Requires: %{name} = %{version}
50
51 %package doc
52 Summary: Documentation
53 Group: Development/Tools
54
55 %description
56 This package contains the basic OpenAVB userspace daemons.
57
58 %description kmod-igb
59 This package contains the kernel module required by OpenAVB for Intel
60 ethernet cards.
61
62 %description libigb
63 This package contains the libigb runtime library from the OpenAVB
64 distribution.
65
66 %description examples
67 This package contains various test and example utilities for OpenAVB.
68
69 %description devel
70 This package contains header files and libraries for OpenAVB.
71
72 %description doc
73 This package contains some documentation from the OpenAVB distribution.
74
75 %prep
76 %setup -q
77
78 %build
79 # For now, always compile for debugging...
80 #%if %{?_with_debug:1}%{!?_with_debug:0}
81 export CFLAGS="-O0 -g3"
82 export CXXFLAGS="-O0 -g3"
83 #%endif
84
85 NUM_CPUS="`cat /proc/cpuinfo | tr -s '\t' ' ' | \
86                grep '^processor *:' | wc -l`"
87 [ -z "$NUM_CPUS" ] && NUM_CPUS=1
88
89 CONFIG_OPTIONS="--enable-kmod-flags=EXTRA_CFLAGS=-DIGB_PTP"
90
91 ./bootstrap && \
92     %configure $CONFIG_OPTIONS  && \
93     make BUILD_KERNEL=%{kernel_moddir} clean && \
94     make BUILD_KERNEL=%{kernel_moddir} -j$(($NUM_CPUS + 1))
95
96 %install
97 rm -rf $RPM_BUILD_ROOT
98
99 make DESTDIR=$RPM_BUILD_ROOT \
100     INSTALL_MOD_PATH=$RPM_BUILD_ROOT \
101     BUILD_KERNEL=%{kernel_moddir} install
102
103 rm -f $RPM_BUILD_ROOT%{_libdir}/libigb.la
104
105 # Install systemd and sample 'configuration' files.
106 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig \
107     $RPM_BUILD_ROOT/lib/systemd/system \
108     %{buildroot}/%{_sysconfdir}/modprobe.d
109 /usr/bin/install -m 644 packaging/openavb.env \
110     $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/openavb
111 /usr/bin/install -m 644 -t $RPM_BUILD_ROOT/lib/systemd/system \
112     packaging/mrpd.service packaging/gptp.service
113 /usr/bin/install -m 644 packaging/igb_avb.conf \
114     %{buildroot}/%{_sysconfdir}/modprobe.d
115
116 %clean
117 rm -rf $RPM_BUILD_ROOT
118
119 %post libigb
120 ldconfig
121
122 %postun libigb
123 ldconfig
124
125 %post kmod-igb
126 depmod -a %{kernel_moddir}
127
128 %files
129 %defattr(-,root,root,-)
130 %{_sbindir}/daemon_cl
131 %{_sbindir}/mrpd
132 %{_bindir}/mrpctl
133 %{_sysconfdir}/sysconfig/openavb
134 /lib/systemd/system/mrpd.service
135 /lib/systemd/system/gptp.service
136
137 %files kmod-igb
138 %defattr(-,root,root,-)
139 %{kernel_modpath}/kernel/drivers/net/igb_avb
140 %config(noreplace)%{_sysconfdir}/modprobe.d/igb_avb.conf
141
142 %files libigb
143 %defattr(-,root,root,-)
144 %{_libdir}/libigb.so.*
145
146 %files examples
147 %defattr(-,root,root,-)
148 %{_bindir}/mrpl
149 %{_bindir}/mrpq
150 %{_bindir}/simple_talker
151
152 %files devel
153 %defattr(-,root,root,-)
154 %{_includedir}/igb
155 %{_libdir}/libigb.so
156 %{_libdir}/pkgconfig/igb.pc
157
158 %files doc
159 %defattr(-,root,root,-)
160 %doc README.rst documents
161 %license examples/LICENSE
162 %doc examples/mrp_client examples/simple_listener examples/simple_talker