File tclhttpd.spec of Package tclhttpd

Name:           tclhttpd
Version:        3.5.1
Release:        2
Source0:        %name%version.tar.bz2
Group:          Productivity/Networking/Web/Servers
Summary:        Tcl Web Server
License:        unknown
Url:            http://www.tcl.tk/software/tclhttpd/
Requires:       tcllib

BuildRequires:  tcl-devel fdupes

%description
It is a pure-Tcl implementation of an HTTP protocol server. It runs as a script on top of a vanilla Tcl interpreter.

%if 0%{!?tclscriptdir:1}
%define tclscriptdir %(echo 'puts [ lindex $auto_path 0 ]' | tclsh)
%endif

%define _pkgdatadir %tclscriptdir/%name%version

##########
##########
%prep
%setup -q -n %name%version

##
## let linker set soname in libraries
##
sed -i \
	-e 's|\(\${SHLIB_LD} -o \$@ \$(\([^[:space:]]\+\)_OBJECTS) \${SHLIB_LDFLAGS} \${SHLIB_LD_LIBS}\)|\1 -Wl,-h,\$(\2_LIB_FILE)|' \
	-e 's|\$(COMPILE).*src/crypt.c.*|& -D_XOPEN_SOURCE|' \
	Makefile.in

##
## fix man page
##
sed -f - -i doc/httpd.1 <<-EOT
	/^.BS$/{
		a\\\\
		d
	}
	/^.BE$/d
	s/^\.DS\$/\n.in +4n\n.nf/g
	s/^\.DE\$/.fi\n.in\n/g
	/^.so man.macros\$/d
EOT

##
## fix a shebang
##
sed -i '1s|^#!.*$|#!/bin/sh|' bin/%name.etc.init

##
## update file paths
##
sed -i -r \
	-e 's|(set Config\(config\) \[file join) [^[:space:]]+|\1 %_sysconfdir|' \
	-e 's|(^set Config\(main\) .*Config\()home|\1lib|' \
	-e 's|(^set Config\([[:alpha:]]+\).*join )\[file dirname \$Config\(home\)\](.*)|\1/var/lib/%name\2|' \
	bin/httpd.tcl

sed -i 's|\^Config main.*|# &|' bin/%name.rc

##
## fix library paths in pkgIndex.tcl files
##
for LIB in crypt limit; do
	sed -i 's|\$dir @RELPATH@|%_libdir/'"$LIB"'1.0|' ${LIB}_pkgIndex.tcl.in
	tail ${LIB}_pkgIndex.tcl.in
done

##########
##########
%build
%configure --with-tclconfig=%_libdir --with-serverroot=/var/lib/%name
make CFLAGS="%optflags -DUSE_INTERP_RESULT=1 -fPIC" %_smp_mflags

##########
##########
%install

##
## install
##
%make_install

##
## find duplicated files
##
%fdupes -s %buildroot/var/lib

##
## fix file permissions
##
find %buildroot/var/lib/%name -type f -a \( -iname "*.css" -o -iname "*.html" -o -iname "*.org" -o -iname "*.tcl" -o -iname "*.exe" \) -exec chmod 644 {} \;
chmod 0644 %buildroot/var/lib/%name/htdocs/cgi-bin/junk
chmod 0755 %buildroot/var/lib/%name/%name.etc.init

##
## remove obsolete static binary file
##
rm %buildroot/var/lib/%name/htdocs/cgi-bin/env

##
## move pkgIndex.tcl files to subdirectories in _datadir/tcl
##
install -d -m 0755 %buildroot%tclscriptdir
mv %buildroot%_libdir/{{limit,crypt}1.0,%name%version} %buildroot%tclscriptdir/

##
## move a file from _bindir to a subdirectory in _datadir/tcl
##
install -p -m 0644 %buildroot{%_bindir/httpdthread.tcl,%_pkgdatadir/}
rm %buildroot%_pkgdatadir/httpdthread.tcl

##
## move config file to _sysconfdir
##
install -pD -m 0644 %buildroot{%_bindir,%_sysconfdir}/%name.rc
rm %buildroot%_bindir/%name.rc

##
## rename main program file to fit man page name
##
mv %buildroot%_bindir/httpd{.tcl,}

##
## move shared libraries to subdirectories
##
for i in crypt limit; do
	install -pD -m 0755 %buildroot%_libdir/{,${i}1.0/}lib${i}1.0.so
	rm  %buildroot%_libdir/lib${i}1.0.so
done


%files
%defattr(-,root,root,-)
%config /var/lib/*
%config %_sysconfdir/*
%_bindir/*
%tclscriptdir/*
%_libdir/*
%_mandir/man1/*


%changelog