aboutsummaryrefslogtreecommitdiff
path: root/src/makesource.sh
blob: 0de872f6084d6d2789278a8b3981e6d09a9f071f (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
#!/bin/sh

ZEXY_H=z_zexy.h
ZEXY_C=z_zexy.c
ZEXY_S=Make.source


GREP=grep
AWK=awk
SED=sed

#################################
## functions

function head_h() {
 echo "/* zexy-setup autogenerated header-file"
 echo " * generated by \"$0\""
 echo " * !! DO NOT MANUALLY EDIT  !!"
 echo " */"
 echo
 echo "#ifndef Z_ZEXY_H__"
 echo "#define Z_ZEXY_H__"
}

function foot_h() {
 echo "#endif /* Z_ZEXY_H__ */"
 echo ""
}

function head_c() {
 echo "/* zexy-setup autogenerated setup-file"
 echo " * generated by \"$0\""
 echo " * !! DO NOT MANUALLY EDIT  !!"
 echo " */"
 echo 
 echo "#include \"$ZEXY_H\""
 echo
 echo "void z_zexy_setup(void)"
 echo "{"
}

function foot_c() {
 echo "}"
 echo
}

function head_s() {
  echo "SOURCES = \\"
}

function foot_s() {
  echo "	zexy.c"
  echo
}

function get_setupfunctions() {
  if [ -e "$1" ]
  then
    $GREP "^void .*_setup(void)" $i | $AWK '{print gensub("_setup.*", "_setup", "g", $2);}'
  fi
}

##################################
## body

head_h > $ZEXY_H
head_c > $ZEXY_C
head_s > $ZEXY_S

for i in `ls *.c | grep -v zexy.c`
do
  NAME="${i%.c}"
  SETUPNAMES=`get_setupfunctions $i`
  if [ "$SETUPNAMES" ]
  then
    echo "	$i \\" >> $ZEXY_S
    for SETUPNAME in $SETUPNAMES
    do
      echo "void ${SETUPNAME}(void);" >> $ZEXY_H
      echo "	${SETUPNAME}();" >> $ZEXY_C
    done
  fi
done

foot_h >> $ZEXY_H
foot_c >> $ZEXY_C
foot_s >> $ZEXY_S