]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - crypto/openssh/freebsd-namespace.sh
ssh: update FREEBSD-upgrade instructions
[FreeBSD/FreeBSD.git] / crypto / openssh / freebsd-namespace.sh
1 #!/bin/sh
2 #
3 # Namespace munging inspired by an equivalent hack in NetBSD's tree: add
4 # the "Fssh_" prefix to every symbol in libssh which doesn't already have
5 # it.  This prevents collisions between symbols in libssh and symbols in
6 # other libraries or applications which link with libssh, either directly
7 # or indirectly (e.g. through PAM loading pam_ssh).
8 #
9
10 set -e
11
12 eval "unset $(env | sed -nE 's/^(LC_[A-Z]+)=.*$/\1/p')"
13 export LANG=C
14
15 error() {
16         echo "$@" >&2
17         exit 1
18 }
19
20 # Locate the source directories
21 self=$(realpath ${0})
22 srcdir=${self%/*}
23 header=${srcdir}/ssh_namespace.h
24 top_srcdir=${srcdir%/crypto/openssh}
25 libssh_srcdir=${top_srcdir}/secure/lib/libssh
26
27 if [ ! -d ${srcdir} -o \
28      ! -f ${header} -o \
29      ! -d ${libssh_srcdir} -o \
30      ! -f ${libssh_srcdir}/Makefile ] ; then
31         error "Where is the libssh Makefile?"
32 fi
33
34 ncpu=$(sysctl -n hw.ncpu)
35 ssh_make() {
36         make -C${libssh_srcdir} -j$((ncpu + 1)) "$@"
37 }
38
39 # Clear out, recreate and locate the libssh build directory
40 ssh_make cleandir
41 ssh_make cleandir
42 ssh_make obj
43 libssh_builddir=$(realpath $(ssh_make -V.OBJDIR))
44 libssh=libprivatessh.a
45
46 # Clear the existing header
47 generated="@""generated"
48 cat >${header} <<EOF
49 /*
50  * This file was machine-$generated.  Do not edit manually.
51  * Run crypto/openssh/freebsd-namespace.sh to regenerate.
52  */
53 EOF
54
55 # Build libssh
56 ssh_make depend
57 ssh_make ${libssh}
58 if [ ! -f ${libssh_builddir}/${libssh} ] ; then
59         error "Where is ${libssh}?"
60 fi
61
62 # Extract symbols
63 nm ${libssh_builddir}/${libssh} | awk '
64      /^[0-9a-z]+ [Tt] [A-Za-z_][0-9A-Za-z_]*$/ && $3 !~ /^Fssh_/ {
65          printf("#define %-39s Fssh_%s\n", $3, $3)
66      }
67 ' | unexpand -a | sort -u >>${header}
68
69 # Clean and rebuild the library
70 ssh_make clean
71 ssh_make ${libssh}
72
73 # Double-check
74 nm ${libssh_builddir}/${libssh} | awk '
75     /^[0-9a-z]+ [Tt] [A-Za-z_][0-9A-Za-z_]*$/ && $3 !~ /^Fssh_/ {
76          printf("ERROR: %s was not renamed!\n", $3);
77          err++;
78     }
79     END {
80         if (err > 0)
81             exit(1);
82     }
83 '