summaryrefslogtreecommitdiff
path: root/devel/import-minitasn1.sh
blob: d8b48daac865d15109cce65c856eebeece273463 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

# This script copies files from the libtasn1 upstream, with necessary
# adjustments for bundling in GnuTLS.

set +e

: ${srcdir=.}
SRC=$srcdir/devel/libtasn1/lib
DST=$srcdir/lib/minitasn1

IMPORTS="
coding.c
decoding.c
element.c
element.h
errors.c
gstr.c
gstr.h
int.h
parser_aux.c
parser_aux.h
structure.c
structure.h
version.c
libtasn1.h
"

test -d $DST || mkdir $DST

ASN1_VERSION=`grep AC_INIT $SRC/../configure.ac | sed -e 's/.*\],\[\([^]]*\)\],\[.*/\1/g'`
ASN1_VERSION_MAJOR=`echo ${ASN1_VERSION} | cut -d . -f 1`
ASN1_VERSION_MINOR=`echo ${ASN1_VERSION} | cut -d . -f 2`
ASN1_VERSION_PATCH=`echo ${ASN1_VERSION} | cut -d . -f 3`
ASN1_VERSION_NUMBER=`printf '0x%02x%02x%02x' $ASN1_VERSION_MAJOR $ASN1_VERSION_MINOR $ASN1_VERSION_PATCH`

for f in $IMPORTS; do
  src=$SRC/$f
  dst=$DST/$f
  if test "$f" = "libtasn1.h"; then
    src=$SRC/includes/$f.in
  fi
  if test -f $src; then
    if test -f $dst; then
      echo "Replacing $dst (existing file backed up in $dst~)"
      mv $dst $dst~
    else
      echo "Copying file $dst"
    fi
    cp $src $dst
    case $dst in
      */libtasn1.h)
	sed \
	  -e 's/@VERSION@/'${ASN1_VERSION}'/g' \
	  -e 's/@ASN1_VERSION_MAJOR@/'${ASN1_VERSION_MAJOR}'/g' \
	  -e 's/@ASN1_VERSION_MINOR@/'${ASN1_VERSION_MINOR}'/g' \
	  -e 's/@ASN1_VERSION_PATCH@/'${ASN1_VERSION_PATCH}'/g' \
	  -e 's/@ASN1_VERSION_NUMBER@/'${ASN1_VERSION_NUMBER}'/g' \
	  $dst > $dst-t && \
	mv $dst-t $dst
	;;
    esac
  else
    echo "Error: $src not found" 1>&2
    exit 1
  fi
done