xref: /llvm-project/libcxxabi/src/demangle/cp-to-llvm.sh (revision df9301ed5831f4c9dd531cbc9dd0d54de3210419)
1#!/bin/bash
2
3# Copies the 'demangle' library, excluding 'DemangleConfig.h', to llvm. If no
4# llvm directory is specified, then assume a monorepo layout.
5
6set -e
7
8cd $(dirname $0)
9HDRS="ItaniumDemangle.h ItaniumNodes.def StringViewExtras.h Utility.h"
10LLVM_DEMANGLE_DIR=$1
11
12if [[ -z "$LLVM_DEMANGLE_DIR" ]]; then
13    LLVM_DEMANGLE_DIR="../../../llvm/include/llvm/Demangle"
14fi
15
16if [[ ! -d "$LLVM_DEMANGLE_DIR" ]]; then
17    echo "No such directory: $LLVM_DEMANGLE_DIR" >&2
18    exit 1
19fi
20
21read -p "This will overwrite the copies of $HDRS in $LLVM_DEMANGLE_DIR; are you sure? [y/N]" -n 1 -r ANSWER
22echo
23
24if [[ $ANSWER =~ ^[Yy]$ ]]; then
25    cp -f README.txt $LLVM_DEMANGLE_DIR
26    chmod -w $LLVM_DEMANGLE_DIR/README.txt
27    for I in $HDRS ; do
28	rm -f $LLVM_DEMANGLE_DIR/$I
29	dash=$(echo "$I---------------------------" | cut -c -27 |\
30		   sed 's|[^-]*||')
31	sed -e '1s|^//=*-* .*\..* -*.*=*// *$|//===--- '"$I $dash"'-*- mode:c++;eval:(read-only-mode) -*-===//|' \
32	    -e '2s|^// *$|//       Do not edit! See README.txt.|' \
33	    $I >$LLVM_DEMANGLE_DIR/$I
34	chmod -w $LLVM_DEMANGLE_DIR/$I
35    done
36fi
37