* small addition for new SMARTTIME24 token.
[alpine.git] / contrib / utils / txtcc.sh
blob0d1bb8c9f1d0d51b2074ab63e668a9d9feb2f799
1 #!/bin/sh
3 # On ultrix, this will compile string constants into the text segment
4 # where they can be shared. Use to build pine by saying:
6 # build CC=txtcc gul
8 # As of Pine4.03, this moves about 675k per process into sharable memory
10 # Corey Satten, corey@cac.washington.edu, 9/11/98
12 TMP1=/tmp/cc$$.s
13 TMP2=/tmp/cc$$.delayed
14 trap "rm -f $TMP1 $TMP2" 0 1 2 13 15
17 for i in "$@"; do
18 case "$oflag//$i" in
19 //-c) cflag=1;;
20 //-o) oflag=1;;
21 //-g) gflag=1;;
22 1//*) ofile="$i"; oflag=;;
23 //*.c) cfile="$i"; : ${ofile=`basename $i .c`.o};;
24 esac
25 done
27 case "$cflag" in
28 1) sfile=`basename $ofile .o`.s
29 gcc -S "$@"
31 # Postprocess assembly language to move strings to .text segment.
33 # Use sed to collect .ascii statements and their preceding label
34 # and .align and emit those to $TMP2, the rest to $TMP1.
36 # Start in state0
37 # In state0: if .align is seen -> state1; else print, -> state0
38 # In state1: if a label is seen -> state2; else -> punt
39 # In state2: if .ascii is seen -> state3; else -> punt
40 # In state3: if .ascii is seen -> state4; else write TMP2, -> state0
41 # In state4: append to buffer, -> state3
42 # In state punt: print unprinted lines, -> state0
44 sed '
45 : state0
46 /^[ ][ ]*\.align/ b state1
49 : state1
51 N; s/^[^\n]*\n//; H
52 /^[!-~]*:/ b state2
53 b punt
55 : state2
56 N; s/^[^\n]*\n//; H
57 /^[ ][ ]*\.ascii/ b state3
58 b punt
60 : state3
61 N; s/^[^\n]*\n//
62 /^[ ][ ]*\.ascii/ b state4
64 w '"$TMP2"'
66 b state0
68 : state4
70 b state3
72 : punt
74 ' $sfile > $TMP1
76 # now add the deferred .ascii statements to .text segment in $TMP1
77 echo ' .text' >> $TMP1
78 cat $TMP2 >> $TMP1
80 rm `basename $ofile .o`.s
81 gcc ${gflag+"-g"} -c -o $ofile $TMP1
83 *) gcc "$@"
85 esac