diff --git a/Makefile b/Makefile index eba3e9c..5941712 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/share/man CFLAGS = -O2 -g -std=c99 -fno-strict-aliasing -Wall -W -D_GNU_SOURCE -I/usr/local/include +CFLAGS += -I/usr/include/libev LDFLAGS = -lssl -lcrypto -lev -L/usr/local/lib OBJS = stud.o ringbuffer.o configuration.o @@ -48,5 +49,18 @@ install: $(ALL) clean: rm -f stud $(OBJS) +GIT_VERSION=$(shell git describe) +VERSION_MAJOR=$(firstword $(subst -, ,$(GIT_VERSION))) +TMPDIR=$(shell pwd)/.rpmbuild + +rpm: + mkdir -p ${TMPDIR}/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + git archive HEAD . --prefix=stud-$(VERSION_MAJOR)/ \ + > ${TMPDIR}/SOURCES/stud-source.tar + sed -re s/GIT_VERSION/$(shell git describe)/ \ + rhel/stud.spec > ${TMPDIR}/SPECS/stud.spec + rpmbuild --define "_topdir ${TMPDIR}" \ + -bb ${TMPDIR}/SPECS/stud.spec $(if $(USE_SHARED_CACHE),--with cache,) + find ${TMPDIR}/RPMS/ -type f -name "*.rpm" -exec mv {} . \; .PHONY: all realall diff --git a/rhel/stud.spec b/rhel/stud.spec new file mode 100644 index 0000000..f5a288a --- /dev/null +++ b/rhel/stud.spec @@ -0,0 +1,90 @@ +# The GIT_VERSION token below is automatically changed to the value of +# `git describe` by the top-level Makefile's "rpm" build target +%define git_version GIT_VERSION +# +# The git version is -#-sha1, where the is the most recent +# annotated git tag, # is the number of commits since the tag, and the +# sha1 is 'g' plus the first 7 chars of the most recent commit sha1-id +# on the branch being compiled +# +# This will split the version information back into the (version) +# and the #-sha1 (post_tag) parts +# +%define version %(echo %{git_version} | cut -d- -f1) +%define post_tag %(echo %{git_version} | cut -s -d- -f2- | sed -e s/-/_/g) +%if x%{post_tag} == "x" + %undefine post_tag +%endif + +# Use --with cache to build the RPM with the USE_SHARED_CACHE feature +%bcond_with cache + +Name: stud +Version: %{version} +Release: %{?post_tag}%{!?post_tag:1}%{?dist} +Summary: The Scalable TLS Unwrapping Daemon + +Group: Productivity/Networking/Web/Proxy +License: BSD +URL: https://github.com/bumptech/stud +Source0: stud-source.tar + +BuildRequires: libev-devel +Requires: libev openssl + +%description +stud is a network proxy that terminates TLS/SSL connections and forwards the +unencrypted traffic to some backend. It's designed to handle 10s of +thousands of connections efficiently on multicore machines. + +%prep +%setup -q +%if %{with cache} +mkdir ebtree +curl http://1wt.eu/tools/ebtree/ebtree-6.0.8.tar.gz | tar xzf - -C "ebtree" --strip 1 +%endif + +%build +make %{?_smp_mflags} %{?_with_cache:USE_SHARED_CACHE=1} + + +%install +rm -rf %{buildroot} +make install DESTDIR=%{buildroot} PREFIX=/usr %{?_with_cache:USE_SHARED_CACHE=1} +install -d %{buildroot}/etc/init.d +install init.stud %{buildroot}/etc/init.d/stud + +%clean +rm -rf %{buildroot} + + +%files +%defattr(-,root,root,-) +/usr/bin/stud +/etc/init.d/stud +%doc +/usr/share/man/man8 + + +%preun +if [ "$1" = "0" ]; then + service stud stop 2>/dev/null + true +fi + +%postun +if [ "$1" = "0" ]; then + # remove rundir + rm -rf /var/run/stud >/dev/null 2>&1 + + # remove config dir + rm -rf /etc/stud >/dev/null 2>&1 +fi + +%post +mkdir -p /var/run/stud +mkdir -p /etc/stud + + +%changelog +