I have a bunch of tcl scripts that I use for comma...
# magic
m
I have a bunch of tcl scripts that I use for command line use with magic, eg lvs. Is there a way to provide the name of the design via command line or environment variable?
eg I have this
box 0 0 0 0
load tt_um_magic_challenge.mag
extract do local
extract all
ext2spice lvs
ext2spice cthresh infinite
ext2spice short resistor
ext2spice -d -o tt_um_magic_challenge.lvs.spice
quit -noprompt
And I don't want the project names hardcoded in the tcl
can I have a $project in there and somehow supply the $project when I startup magic?
hmm, I can do it with env vars and then use $::env(env_var_name)
t
There are several ways to do this; one is that you can run magic from a script with
<< EOG
followed by all the commands written inside the shell script so that you can do shell variable substitution. The other way is mentioned in the usage web page for magic:
Copy code
(versions from 8.3.185) The behavior is the same as above, but if any TCL script is passed on the command line, then all arguments after the name of the TCL script are assumed to be arguments passed to the script and not input files to be processed by magic. The TCL script can see the whole command line argument list in the variable $argv (length $argc).
So you can just type, e.g.,
magic -dnull -noconsole myscript.tcl arg1 arg2 arg3
and then pick up those arguments from within the script using $argc and $argv as stated above.
๐Ÿ™Œ 1
m
thanks Tim
I did check the man page, but was just looking for the arguments listed at the top level
looks like netgen does the same, nice
trying to come up with some tcl that gets me arg1 in
magic -dnull -noconsole myscript.tcl arg1
I have to split $argv and grab the last arg
lindex $argv $argc-1
looks to work
t
Great; I much prefer that to using environment variables.
m
image.png
tried pasting the code but somethings wrong with slack's code block and the formatting was crazy
anyway, the above works nicely
๐Ÿ‘ 1
actually, netgen doesn't seem to support that
I can access argv, and even set a variable
but netgen errors out on the wrong number of args
t
Netgen and magic have the same interface (I made them the same way), so if netgen's isn't handling variables properly, it should be easy enough to track down and fix.
m
ok
I have my lvs.netgen.tcl script like this:
and call netgen like this: netgen -batch source tcl/lvs_netgen.tcl tt_um_magic_challenge
and it fails like this:
t
I have a meeting in 3 minutes but I'll try to track the issue down later.
m
thanks
this works inside netgen:
netgen -batch 'set project tt_um_magic_challenge; source tcl/lvs_netgen.tcl'
doesn't work from commandline
image.png
t
The issue is that "-batch" is followed by a command in netgen (which is a Tcl command), but there isn't a way to pass multiple commands. So "-batch source ..." can be used to execute multiple commands, except that Tcl doesn't allow arguments to be passed through the "source" command (seems like an oversight. . .). If you split into multiple Tcl commands, then you have to separate the commands with
;
, but the linux command line will grab it first and interpret it as a linux command separator. Anything you do to get rid of the delimiter like putting the command in quotes causes the command not to be seen as a command. But this works: File "test.tcl":
Copy code
# Tcl file
puts stdout $myvar
puts stdout "that's all, folks!"
exit
Then do:
Copy code
netgen -batch eval "set myvar hello ; source test.tcl"
So what I did was to put it in quotes to protect it from the shell, and then the command passed to netgen is now "eval", which evaluates the following string argument as a command.
m
ah, nice.
a
Hi @Matt Venn. I've solved the original problem using makefiles, and using the
define ... endef
construct. I hope you find it useful. https://github.com/akiles-esta-usado/ic-makefile/blob/main/magic.mk Are your scripts available to see? It could be great to find more use-cases for my project.
m
hey, looks good, thanks