hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
#!/bin/bash
# Script to convert defines in compiler option in to C's defines
# Should be executed in make file and it take ccflags-y as the
# compiler options. The content will be redirected to the first arguement.
 
temp=$1_temp
 
echo "#ifndef __SSV_CONF_PARSER_H__" > $temp
echo "#define __SSV_CONF_PARSER_H__" >> $temp
 
echo "char const *conf_parser[] = {" >> $temp
 
for flag in ${ccflags-y}; do
   if [[ "$flag" =~ ^-D.* ]]; then
       def=${flag:2}
        if [[ "$def" =~ .= ]]; then
            def_1=${def/\=/_}
            echo "\"$def_1\"," >> $temp
        else
           echo "\"$def\"," >> $temp
        fi
   fi
done
 
echo "\"\"};" >> $temp
 
echo "#endif // __SSV_CONF_PARSER_H__" >> $temp
if [ -f $1 ];
then
   DIFF=$(diff $1 $temp)
   if [ "$DIFF" == "" ]; then
            rm $temp
   else
            mv $temp $1
   fi
else
   mv $temp $1
fi