14f52dfbbSDag-Erling Smørgrav#!/bin/sh 24f52dfbbSDag-Erling Smørgrav# 34f52dfbbSDag-Erling Smørgrav# Namespace munging inspired by an equivalent hack in NetBSD's tree: add 44f52dfbbSDag-Erling Smørgrav# the "Fssh_" prefix to every symbol in libssh which doesn't already have 54f52dfbbSDag-Erling Smørgrav# it. This prevents collisions between symbols in libssh and symbols in 64f52dfbbSDag-Erling Smørgrav# other libraries or applications which link with libssh, either directly 74f52dfbbSDag-Erling Smørgrav# or indirectly (e.g. through PAM loading pam_ssh). 84f52dfbbSDag-Erling Smørgrav# 94f52dfbbSDag-Erling Smørgrav 104f52dfbbSDag-Erling Smørgravset -e 114f52dfbbSDag-Erling Smørgrav 124f52dfbbSDag-Erling Smørgraveval "unset $(env | sed -nE 's/^(LC_[A-Z]+)=.*$/\1/p')" 134f52dfbbSDag-Erling Smørgravexport LANG=C 144f52dfbbSDag-Erling Smørgrav 154f52dfbbSDag-Erling Smørgraverror() { 164f52dfbbSDag-Erling Smørgrav echo "$@" >&2 174f52dfbbSDag-Erling Smørgrav exit 1 184f52dfbbSDag-Erling Smørgrav} 194f52dfbbSDag-Erling Smørgrav 204f52dfbbSDag-Erling Smørgrav# Locate the source directories 214f52dfbbSDag-Erling Smørgravself=$(realpath ${0}) 224f52dfbbSDag-Erling Smørgravsrcdir=${self%/*} 234f52dfbbSDag-Erling Smørgravheader=${srcdir}/ssh_namespace.h 244f52dfbbSDag-Erling Smørgravtop_srcdir=${srcdir%/crypto/openssh} 254f52dfbbSDag-Erling Smørgravlibssh_srcdir=${top_srcdir}/secure/lib/libssh 264f52dfbbSDag-Erling Smørgrav 274f52dfbbSDag-Erling Smørgravif [ ! -d ${srcdir} -o \ 284f52dfbbSDag-Erling Smørgrav ! -f ${header} -o \ 294f52dfbbSDag-Erling Smørgrav ! -d ${libssh_srcdir} -o \ 304f52dfbbSDag-Erling Smørgrav ! -f ${libssh_srcdir}/Makefile ] ; then 314f52dfbbSDag-Erling Smørgrav error "Where is the libssh Makefile?" 324f52dfbbSDag-Erling Smørgravfi 334f52dfbbSDag-Erling Smørgrav 344f52dfbbSDag-Erling Smørgravncpu=$(sysctl -n hw.ncpu) 354f52dfbbSDag-Erling Smørgravssh_make() { 364f52dfbbSDag-Erling Smørgrav make -C${libssh_srcdir} -j$((ncpu + 1)) "$@" 374f52dfbbSDag-Erling Smørgrav} 384f52dfbbSDag-Erling Smørgrav 394f52dfbbSDag-Erling Smørgrav# Clear out, recreate and locate the libssh build directory 404f52dfbbSDag-Erling Smørgravssh_make cleandir 414f52dfbbSDag-Erling Smørgravssh_make cleandir 424f52dfbbSDag-Erling Smørgravssh_make obj 434f52dfbbSDag-Erling Smørgravlibssh_builddir=$(realpath $(ssh_make -V.OBJDIR)) 444f52dfbbSDag-Erling Smørgravlibssh=libprivatessh.a 454f52dfbbSDag-Erling Smørgrav 464f52dfbbSDag-Erling Smørgrav# Clear the existing header 47*b3e858f7SEd Mastegenerated="@""generated" 484f52dfbbSDag-Erling Smørgravcat >${header} <<EOF 494f52dfbbSDag-Erling Smørgrav/* 50*b3e858f7SEd Maste * This file was machine-$generated. Do not edit manually. 514f52dfbbSDag-Erling Smørgrav * Run crypto/openssh/freebsd-namespace.sh to regenerate. 524f52dfbbSDag-Erling Smørgrav */ 534f52dfbbSDag-Erling SmørgravEOF 544f52dfbbSDag-Erling Smørgrav 554f52dfbbSDag-Erling Smørgrav# Build libssh 564f52dfbbSDag-Erling Smørgravssh_make depend 574f52dfbbSDag-Erling Smørgravssh_make ${libssh} 584f52dfbbSDag-Erling Smørgravif [ ! -f ${libssh_builddir}/${libssh} ] ; then 594f52dfbbSDag-Erling Smørgrav error "Where is ${libssh}?" 604f52dfbbSDag-Erling Smørgravfi 614f52dfbbSDag-Erling Smørgrav 624f52dfbbSDag-Erling Smørgrav# Extract symbols 634f52dfbbSDag-Erling Smørgravnm ${libssh_builddir}/${libssh} | awk ' 644f52dfbbSDag-Erling Smørgrav /^[0-9a-z]+ [Tt] [A-Za-z_][0-9A-Za-z_]*$/ && $3 !~ /^Fssh_/ { 654f52dfbbSDag-Erling Smørgrav printf("#define %-39s Fssh_%s\n", $3, $3) 664f52dfbbSDag-Erling Smørgrav } 674f52dfbbSDag-Erling Smørgrav' | unexpand -a | sort -u >>${header} 684f52dfbbSDag-Erling Smørgrav 694f52dfbbSDag-Erling Smørgrav# Clean and rebuild the library 704f52dfbbSDag-Erling Smørgravssh_make clean 714f52dfbbSDag-Erling Smørgravssh_make ${libssh} 724f52dfbbSDag-Erling Smørgrav 734f52dfbbSDag-Erling Smørgrav# Double-check 744f52dfbbSDag-Erling Smørgravnm ${libssh_builddir}/${libssh} | awk ' 754f52dfbbSDag-Erling Smørgrav /^[0-9a-z]+ [Tt] [A-Za-z_][0-9A-Za-z_]*$/ && $3 !~ /^Fssh_/ { 764f52dfbbSDag-Erling Smørgrav printf("ERROR: %s was not renamed!\n", $3); 774f52dfbbSDag-Erling Smørgrav err++; 784f52dfbbSDag-Erling Smørgrav } 794f52dfbbSDag-Erling Smørgrav END { 804f52dfbbSDag-Erling Smørgrav if (err > 0) 814f52dfbbSDag-Erling Smørgrav exit(1); 824f52dfbbSDag-Erling Smørgrav } 834f52dfbbSDag-Erling Smørgrav' 84