Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/mam/mamold.sh
1808 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1989-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# Glenn Fowler <[email protected]> #
18
# #
19
########################################################################
20
: convert mam to old make makefile
21
22
function convert
23
{
24
typeset buf=$*; typeset -i i
25
set -s -A variable ${variable[@]}
26
for (( i = ${#variable[@]} - 1; i >= 0; i-- ))
27
do buf=${buf//\$${variable[i]}/\$(${variable[i]})}; done
28
print -r -- "$buf"
29
}
30
function closure
31
{
32
typeset i j
33
for i
34
do [[ " $list " == *" $i "* ]] && continue
35
list="$list $i"
36
for j in ${implicit[$i]}
37
do closure $j; done
38
done
39
}
40
41
typeset -A prereqs implicit action
42
typeset -i level=0 nvariables=0
43
typeset rule list order target variable
44
45
print "# # oldmake makefile generated by $0 # #"
46
while read -r op arg val extra junk
47
do case $op in
48
[0-9]*) op=$arg
49
arg=$val
50
val=$extra
51
;;
52
esac
53
case $op in
54
setv) variable[nvariables++]=$arg
55
convert "$arg = $val"
56
;;
57
make|prev) rule=${target[level]}
58
[[ " $val " == *" implicit "* ]] &&
59
implicit[$rule]="${implicit[$rule]} $arg" ||
60
prereqs[$rule]="${prereqs[$rule]} $arg"
61
[[ $op == prev ]] && continue
62
target[++level]=$arg
63
[[ " $order " != *" $arg "* ]] && order="$order $arg"
64
;;
65
exec) [[ $arg == - ]] && arg=${target[level]}
66
[[ ${action[$arg]} ]] &&
67
action[$arg]=${action[$arg]}$'\n'$'\t'$val ||
68
action[$arg]=$'\t'$val
69
;;
70
done) level=level-1
71
;;
72
esac
73
done
74
for rule in $order
75
do [[ ! ${prereqs[$rule]} && ! ${action[$rule]} ]] && continue
76
list=
77
closure ${prereqs[$rule]} && print && convert "$rule :$list"
78
[[ ${action[$rule]} ]] && convert "${action[$rule]}"
79
done
80
81