summaryrefslogtreecommitdiff
path: root/contrib/addsourcedir
blob: ef6aedd156f70da3228554fc1c262f4f1b63c623 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
#
# addsourcedir
# Morgan Deters <mdeters@cs.nyu.edu> for the CVC4 project
# Copyright (c) 2010  The CVC4 Project
#
# usage: addsourcedir paths...
#

progname=`basename "$0"`
cd `dirname "$0"`/..

if [ $# -lt 1 ]; then
  echo >&2
  echo "usage: $progname paths..." >&2
  echo >&2
  echo "Each path should be relative to the top-level source directory, e.g.:" >&2
  echo >&2
  echo "  $progname src/expr" >&2
  echo >&2
  exit 1
fi

while [ $# -gt 0 ]; do
  srcdir="$1"; shift

  # remove trailing slashes, if any
  srcdir=`expr "$srcdir" : '\(.*[^/]\)/*$'`
  # remove redundant slashes, if any
  srcdir=`echo "$srcdir" | sed 's,//*,/,g'`

  if expr "$srcdir" : src/ >/dev/null; then :; else
    echo "$progname: error: Directories must be under src/" >&2
    echo "$progname: error: and \`$srcdir' isn't!" >&2
    echo "$progname: error: Make sure you provide source paths" >&2
    echo "$progname: error: relative to the top level, e.g. \`src/expr'." >&2
    exit 1
  fi

  if [ -d "$srcdir" ]; then :; else
    echo "creating directory \`$srcdir'..."
    mkdir -p "$srcdir"
  fi

  # enough dotdots to get us back to the top-level directory
  # (e.g. "src/foo" yields "../.." here), used for $(topdir) in Makefile
  topdir=`echo "$srcdir" | sed 's,[^/]\+,..,g'`
  # one less, used for the include path in Makefile.am
  topsrcdir=`echo "$topdir" | sed 's,\.\./,,'`

  if [ -e "$srcdir/Makefile" ]; then
    echo "$progname: warning: not replacing extant \`$srcdir/Makefile'." >&2
  else
    echo "generating \`$srcdir/Makefile'..."
    cat >"$srcdir/Makefile" <<EOF
topdir = $topdir
srcdir = $srcdir

include \$(topdir)/Makefile.subdir
EOF
  fi

  if [ -e "$srcdir/Makefile.am" ]; then
    echo "$progname: warning: not replacing extant \`$srcdir/Makefile.am'." >&2
  else
    echo "generating \`$srcdir/Makefile.am'..."
    clibbase=`expr "$srcdir" : '.*/\([^/]\+\)$'`
    if expr "$srcdir" : src/parser >/dev/null; then
      definitions="	-D__BUILDING_CVC4PARSERLIB \\
"
      visibility=' $(FLAG_VISIBILITY_HIDDEN)'
    elif expr "$srcdir" : src/main >/dev/null; then
      definitions=
      visibility=
    else
      definitions="	-D__BUILDING_CVC4LIB \\
"
      visibility=' $(FLAG_VISIBILITY_HIDDEN)'
    fi
    clibname="lib${clibbase}.la"
    clibtarget="lib${clibbase}_la"
    cat >"$srcdir/Makefile.am" <<EOF
AM_CPPFLAGS = \\
$definitions	-I@srcdir@/$topsrcdir/include -I@srcdir@/$topsrcdir -I@builddir@/$topsrcdir
AM_CXXFLAGS = -Wall$visibility

noinst_LTLIBRARIES = $clibname

${clibtarget}_SOURCES = \\
	SOURCEFILE.cpp
EOF
  fi
done

generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback