xref: /netbsd-src/external/gpl3/gcc.old/dist/libsanitizer/merge.sh (revision c0a68be459da21030695f60d10265c2fc49758f8)
1#!/bin/bash
2
3# FIXME: do we need a license (or whatever else) header here?
4
5# This script merges libsanitizer sources from upstream.
6
7VCS=${1:-svn}
8
9get_upstream() {
10  rm -rf upstream
11  #cp -rf orig upstream
12  svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk upstream
13}
14
15get_current_rev() {
16  cd upstream
17  svn info | grep Revision | grep -o '[0-9]*'
18}
19
20list_files() {
21  (cd $1; ls *.{cc,h,inc,S} 2> /dev/null)
22
23}
24
25change_comment_headers() {
26  for f in $(list_files $1); do
27    sed -n 3p $1/$f | grep -q 'The LLVM Compiler Infrastructure' || continue
28    changed=$(awk 'NR != 2 && NR != 3' < $1/$f)
29    echo "$changed" > $1/$f
30  done
31}
32
33# ARGUMENTS: upstream_path local_path
34# This function merges changes from the directory upstream_path to
35# the directory  local_path.
36merge() {
37  upstream_path=upstream/$1
38  local_path=$2
39  change_comment_headers $upstream_path
40  echo MERGE: $upstream_path
41  all=$( (list_files $upstream_path; list_files $local_path) | sort | uniq)
42  #echo $all
43  for f in $all; do
44    if  [ -f $upstream_path/$f -a -f $local_path/$f ]; then
45      echo "FOUND IN BOTH     :" $f
46      # diff -u $local_path/$f $upstream_path/$f
47      cp -v $upstream_path/$f $local_path
48    elif [ -f $upstream_path/$f ]; then
49      echo "FOUND IN UPSTREAM :" $f
50      cp -v $upstream_path/$f $local_path
51      $VCS add $local_path/$f
52    elif [ -f $local_path/$f ]; then
53      echo "FOUND IN LOCAL    :" $f
54      $VCS rm $local_path/$f
55    fi
56  done
57
58}
59
60fatal() {
61  echo "$1"
62  exit 1;
63}
64
65pwd | grep 'libsanitizer$' || \
66  fatal "Run this script from libsanitizer dir"
67get_upstream
68CUR_REV=$(get_current_rev)
69echo Current upstream revision: $CUR_REV
70merge include/sanitizer include/sanitizer
71merge lib/asan asan
72merge lib/lsan lsan
73merge lib/tsan/rtl tsan
74merge lib/sanitizer_common sanitizer_common
75merge lib/interception interception
76merge lib/ubsan ubsan
77
78# Need to merge lib/builtins/assembly.h file:
79mkdir -p builtins
80cp -v upstream/lib/builtins/assembly.h builtins/assembly.h
81
82rm -rf upstream
83
84# Update the MERGE file.
85cat << EOF > MERGE
86$CUR_REV
87
88The first line of this file holds the svn revision number of the
89last merge done from the master library sources.
90EOF
91