summaryrefslogtreecommitdiffstats
path: root/doc/initbuildboot.sh
blob: ea8dc12a242336fa3730159fa2ef08da63e5c612 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
VER="R0.06"

BBTEMPLATE=
BBXML=

USAGE="`basename $0` -xml buildbootxml-to-create  -template templatexml-file ($VER)
    Currently only supports sequence types Build-command: and Boot-command:
    Both files should have path book-*release-info/doc/
    Creates the XML file from the template, inserting build/boot commands
    from the various s_targets/XXXtargetXXX/README files
    at the place in template with >SCRIPT_INCLUDES_BUILD_BOOT_SECTIONS_HERE<
    ignoring rest of template
    The code tries to fold too long lines, but this is not perfect. Best would
    be if the command lines already in README are short enough, e.g. by
    using short variables, which work both on shell and uboot command lines"

while echo "x$1" | egrep '^x-' >/dev/null 2>&1
do
  OPT="$1" ; shift
  if [ "$OPT" = "--help" -o "$OPT" = "-h" -o "$OPT" = "-help" ] ; then echo "$USAGE" ; exit ; fi
  if [ "$OPT" = "-xml" ] ; then BBXML="$1" ; shift; fi
  if [ "$OPT" = "-template" ] ; then BBTEMPLATE="$1" ; shift; fi
done
if [ "$BBTEMPLATE" = "" ]; then echo "ERROR: Missing option -template templatefile"; exit ; fi
if [ "$BBXML" = ""      ]; then echo "ERROR: Missing option -xml buildbootxml-to-create"; exit ; fi
if [ ! -f "$BBTEMPLATE" ]; then echo "ERROR: Missing templatefile '$BBTEMPLATE'"; exit; fi
if [ ! -d "`dirname \"$BBXML\"`" ]; then echo "ERROR: Missing parent directory for '$BBXML'"; exit ; fi

echo "`basename $0` Creating $BBXML from"
TARGETREADMES=`cd s_targets ; ls -d */README | tr '\n' ' '`
echo "     $TARGETREADMES"

# README file formats:
# a) Sequence starts: ___ XXXX:yyyy or ___ XXXX:yyyy conffile
#    where XXXX is a type, yyyy is text to be in title
# b) Inside sequence: ___ END ends the sequence  (ignore rest of line)
# c) Inside sequence: # Documentation line
# d) Inside sequence: Anything else is command or config lines
#    Conv.to XML: ">" "<" "&" and put all inside <programlisting>
# *) Anywhere ____xxxx Leading 4 underlines or more, always ignored
#    unless one of the recognized XXXX
# *) Anywhere outside sequence, ignore all
# *) There can be multiple of each type of sequence in each README file
#    with different yyyy


cat $BBTEMPLATE | awk '
   />SCRIPT_INCLUDES_BUILD_BOOT_SECTIONS_HERE</ {exit 0; }
   { print $0; }
' >$BBXML


# Long command lines: The awk code below breaks too long lines, but this is not perfect.
extractcmds_filter() {
   echo "        <programlisting>" | tr -d '\n'
   sed '/^___/d;s/\&/\&amp;/g' | sed 's/</\&lt;/g;s/>/\&gt;/g;/^$/d' | \
    awk 'BEGIN               { MAX=90; }
         ( length($0) > MAX ) {
            LINE=$0;
            while (length(LINE) > MAX) {
              if (index(LINE," ") == 0 ) {
                print "ERROR: PROBLEM: No space in too long line:" LINE  > "/dev/stderr";
                print $LINE;
                next;
              }
              i=MAX; while ( substr(LINE,i,1) != " " ) { i=i-1; if (i==0) {break;} }
              print substr(LINE,0,i) "\\";
              REST=substr(LINE,i+1);
              if ( length(REST) == 0 ) { next ; }
              LINE="           " REST;
            }
            if ( length(LINE) > 0 ) { print LINE; next ; }
         }
         { print;}'
   echo "</programlisting>"
}

extractcmds_for_type() { # target/README BOOTorBUILD
  README=s_targets/"$1"
  CMDTYPE="$2"
  COMMANDSFOR=`egrep "___$CMDTYPE:" $README`
  for CMDS in $COMMANDSFOR
  do
     cmdsfor=`echo "$CMDS" | sed 's/[^:]*://'`
#--      echo "         <para>$CMDTYPE for $cmdsfor</para>"
     cat "$README" | sed -n "/$COMMANDSFOR/,/___END/p" | extractcmds_filter
  done
}

for targetreadme in $TARGETREADMES
do
   TARGET=`dirname $targetreadme`
   echo "" >>$BBXML
   echo "  <section id=\"target_$TARGET\">" >>$BBXML
   echo "    <title>Target $TARGET</title>" >>$BBXML
   echo "     <remark>NOTE: DO NOT EDIT THIS GENERATED FILE! Only edit the template file.</remark>" >>$BBXML
   echo "    <section>" >>$BBXML
   echo "        <title>Build Instructions for $TARGET</title>" >>$BBXML
   extractcmds_for_type $targetreadme Build-command >>$BBXML
   echo "    </section>" >>$BBXML
   echo "" >>$BBXML
   echo "    <section>" >>$BBXML
   echo "       <title>Boot Instructions for $TARGET</title>" >>$BBXML
   extractcmds_for_type $targetreadme Boot-command >>$BBXML
   echo "    </section>" >>$BBXML
   echo "  </section>" >>$BBXML
done

echo "</chapter>" >>$BBXML
echo "Ready created $BBXML"