shmam.awk revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
##########################################################
# MG: A UNIX Tool to generate new MAKEFILES from
# shell commands
# A. Kumar, ATT-BL, CB-2454, 3C-291
# THIS TOOL IS NOT SUPPORTED at this time
# Sept. 1, 1988
# However, please send any suggestions/bugs/enhancements
# to me (cblph!ajy) for future generics.
##########################################################
###############################################################
# AT&T BELL LABS - PROPRIETARY #
# Use pursuant to company Instructions #
# This source code is a proprietary information of #
# AT&T and it is not for use or disclosure #
# outside company except written agreement. #
###############################################################
BEGIN {
#YOU COULD ADD to these lists for command recognition
#do not give full path names, only the name of the command
CC_cmds="cc m32cc m15cc m32ld ld ceccc cecc m4"
AR_cmds="ar m32ar"
CP_cmds="cp mv ln"
CPMV_cmds="cpmv move"
CHMOD_cmds="chmod"
STRIP_cmds="strip m32strip"
MKLN_cmds="mkln 3b2mkln"
PAT_cmds="ppmkpat nepat pat"
{
dl="_"
}
else
{
}
#changing this debug level will print more stuff.
#this is for future debugging...
if (oOPT == 0)
{
MAXPERLINE=50
}
else
{
}
#change this variable to =1 for backslash output...
DSTYLE="ajy"
Style_new = 0
else if (sOPT == 1)
{
print "new style"
Style_new = 1
}
else
{
}
########################
else
{
}
#FUZZYMATCH=4
#how far in the line could an executable exist on $0
# for example
# + x cc will not be recoginized with FUZZYMATCH=2
# but
# x cc will be recoginixzed...
NULL=""
#used by var_i,val_i arrays.
iIN=0
iCMD=0;
CMD = 0
Vmake="M"
iMAKE = 0
#edge list for include files (i,j)
# where i and j are include directories.
iEDGES = 0
# used by lib directory lists
iaEDGES = 0
iINCDIR=0
iLIBDIR=0
iCMD=0 #noof commands in the install script.
CONINVAR="INSTDIR"
## if you have an initial list of vars, put in invar array.
#shell variables are input here,
XCMDNAME="CMD"
VXCMDNAME="VCMD"
iVAR++
#assert iVAR=1
val[1]=""
#lint files in LINTFILES
iVAR++
###test
}
END {
# build the variable list, typically install dirs INSTDIR1, ...and others
#builds Sdep lines for SOURCE.a..etc. and also variables.
# build COMMAND and LIBxxx and LIBxxxFILES variables
# var is only concerned with variables and not with any install dirs
# build the dependency lines, such as .ALL:, a:: rules etc
# print the above list
# print_invar MUST follow all bld's because all install directories not
# used are not printed by default
# build and print the SOURCE, .a lists
# print the above
# print the above dep lines
# also, as a sideeffect generate .CMD options
}
#chmod xxx tar tar tar ...
# j j+1 j+2
#strip tar tar tar ...
# j J+1
#mkln tar tar tar ...
# j j+1
{ #BEGIN OF MAIN PROGRAM
lmatch=0
#global variable cmdtype is set by get_cmds.
continue
#reaching here means command is recognized, get index
call_CC_cmds($0, NF, cmd, cmdtype, iindex)
lmatch=1
break
}
call_AR_cmds($0, NF, cmd, cmdtype, iindex)
lmatch=1
break
}
call_CP_cmds($0, NF, cmd, cmdtype, iindex)
lmatch=1
break
}
call_CH_cmds($0, NF, cmd, cmdtype, iindex)
lmatch=1
break
}
call_PAT_cmds($0, NF, cmd, cmdtype, iindex)
lmatch=1
break
}
else {
print "[internal error]" 1023394830498
}
}#end of for loop for checking args..
#print "ignored:\n" $0
ignore($0)
}
} #END OF MAIN PROGRAM
#returns the actual command matched
#cmd from *_cmds arrays defined earlier
#GLOBALS:also cmdtype is set
{
cmdtype="CC_cmds"
return(cmd)
}
cmdtype="CP_cmds"
return(cmd)
}
cmdtype="CPMV_cmds"
return(cmd)
}
cmdtype="AR_cmds"
return(cmd)
}
cmdtype="CH_cmds"
return(cmd)
}
cmdtype="CHMOD_cmds"
return(cmd)
}
cmdtype="STRIP_cmds"
return(cmd)
}
cmdtype="MKLN_cmds"
return(cmd)
}
cmdtype="PAT_cmds"
return(cmd)
}
cmd=""
cmdtype=""
}#end of function 1
#/chmod / || /strip / m32strip or mkln
{
}
opt=""
if ($(k) ~ /^\-.*/ )
else {
starti=k
break
}
}
}
tar = $(k)
#find if the target already exists?
#loop over targets :
#this is a change on that target...
#must have an installation ?
#src= src is the ???
#KLUDGE : $(<) or $(>) find it from target.
else
}
} else {
#now the object is neither in target list, nor in install list, so must
#be something not dependent on anything, need a ins[] line here?
} else {
print "no dependency why have it in this makefile"
ignore($0)
} #mkln chk.
} #the last else
} # for all targets
} #e_o_f:call_CH_cmds
{
if (j > 0) {
#this is a cc line with -o
tar=$(j+1)
if (tar ~ /^\.\/.*/ )
ignore($0)
next
}
else {
}
#convert all .o to .c
#also any .c's are put in the _cli list.
#side effects are to build .SOURCE.c,.o in future versions
dot_o2c($0)
#process any libraries
#side effects are to build .SOURCE.a (ok)
dot_as($0)
#process any header file dependency
#side effects are to build .SOURCE (ok)
dot_Is($0)
dflags($0)
print "(FLAG) rule"
#new dependency is here
}
} #end of -o processing
# usually -c option
dot_o2c($0)
dot_Is($0)
dflags($0)
#gsf# print ".o : rule"
#this is a cc line with -c
#may want to do a check if more .c on line
#gsf# print ".o " tar _Dli
}
}
#tar=
} else {
#gsf# print "what is =" $0
}
#new dependency is here
}
} #end of -c processing
}#e_o_f:CC_cmds
#if ($0 ~ /mv / || /cp / || /ln / || /move / || /cpmv / )
function call_CP_cmds(lin, nlin, cmd, cmdtype, iindex, i,j,k,arr,tmp,opt, kloop, command, src, dest, starti, ddest, dsrc, bdest, bsrc, opt, u)
{
command=cmd
j=iindex
src=$(j+1)
dest=$(j+2)
starti=j+2
}
src=$(j+1)
dest=$(j+5)
starti=j+5
}
opt=""
continue
}
#print bsrc "\ " dsrc
} else {
}
} else { #donot test any directories, assume fullpath name
}
}
kCMD++;
#check to see if bsrc is built here, and any precommands exist.
#such as a m32strip, chmod etc.
print "bsrc was modified"
#print "putting:" icmd[bsrc,u] " TO " k
}
}
#call subinvar simply to increment the count, to make sure these
# variables are used...
#print "insorder" kCMD " {}-"insorder[kCMD]
else {
}
} #for loop for each destination
} #e_o_f:CP_cmds
#/ar /
function call_AR_cmds(lin, nlin, cmd, cmdtype, iindex, i,j,k,arr,tmp,opt, kloop, command, src, dest, starti, ddest, dsrc, bdest, bsrc, opt, u,jj)
{
j=iindex
tar=$(j+2)
#print "Warning:multiple archive (ar) target: " tar
dot_o2c($0)
if (x > 0 ) {
}
}
} else {
#AR command processing, build the list
}
}#e_o_f:AR_cmds
{
find_in_out($0)
}
{
}
{
}
}
#print "s="s "ic="ic
}else;
#print "not used"
}
#print "s="s "ic="ic
}else ;
#print "not used"
}
}
#prints the SOURCE.h, .a lists
function bld_SOURCE()
{
#dont print SOURCE.h
#print "empty SOURCE.h"
#noop();
Sdeph=""
else {
# printf(".SOURCE.h:%s %s\n\n", v2(hdrlist), v2(resth["1"]))
}
#dont print SOURCE.h
#print "empty SOURCE.a"
#noop();
Sdepa=""
else
#printf(".SOURCE.a:%s %s\n\n", v2(hdrlist), v2(resta["1"]))
#dont print SOURCE.h
#print "empty SOURCE.a"
#noop();
Sdepo=""
else
#printf(".SOURCE.o:%s %s\n\n", v2(hdrlist), v2(resta["1"]))
#dont print SOURCE.h
#print "empty SOURCE.a"
#noop();
Sdepc=""
else
#printf(".SOURCE.c:%s %s\n\n", v2(hdrlist), v2(restc["1"]))
}
function print_SOURCE()
{
}
#print install directory variable names
function print_invar(vardir)
{
continue
}
continue
}
else
}
}
{
#instdir[dir(path] = VAR
#invar[VAR] = val
#generate a define, and assign it
#longest common substring, number of times used etc.
found=0
#print "1"
found=1
}
#print "2"
found=1
}
#print "3"
found=1
}
#print "v sub match" dir "->" subinvar(dir)
found=1
}
#either found or not found
iINVAR++
# instdir[dir] = compress(newvar)
} else
#instdir[dir] = vardir
} # for
}
#add a new invar[xx] = dir type variable ...
{
found=0
found=1
#either found or not found
iINVAR++
# instdir[dir] = newvar
} else
#instdir[dir] = vardir
}
#version 2.0 nmake install uses an explicit install: dependency rule
# print_install2( i,j, dir, found[A#version 2.0 nmake install uses an explicit install: dependency r
{
#first build install: dependency line
#next print each specific dependency line as a .CMD command
#may be in future combine all installdirectories as one variable.
#in ins, all extra commands.
#AJYBLANK printf("\n");
#print "sub: " dir " -> " nm
found=1
}
else
{
found=0
#KLUDGE (compress(invar[vardir]) == compress(dir))
{
myvardir=""
else
found = 1
break;
}
if (found ==1)
}
pmyvardir=""
else
else
#install_list=install_list " $("tayvardir")/"arr["4"]
#printf("\nINSTALLDIR=$(%s)\n", myvardir)
} else {
;
#print "WARNING: empty install: rule"
}
#print "LOGIC ERROR:call author immediately"
#printf("\nINSTALLDIR=%s\n", dir)
# now we have the install line
# now find the actual load line
else
}
else
printf("%s : %s", virtual_g(pmyvardir, arr["4"], arr["2"]), compress(subinvar(arr["1"]) "/" arr["2"]) ) ;
}
if (((itype == "install") && (Style_new != 1) ) || ((Style_new==1) && (virtual_ins[iorder] != 1) && (itype== "install" )) ) {
else
}
virtual_kkcmd[ic]=1
} else {
normal_kkcmd[ic]=1
}
}
#now the install line:
} else {
}
}
function print_install( i,j, dir, found, vardir, ic)
{
print "&*^%$#FATAL ERROR : nosuchfunction exists"
}
{
for (i=0; i<=iDEP; i++)
#gsf# if ((val[CMD] != "") && (COMD[ldep[i]] != 1))
#gsf# ALLlist = ALLlist " $(COMMANDS) "
#MAJOR KLUDGE::
}
#distinguish between :: and : rules
operator=":"
else
operator="::"
} else {
#use "backslash for formatting.
}
}
print "WARNING: following rule be defined:"
print " *.ln : *.c "
print " mkln $(>) "
}
}
}
#builds dep lines
#uses global lists
{
iDEP++
} else {
# a command from .c,.o
#i = ivar[tar]
iDEP++
#XAJY print tar "**" base "***" icmd[tar,1]
viDEP++
}
}
#XAJY for(i=0;i<=iDEP; i++) print i"="ldep[i]
#go thru all targets...if new style
##ins[dsrc, bsrc, ddest, bdest] = kCMD
#print "NEW STYLE:" iDEP
#print "LDEP=" ldep[jjj]
else
}#if match!
}#forloop
}#fo all install tars
}
}
function print_var(i)
{
continue
}
continue
}
}
}
#builds var list
#uses global lists...
{
#print tar "is lib"
#is a library!
else {
iVAR++
iVAR++
#ivar[tar] = iVAR
noprintvar[var[iVAR]]=""
}
; #donot put in commands line, nouse
} else {
#if command from .c,.osas usual
# var[CMD] = "CMDS" as defined
#substitute with subinvar, if tar has a dir?
else {
print "dir match by (sub)invar"
}
#iVAR++
#ivar[tar] = iVAR
#var[iVAR] = "CMD" tar "FILES"
#val[iVAR] = cdep[tar]
}
} #for
}
{
for(i=1; i<=n; i++) {
#print "bas=" bas " test=" t
return i
}
return -1
}
}
else {
}
}
# print "checking " iass
xmatch=1
xmatch=0
if (xmatch == 1 )
xmatch =0
#check if matched, or else go over next one
#print "match" ic i
return(i)
}
}
#if we reach here, means we found no match.
iCCMD++
return(iCCMD)
}
# print "checking " iass
xmatch=1
xmatch=0
if (xmatch == 1 )
xmatch =0
#check if matched, or else go over next one
#print "match" ic i
return(i)
}
}
#if we reach here, means we found no match.
iKCMD++
return(iKCMD)
}
function smatch(s, t, i)
{
for(i=1; i<=NF; i++)
if($i == t)
return i
return -1
}
function print_Is(i)
{
for (i=0; i<=iEDGES; i++)
}
{
prev=""
_Ili=""
for(k=1; k<=NF; k++)
bincl = $k
continue;
iINCDIR++
}
else {
iEDGES++
}
}
}
{
prev=""
_ali=""
basename($k)
dirname($k)
iLIBDIR++
}
else {
iaEDGES++
}
}
basename($k)
dirname($k)
iLIBDIR++
}
else {
iaEDGES++
}
}#if dlib is not= ""
}
} #for all members in the line
}
#_cli is a global variable.
{
#print $0
_cli=""
prev_o=""
prev_c=""
} #if
else {
iOBJDIR++
}
else {
ioEDGES++
}
}
} #if a .o
else {
iDOTCDIR++
}
else {
icEDGES++
}
}
}
} # for loop
}
#base is a global variable, need to learn how
{
}
{
}
#dir is a global;
{
dir=""
#print arr[i] "/"
}
return
if (b == "" )
else
path=""
}
{
return 1
else
return -1
}
function isI(s)
{
if (sub(/\-I/,"", s) == 1 ) {
return 1
} else {
return 0
}
}
function isa(s)
{
return 1
else
return -1
}
{
if (s ~ /^\-l/ )
return 1
else
return -1
}
function isc(s)
{
return 1
else
return -1
}
#top_sort
#globals: snode, enode, _SOURCEh
{
_SOURCEh=""
for (i in q)
delete q[i]
nodecnt = 0
a=snode[j]
pcnt[a] = 0
b=enode[j]
pcnt[b]++
}
back = 0
nodecnt++
#print "no back, pred:" back node
}
}
#print "n=" nodecnt
#printf(" %s", node = q[front])
#printf(" %s", node )
}
}
}
# a sample call : notonlist(hdrlist, dotcdir, iDOTCDIR, restc)
{
#arr["1"] ["2"],...["i"]
for (i=1; i<=nlist; i++)
continue;
else {
found=0
for (j=1; j<=n; j++)
found=1
#list[i] does not belong to arr/s
}
}
}
{
#next piece of code removes all multiple occurences of ///->to one /
#KLUDGE : use a for loop with a # of selections made counter
# now compare tmptar1 and tmptar
return(x)
}
}
return(-2)
}
#takes in a ccl, a list of defines,
# sideeffects add to a list of cc flags.
# shcc[] changed
{
print "CC flags(predefined outside makefile): "
for(i=1; i<=k; i++) {
} else
}
}
#determines if l has any -D type commands, and returns them
#in a global list _Dli
#other side effects is to generate a define var list.
# to be printed at the begining. we will use var[], val[] arrays.
{
_Dli=""
#assume $1, $2, ... etc. are valid arguments
if ($k ~ /^-D/ ) #yes a -D type var
{
def = $k
defval=$k
defval=""
defval=$k
#print "a define: " def ": " defval
#print "already in shcc"
#ok, do nothing
;
}
else {
#aha, this define should go into _Dli
# printed when those variables get printed
found=0
for(i=1;i<=iVAR; i++)
found=1
#print "in array"
iVAR++
}
}
} #if $k is ^-D
} #for loop over all items in l
#print "_Dli at return=", _Dli
}
function noop(){}
{
return(-1)
#print listy
for (j=1; j<=x; j++)
#print listy
return(1)
}
#print listy
return(-1)
}
iSHVAR++
sname = x
svalue = x
#print "< " sname " " svalue " >"
}
#this is the default for cc flags, call bld_shcc multiple times
# if you want more flags as defaulted outside makefile
print "NOPRINTVAR:these variables will not be printed"
print " in the Makefile(s) generated"
}
}
CC_SHVAR = "ENVCCF"
#print "ok"
}
else;
# note that this is used in determining what flags to set
# during the makefile generation since some flags on CC
# might be simply a property within that makefile.
NMAKE_SHVAR = "NMAKE_VER"
nmake_ver="1.4"
nmake_ver="2.0"
else {
print "1.4 or 2.0 in NMAKE_VER var"
}
} else {
; #print "using 2.0 nmake version"
}
#nmake_var is unused currently
}
function plogic(s)
{
}
#$0
function find_in_out(s, arr, n,i )
{
for(i=1;i<=n;i++) {
}
}
}
function tar_in_ins(tar, btar, dtar , i, jj)
{
#print btar " - " dtar
#print arr["3"] " - " arr["4"]
{
print "WARNING: CHECK Makefile.0 "
}
} #for
}
#ins[dsrc, bsrc, ddest, bdest] = kCMD
#rule for patterns
# syntax :
# <cmd> <options> <name> < <fname>
# cat <fname> | <cmd> <options> <name> - this is not implemented.
# .p : .pat .CMD.xx
{
opts=""
if ($k ~ /\-/) {
print "Warning: options on pattern could be ignored"
#options, use them
} else if ($k ~ /</ ) {
#break out of loop
break;
} else {
name=$k
break;
}
} #for loop
#print "name=" name " fname=" fname
#KLUDGE 1 is for patterns PATTERNS
#KLUDGE 0 is for COMMANDS variables.
var_cnt[1]++
kCMD++
# print "insorder" kCMD " {}-"insorder[kCMD]
}
{
#use if this is set
return 1
else
return 0
}
{
#KLUDGE AND INEFFICIENT!
for (i=0;i<=15; i++)
for (i=0;i<=15; i++)
}
}
function abs2relpath(path, i, j)
{
}
function vcommand(command, i, j, k)
{
for(i=1; i<=iVAR; i++)
var_cnt[i]++
return("$("var[i]")")
}
return(command);
}
return
return
}
iVAR++
sname = x
svalue = x
}
}
return
return
}
#iINVAR++
sname = x
svalue = x
### added for X=xxx:xx:yyy:zzz kind of assignments.
invar[sname]=tmpa #use first define...as default
} else
invar_more[sname]=1#this indicates if we need
iIN++;
}
}
} else {
iIN++
}
}
} else { #if a : separated define exists ...
invar_more[sname]=1
iIN++
}
} #regular define with no colons:...
}#while allinvars in invarfile...
}
#puts time stamp in the makefile generated.
function ts_makefile(d, x)
{
while (getline x <premakefile >0)
}
}
#returns a variable or NULL string depending on if it is
#defined.
{
e=""
#print "found a sub " val ":" nm
}
#print "v2n: " "val=" val"<" " pwd=" pwd " fv2n=" fv2n"<"
#print "e=" e
if (e == "" ) {
#try another variation
}
return e
} else
return NULL
}
#in:a list "/eald ../sdlfk /./..sdf" etc.
#out: a list with variables substitutes.
{
jlist=""
#print "vval=" vval
#vvar=v2n(vval);
else {
}
}
#this piece of code is extinct below:::
#check the INSTDIR list...
found=0
found=1
break;
}
}
if (found == 1)
else
}
}
{
if (xval ~/^\.\/.*/ )
#no doble slashes; KLUDGE
for (i=0;i<=5; i++)
#cannot remove this single slash! so return...
}
}
#substiture the s with invar[VAR]=VAL, using first match!!!
#bug removal1: ./ or "" matching prohibited...
{
match_val=""
match_var=""
continue
#cant match this noops.
continue
}
r=""
#print i "-" s "/" length(s) "-" yval "/"length(yval)
if ((r ~ /\/.*/) || (r == "") )
else {
continue
}
if (i== 1) {
#print yvar " val=" yval "len=" length(yval)
if ((r ~ /\/.*/) || (r == "") )
else {
continue
}
#print "r=" r
}
} #for match
r=""
continue
#cant match this noops.
continue
}
if (i== 1) {
#print yvar " val=" yval "len=" length(yval)
if ((r ~ /\/.*/) || (r == "") )
else {
continue
}
#print "r=" r
}
}#loop thru all var_i
#something matched!
return(match_val)
}
#else return same old string...
return(s1)
}
#return ("$(" yvar ")/" r);
#given a string s, determines any .SOURCE.* lines for
#modification...
function spath(s)
{
iDOTCDIR++
}
} else {
}
}
#converts a any file to a .ln file
{
#is a .c so get base name and convert...
tmp=s
} else {
return(s".ln")
}
}
{
thisline=0
maxline=1
#print maxline
{
#print thisline maxline Larr[Li]
thisline++
}else {
#here we have printed max on this line, start newline
thisline=1
}
}
#printf("\t\t%s\n\n",Larr[Li])
}
{
if (level > debug_level )
return
}
{
}
{
print "Virtual error:duplicate" a "--" b "--" c
} else {
usage[c]++
if (usage[c] == 1)
else
}
}
function print_dep_new()
{
}
#returns "" or some more dependencies...
{
}else {
return("");
}
#here there are more targets, ....
#following code from install dire...
}
{
return(s);
}