File: check_define.sh

package info (click to toggle)
cppad 2026.00.00.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,584 kB
  • sloc: cpp: 112,960; sh: 6,146; ansic: 179; python: 71; sed: 12; makefile: 10
file content (76 lines) | stat: -rwxr-xr-x 2,410 bytes parent folder | download | duplicates (2)
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
#! /bin/bash -e
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
# SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
# SPDX-FileContributor: 2003-22 Bradley M. Bell
# ----------------------------------------------------------------------------
if [ $0 != 'bin/check_define.sh' ]
then
   echo 'bin/check_define.sh: must be executed from its parent directory'
   exit 1
fi
# -----------------------------------------------------------------------------
echo 'Check '# define' versus '# undef' names and check for addon names'
echo '-----------------------------------------------------------------------'
file_list=`git ls-files '*.hpp' '*.in' |
   sed -n -e '/^include\/cppad\//p'`
add_on_list='CG PY TMB MIXED'
#
# preprocessor symbols in user API
sed -n -e "/^# *undef /p" xrst/preprocessor.xrst | sed \
   -e "s/^# *undef  *\([A-Za-z0-9_]*\).*/\1/" > check_define.2
#
for file in $file_list
do
      include_guard=`echo $file | sed \
         -e 's|^include/||' \
         -e 's|\.in||' \
         -e 's|/|_|g' \
         -e 's|\.hpp|_hpp|' \
         | tr [a-z] [A-Z]
      `
      # define
      if [ ! -e $file.in ]
      then
         sed -n -e "/^# *define /p" $file | sed \
            -e "/^# *define *$include_guard/d" \
            -e '/^# define NOMINMAX/d' \
            -e "s/^# *define  *\([A-Za-z0-9_]*\).*/\1/" >> check_define.1
      fi
      # undef
      if [ ! -e $file.in ]
      then
         # note <cppad/local/utility/cppad_vector_itr.hpp> is special
         sed -n -e "/^# *undef /p" $file | sed \
            -e '/CPPAD_LOCAL_UTILITY_CPPAD_VECTOR_ITR_HPP/d' \
            -e "s/^# *undef  *\([A-Za-z0-9_]*\).*/\1/" >> check_define.2
      fi
      # add_on
      for add_on in $add_on_list
      do
         if grep "CPPAD_${add_on}_" $file
         then
            add_on_error='true'
         fi
      done
done
# sort lists
for file in check_define.1 check_define.2
do
   sort -u $file > check_define.3
   mv check_define.3 $file
done
if ! diff check_define.1 check_define.2
then
   echo 'check_define.sh: Error: defines and undefs do not match'
   rm check_define.1 check_define.2
   exit 1
fi
rm check_define.1 check_define.2
echo '-----------------------------------------------------------------------'
if [ "$add_on_error" == 'true' ]
then
   echo 'check_define.sh: Error: add_on preprocessor symbol found'
   exit 1
fi
echo 'check_define.sh: OK'
exit 0