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