1#!/bin/tcsh -f
2#
3#------------------------------------------------------------------
4# qflow.sh --- main program shell script
5#------------------------------------------------------------------
6
7# The version of qflow is determined at compile/install time
8set qflowversion=QFLOW_VERSION.QFLOW_REVISION
9
10# Environment variable overrides the tech type in all cases except
11# when the technology is specified on the command line by -T.  If
12# the environment variable is not set, the technology defaults to
13# the technology that is issued with the qflow distribution.
14
15set tech=`printenv QFLOW_TECH`
16set techdir=""
17set has_tech=0
18if ( $tech == "" ) then
19   # But. . . check if there is already a "qflow_vars.sh".  If so,
20   # parse it for "techname", and use that preferentially over the
21   # default technology.
22   if ( -f qflow_vars.sh ) then
23      set tech=`cat qflow_vars.sh | grep techname | cut -d= -f2`
24      set techdir=`cat qflow_vars.sh | grep techdir | cut -d= -f2`
25      set has_tech=1
26   else
27      set tech=osu035
28      set has_tech=-1
29   endif
30endif
31
32# Environment variable overrides the project root path in all cases
33# except when the project root path is specified on the command line
34# by -p.  If the environment variable does not exist, the project
35# root directory is assumed to be the current working directory.
36
37set projectpath=`printenv QFLOW_PROJECT_ROOT`
38if ( $projectpath == "" ) then
39   set projectpath=`pwd`
40endif
41
42set modulename=""
43set vsource=""
44
45# Don't do anything unless told to on the command line
46set actions=0
47set dogui=0
48set dohelp=0
49set doversion=0
50set dosynth=0
51set doplace=0
52set dosta=0
53set doroute=0
54set dobackanno=0
55set domigrate=0
56set dolvs=0
57set dodrc=0
58set dogdsii=0
59set doclean=0
60set dopurge=0
61set dodisplay=0
62
63while ($#argv > 0)
64   switch($argv[1]:q)
65      case -t:
66      case -T:
67      case --tech:
68	 shift
69	 set tech=$argv[1]
70	 set has_tech=0
71	 shift
72	 breaksw
73      case -p:
74      case -P:
75      case --project:
76	 shift
77	 set project=$argv[1]
78	 shift
79	 breaksw
80      case -h:
81      case -H:
82      case --help:
83	 set dohelp=1
84	 shift
85	 breaksw
86      case -v:
87      case -V:
88      case --version:
89	 set doversion=1
90	 shift
91	 breaksw
92      case gui:
93         set dogui=1
94         shift
95         breaksw
96      case synth:
97      case synthesize:
98	 set dosynth=1
99	 set actions=1
100	 shift
101	 breaksw
102      case place:
103      case placement:
104	 set doplace=1
105	 set actions=1
106	 shift
107	 breaksw
108      case sta:
109      case timing:
110      case statictiming:
111	 set dosta=1
112	 set actions=1
113	 shift
114	 breaksw
115      case route:
116      case routing:
117	 set doroute=1
118	 set actions=1
119	 shift
120	 breaksw
121      case backanno:
122      case backannotate:
123	 set dobackanno=1
124	 set actions=1
125	 shift
126	 breaksw
127      case migrate:
128      case migration:
129	 set domigrate=1
130	 set actions=1
131	 shift
132	 breaksw
133      case lvs:
134	 set dolvs=1
135	 set actions=1
136	 shift
137	 breaksw
138      case drc:
139	 set dodrc=1
140	 set actions=1
141	 shift
142	 breaksw
143      case gdsii:
144      case gds:
145	 set dogdsii=1
146	 set actions=1
147	 shift
148	 breaksw
149      case build:
150	 set dosynth=1
151	 set doplace=1
152	 set doroute=1
153	 set dobackanno=1
154	 set actions=1
155	 shift
156	 breaksw
157      case nocheck:
158      case nochecks:
159	 set dosynth=1
160	 set doplace=1
161	 set dosta=1
162	 set doroute=1
163	 set dobackanno=1
164	 set doclean=1
165	 set dodisplay=1
166	 set actions=1
167	 shift
168	 breaksw
169      case all:
170	 set dosynth=1
171	 set doplace=1
172	 set dosta=1
173	 set doroute=1
174	 set dobackanno=1
175	 set domigrate=1
176	 set dolvs=1
177	 set dodrc=1
178	 set dogdsii=1
179	 set doclean=1
180	 set dodisplay=1
181	 set actions=1
182	 shift
183	 breaksw
184      case clean:
185      case cleanup:
186	 set doclean=1
187	 set actions=1
188	 shift
189	 breaksw
190      case purge:
191	 set dopurge=1
192	 set actions=1
193	 shift
194	 breaksw
195      case display:
196	 set dodisplay=1
197	 set actions=1
198	 shift
199	 breaksw
200      case buffer:
201	 echo "Note:  option buffer is deprecated."
202	 shift
203	 breaksw
204      default:
205	 if (`echo $argv[1] | cut -c1` == "-") then
206	    echo "Unknown option $argv[1]"
207	    set dohelp=1
208	    break
209	 else if ($modulename == "") then
210	    set modulename=$argv[1]
211	    shift
212	 else
213	    echo "Argument $argv[1] after module name $modulename"
214	    set dohelp=1
215	    break
216	 endif
217	 breaksw
218   endsw
219end
220
221if ($dogui == 1) then
222    # Run interactive GUI interface instead of this script.
223    if ( -f QFLOW_SCRIPT_DIR/qflow_manager.py ) then
224        if ( $has_tech == 0 ) then
225	    exec QFLOW_SCRIPT_DIR/qflow_manager.py $tech $modulename
226	else
227	    exec QFLOW_SCRIPT_DIR/qflow_manager.py None $modulename
228        endif
229	# exec should not return. . .
230	exit 0
231    else
232	echo "GUI manager not installed.  Requires python3"
233	set dohelp = 1
234    endif
235endif
236
237if ($modulename == "") then
238   set dohelp=1
239endif
240
241if ($doversion == 1 || $dohelp == 1) then
242   echo "Qflow version QFLOW_VERSION revision QFLOW_REVISION"
243   echo ""
244
245   if ($doversion == 1) then
246      exit 0
247   endif
248endif
249
250if ($dohelp == 1 || $#argv != 0) then
251   echo "Usage: qflow [processes] [options] <module_name>"
252   echo "Processes:  synthesize		Synthesize verilog source"
253   echo "            place		Run initial placement"
254   echo "            sta			Static timing analysis"
255   echo "            route		Run placement and route"
256   echo "            backanno		Post-route timing analysis"
257   echo "            migrate		Generate database and netlists for DRC and LVS"
258   echo "            drc			Run DRC check"
259   echo "            lvs			Run LVS comparison"
260   echo "            gdsii		Generate GDSII output"
261   echo "            clean		Remove temporary working files"
262   echo ""
263   echo "            display		Display routed result"
264   echo ""
265   echo "            build		Run scripts synthesize to backanno"
266   echo "            nochecks		Run scripts synthesize to backanno and display"
267   echo "            all			Run scripts synthesize to gdsii and display"
268   echo ""
269   echo "            gui			Run the qflow interactive GUI"
270   echo ""
271   echo "Options:    -T, --tech <name>		Use technology <name>"
272   echo "            -p, --project <name>	Project root directory is <name>"
273   echo "            -v, --version		Print qflow version and revision"
274   if ($dohelp == 1) then
275      exit 0
276   else
277      exit 1
278   endif
279endif
280
281echo ""
282echo "--------------------------------"
283echo "Qflow project setup"
284echo "--------------------------------"
285echo ""
286
287if ($has_tech == 1) then
288   echo "Technology set to $tech from existing qflow_vars.sh file"
289else if ($has_tech == -1) then
290   echo "No technology specified or found;  using default technology $tech"
291else
292   echo "Technology set to $tech"
293endif
294
295source QFLOW_SCRIPT_DIR/checkdirs.sh ${tech} ${techdir} ${projectpath}
296if ($status == 1) then
297   echo "Failure to verify working directories."
298   echo "Check QFLOW_PROJECT_ROOT environment variable."
299   exit 1
300endif
301
302# Use find, not ls, to avoid error output when no match is found.
303set nvsrc = `find ${sourcedir} -name \*.v -print | grep -v _mapped.v | wc -l`
304set nsvsrc = `find ${sourcedir} -name \*.sv -print | wc -l`
305
306# Verilog file root name is the same as the module name, at least until
307# discovered otherwise.  If the module name is not given on the command
308# line, then there must be one source file and the filename root and
309# module name must match.
310
311if ($modulename == "") then
312   if ($nvsrc == 1) then
313      set vsource=`ls ${sourcedir}/*.v | grep -v _mapped.v`
314      set modulename=${vsource:r}
315   else if ($nsvsrc == 1) then
316      set vsource=`ls ${sourcedir}/*.sv`
317      set modulename=${vsource:r}
318   else if ($nvsrc == 0 && $nsvsrc == 0) then
319      echo "Error:  No verilog source files found in directory ${sourcedir}."
320      exit 1
321   else
322      echo "Error:  No verilog source file or module name has been specified"
323      echo "and directory ${sourcedir} contains multiple verilog files."
324      echo "Please specify the source file or module name on the command line."
325      exit 1
326   endif
327endif
328
329if ($vsource == "") then
330   # First look for a file list (extension ".fl") that specifies exactly
331   # which modules to use;  this overrides the automatic search for
332   # modules.
333   if ( -f "${sourcedir}/${modulename}.fl" ) then
334      set source_file_list = "${sourcedir}/${modulename}.fl"
335   endif
336
337   # If there is no file list, then search for modules with this name.
338   if ( ! ($?source_file_list) ) then
339      # Check all .v and .sv files for one with the specified module.
340      foreach file ( `ls ${sourcedir}/*.v ${sourcedir}/*.sv | grep -v _mapped.v` )
341         set mline = `cat $file | grep module | grep ${modulename} | wc -l`
342         if ( $mline > 0 ) then
343	    set vsource = ${file}
344	    break
345         endif
346      end
347
348      if ( ${vsource} == "" ) then
349         echo "Error:  No verilog file in ${sourcedir} contains module ${modulename}."
350         exit 1
351      endif
352   endif
353endif
354
355# Replace home path in vsource with tilde escape if needed
356if ( ${vsource} != "" ) then
357   set vsource="`echo $vsource | sed -e 's,^${HOME},~,'`"
358endif
359
360#------------------------------------------------------------------
361# Source the technology initialization script
362#------------------------------------------------------------------
363
364if ( -f ${techdir}/${tech}.sh ) then
365   source $techdir/${tech}.sh
366else
367   echo "Error:  Cannot find tech init script ${techdir}/${tech}.sh to source"
368   exit 1
369endif
370
371#------------------------------------------------------------------
372# Prepare the script file to run in the project directory.  We
373# specify all steps of the process and comment out those that
374# have not been selected.  Finally, source the script.
375#------------------------------------------------------------------
376
377set varfile="${projectpath}"/qflow_vars.sh
378set execfile="${projectpath}"/qflow_exec.sh
379set userfile="${projectpath}"/project_vars.sh
380
381#------------------------------------------------------------------
382# Check if a variables file exists.  If so, note that we are
383# regenerating the flow, source the file, check if the technology
384# is being changed, and report if so.
385#------------------------------------------------------------------
386
387set newtech = 0
388if ( -f $varfile ) then
389   set techorig=`cat $varfile | grep techname= | cut -d= -f2`
390   if ( "${tech}" != "${techorig}" ) then
391      echo "Warning:  Project technology changed from ${techorig} to ${tech}"
392      set newtech = 1
393   else
394      echo "Regenerating files for existing project ${modulename}"
395   endif
396endif
397
398echo "#\!/bin/tcsh -f" > ${varfile}
399echo "#-------------------------------------------" >> ${varfile}
400echo "# qflow variables for project ${projectpath}" >> ${varfile}
401echo "#-------------------------------------------" >> ${varfile}
402echo "" >> ${varfile}
403
404echo "set qflowversion=${qflowversion}" >> ${varfile}
405echo "set projectpath=${projectpath}" >> ${varfile}
406echo "set techdir=${techdir}" >> ${varfile}
407echo "set sourcedir=${sourcedir}" >> ${varfile}
408echo "set synthdir=${synthdir}" >> ${varfile}
409echo "set layoutdir=${layoutdir}" >> ${varfile}
410echo "set techname=${techname}" >> ${varfile}
411echo "set scriptdir=${scriptdir}" >> ${varfile}
412echo "set bindir=${bindir}" >> ${varfile}
413echo "set logdir=${projectpath}/log" >> ${varfile}
414echo "#-------------------------------------------" >> ${varfile}
415echo "" >> ${varfile}
416
417echo "#\!/bin/tcsh -f" > ${execfile}
418echo "#-------------------------------------------" >> ${execfile}
419echo "# qflow exec script for project ${projectpath}" >> ${execfile}
420echo "#-------------------------------------------" >> ${execfile}
421echo "" >> ${execfile}
422
423#---------------------------------------------------------
424# Make sure that the flow tools are defined with defaults
425#---------------------------------------------------------
426
427if ( ! (${?synthesis_tool}) ) then
428   if ( HAVE_YOSYS ) then
429      set synthesis_tool=yosys
430   endif
431endif
432
433if ( ! (${?placement_tool}) ) then
434   if ( HAVE_GRAYWOLF ) then
435      set placement_tool=graywolf
436   else if ( HAVE_REPLACE ) then
437      set placement_tool=replace
438   endif
439endif
440
441if ( ! (${?sta_tool}) ) then
442   set sta_tool=vesta
443endif
444
445if ( ! (${?router_tool}) ) then
446   if ( HAVE_QROUTER ) then
447      set router_tool=qrouter
448   endif
449endif
450
451if ( ! (${?migrate_tool}) ) then
452   if ( HAVE_MAGIC ) then
453      set migrate_tool=magic_db
454   endif
455endif
456
457if ( ! (${?lvs_tool}) ) then
458   if ( HAVE_NETGEN ) then
459      set lvs_tool=netgen_lvs
460   endif
461endif
462
463if ( ! (${?drc_tool}) ) then
464   if ( HAVE_MAGIC ) then
465      set drc_tool=magic_drc
466   endif
467endif
468
469if ( ! (${?gds_tool}) ) then
470   if ( HAVE_MAGIC ) then
471      set gds_tool=magic_gds
472   endif
473endif
474
475if ( ! (${?display_tool}) ) then
476   if ( HAVE_MAGIC ) then
477      set display_tool=magic_view
478   endif
479endif
480
481#-----------------------------------------------------
482# The file "project_vars.sh" will ONLY be written if
483# one does not already exist, and then it will be an
484# empty file with a few pointers to values that can
485# be set by the user.
486#-----------------------------------------------------
487
488if ( ! -f ${userfile} ) then
489   echo "#\!/bin/tcsh -f" > ${userfile}
490   echo "#------------------------------------------------------------" >> ${userfile}
491   echo "# project variables for project ${projectpath}" >> ${userfile}
492   echo "#------------------------------------------------------------" >> ${userfile}
493   echo "" >> ${userfile}
494
495   #------------------------------------------------------------------
496   # Check for any option defaults set by the .sh file for each entry
497   # in the project_vars.sh file.  If they are not defined, then set
498   # them to an empty string or a global default, if there is one.
499   # Note that this does not change the behavior that options set
500   # in the tech .sh file become the defaults and are overridden by
501   # the same variables set in the project variables file.  The
502   # purpose is to show the user what the default is, so that they
503   # are aware what they may be changing.
504   #------------------------------------------------------------------
505
506   echo "# Flow options:" >> ${userfile}
507   echo "# -------------------------------------------" >> ${userfile}
508
509   if ( ${?synthesis_tool} ) then
510      echo \# set synthesis_tool = ${synthesis_tool} >> ${userfile}
511   else
512      if ( HAVE_YOSYS ) then
513         echo \# set synthesis_tool = yosys >> ${userfile}
514         set synthesis_tool = yosys
515      else
516         echo \# set synthesis_tool = >> ${userfile}
517      endif
518   endif
519
520   if ( ${?placement_tool} ) then
521      echo \# set placement_tool = ${placement_tool} >> ${userfile}
522   else
523      if ( HAVE_GRAYWOLF ) then
524         echo \# set placement_tool = graywolf >> ${userfile}
525         set placement_tool = graywolf
526      else if ( HAVE_REPLACE ) then
527         echo \# set placement_tool = replace >> ${userfile}
528         set placement_tool = replace
529      else
530         echo \# set placement_tool = >> ${userfile}
531      endif
532   endif
533
534   if ( ${?sta_tool} ) then
535      echo \# set sta_tool = ${sta_tool} >> ${userfile}
536   else
537      echo \# set sta_tool = vesta >> ${userfile}
538      set sta_tool = vesta
539   endif
540
541   if ( ${?router_tool} ) then
542      echo \# set router_tool = ${router_tool} >> ${userfile}
543   else
544      if ( HAVE_QROUTER ) then
545         echo \# set router_tool = qrouter >> ${userfile}
546         set router_tool = qrouter
547      else
548         echo \# set router_tool = >> ${userfile}
549      endif
550   endif
551
552   if ( ${?migrate_tool} ) then
553      echo \# set migrate_tool = ${migrate_tool} >> ${userfile}
554   else
555      if ( HAVE_MAGIC ) then
556         echo \# set migrate_tool = magic_db >> ${userfile}
557         set migrate_tool = magic_db
558      else
559         echo \# set migrate_tool = >> ${userfile}
560      endif
561   endif
562
563   if ( ${?lvs_tool} ) then
564      echo \# set lvs_tool = ${lvs_tool} >> ${userfile}
565   else
566      if ( HAVE_NETGEN ) then
567         echo \# set lvs_tool = netgen_lvs >> ${userfile}
568         set lvs_tool = netgen_lvs
569      else
570         echo \# set lvs_tool = >> ${userfile}
571      endif
572   endif
573
574   if ( ${?drc_tool} ) then
575      echo \# set drc_tool = ${drc_tool} >> ${userfile}
576   else
577      if ( HAVE_MAGIC ) then
578         echo \# set drc_tool = magic_drc >> ${userfile}
579         set drc_tool = magic_drc
580      else
581         echo \# set drc_tool = >> ${userfile}
582      endif
583   endif
584
585   if ( ${?gds_tool} ) then
586      echo \# set gds_tool = ${gds_tool} >> ${userfile}
587   else
588      if ( HAVE_MAGIC ) then
589         echo \# set gds_tool = magic_gds >> ${userfile}
590         set gds_tool = magic_gds
591      else
592         echo \# set gds_tool = >> ${userfile}
593      endif
594   endif
595
596   if ( ${?display_tool} ) then
597      echo \# set display_tool = ${display_tool} >> ${userfile}
598   else
599      if ( HAVE_MAGIC ) then
600         echo \# set display_tool = magic_view >> ${userfile}
601         set display_tool = magic_view
602      else
603         echo \# set display_tool = >> ${userfile}
604      endif
605   endif
606
607   echo "" >> ${userfile}
608
609   echo "# Synthesis command options:" >> ${userfile}
610   echo "# -------------------------------------------" >> ${userfile}
611
612   if ( ${?hard_macros} ) then
613      echo \# set hard_macros = \"${hard_macros}\" >> ${userfile}
614   else
615      echo \# set hard_macros = >> ${userfile}
616   endif
617
618   if ( ${?yosys_options} ) then
619      echo \# set yosys_options = \"${yosys_options}\" >> ${userfile}
620   else
621      echo \# set yosys_options = >> ${userfile}
622   endif
623
624   if ( ${?yosys_script} ) then
625      echo \# set yosys_script = \"${yosys_script}\" >> ${userfile}
626   else
627      echo \# set yosys_script = >> ${userfile}
628   endif
629
630   if ( ${?yosys_debug} ) then
631      echo \# set yosys_debug = \"${yosys_debug}\" >> ${userfile}
632   else
633      echo \# set yosys_debug = >> ${userfile}
634   endif
635
636   if ( ${?abc_script} ) then
637      echo \# set abc_script = \"${abc_script}\" >> ${userfile}
638   else
639      echo \# set abc_script = >> ${userfile}
640   endif
641
642   if ( ${?nobuffers} ) then
643      echo \# set nobuffers = \"${nobuffers}\" >> ${userfile}
644   else
645      echo \# set nobuffers = >> ${userfile}
646   endif
647
648   if ( ${?inbuffers} ) then
649      echo \# set inbuffers = \"${inbuffers}\" >> ${userfile}
650   else
651      echo \# set inbuffers = >> ${userfile}
652   endif
653
654   if ( ${?postproc_options} ) then
655      echo \# set postproc_options = \"${postproc_options}\" >> ${userfile}
656   else
657      echo \# set postproc_options = >> ${userfile}
658   endif
659
660   if ( ${?xspice_options} ) then
661      echo \# set xspice_options = \"${xspice_options}\" >> ${userfile}
662   else
663      echo \# set xspice_options = >> ${userfile}
664   endif
665
666   if ( ${?fill_ratios} ) then
667      echo \# set fill_ratios = \"${fill_ratios}\" >> ${userfile}
668   else
669      echo \# set fill_ratios = >> ${userfile}
670   endif
671
672   if ( ${?nofanout} ) then
673      echo \# set nofanout = \"${nofanout}\" >> ${userfile}
674   else
675      echo \# set nofanout = >> ${userfile}
676   endif
677
678   if ( ${?fanout_options} ) then
679      echo \# set fanout_options = \"${fanout_options}\" >> ${userfile}
680   else
681      echo \# set fanout_options = >> ${userfile}
682   endif
683
684   if ( ${?source_file_list} ) then
685      echo \# set source_file_list = \"${source_file_list}\" >> ${userfile}
686   else
687      echo \# set source_file_list = >> ${userfile}
688   endif
689
690   if ( ${?is_system_verilog} ) then
691      echo \# set is_system_verilog = \"${is_system_verilog}\" >> ${userfile}
692   else
693      echo \# set is_system_verilog = >> ${userfile}
694   endif
695
696   echo "" >> ${userfile}
697   echo "# Placement command options:" >> ${userfile}
698   echo "# -------------------------------------------" >> ${userfile}
699
700   if ( ${?initial_density} ) then
701      echo \# set initial_density = \"${initial_density}\" >> ${userfile}
702   else
703      echo \# set initial_density = >> ${userfile}
704   endif
705
706   if ( ${?graywolf_options} ) then
707      echo \# set graywolf = \"${graywolf_options}\" >> ${userfile}
708   else
709      echo \# set graywolf_options = >> ${userfile}
710   endif
711
712   if ( ${?addspacers_options} ) then
713      echo \# set addspacers_options = \"${addspacers_options}\" >> ${userfile}
714   else
715      echo \# set addspacers_options = >> ${userfile}
716   endif
717
718   if ( ${?addspacers_power} ) then
719      echo \# set addspacers_power = \"${addspacers_power}\" >> ${userfile}
720   else
721      echo \# set addspacers_power = >> ${userfile}
722   endif
723
724   echo "" >> ${userfile}
725   echo "# Router command options:" >> ${userfile}
726   echo "# -------------------------------------------" >> ${userfile}
727
728   if ( ${?route_show} ) then
729      echo \# set route_show = \"${route_show}\" >> ${userfile}
730   else
731      echo \# set route_show = >> ${userfile}
732   endif
733
734   if ( ${?route_layers} ) then
735      echo \# set route_layers = \"${route_layers}\" >> ${userfile}
736   else
737      echo \# set route_layers = >> ${userfile}
738   endif
739
740   if ( ${?via_use} ) then
741      echo \# set via_use = \"${via_use}\" >> ${userfile}
742   else
743      echo \# set via_use = >> ${userfile}
744   endif
745
746   if ( ${?via_stacks} ) then
747      echo \# set via_stacks = \"${via_stacks}\" >> ${userfile}
748   else
749      echo \# set via_stacks = >> ${userfile}
750   endif
751
752   if ( ${?qrouter_options} ) then
753      echo \# set qrouter_options = \"${qrouter_options}\" >> ${userfile}
754   else
755      echo \# set qrouter_options = >> ${userfile}
756   endif
757
758   if ( ${?qrouter_nocleanup} ) then
759      echo \# set qrouter_nocleanup = \"${qrouter_nocleanup}\" >> ${userfile}
760   else
761      echo \# set qrouter_nocleanup = >> ${userfile}
762   endif
763
764   echo "" >> ${userfile}
765   echo "# STA command options:" >> ${userfile}
766   echo "# -------------------------------------------" >> ${userfile}
767
768   echo ""
769   echo "" >> ${userfile}
770   echo \# Minimum period of the clock use \"--period value\" \(value in ps\) \
771	>> ${userfile}
772
773   if ( HAVE_OPENSTA ) then
774      if ( ${?opensta_options} ) then
775         echo \# set opensta_options = \"${opensta_options}\" >> ${userfile}
776      else
777         echo \# set opensta_options = >> ${userfile}
778      endif
779   endif
780   if ( HAVE_OPENTIMER ) then
781      if ( ${?opentimer_options} ) then
782         echo \# set opentimer_options = \"${opentimer_options}\" >> ${userfile}
783      else
784         echo \# set opentimer_options = >> ${userfile}
785      endif
786   endif
787   if ( ${?vesta_options} ) then
788      echo \# set vesta_options = \"${vesta_options}\" >> ${userfile}
789   else
790      echo \# set vesta_options = >> ${userfile}
791   endif
792
793   echo "" >> ${userfile}
794   echo "# Other options:" >> ${userfile}
795   echo "# -------------------------------------------" >> ${userfile}
796
797   if ( ${?migrate_gdsview} ) then
798      echo \# set migrate_gdsview = \"${migrate_gdsview}\" >> ${userfile}
799   else
800      echo \# set migrate_gdsview = >> ${userfile}
801   endif
802   if ( ${?migrate_options} ) then
803      echo \# set migrate_options = \"${migrate_options}\" >> ${userfile}
804   else
805      echo \# set migrate_options = >> ${userfile}
806   endif
807
808   if ( ${?lef_options} ) then
809      echo \# set lef_options = \"${lef_options}\" >> ${userfile}
810   else
811      echo \# set lef_options = >> ${userfile}
812   endif
813
814   if ( ${?drc_gdsview} ) then
815      echo \# set drc_gdsview = \"${drc_gdsview}\" >> ${userfile}
816   else
817      echo \# set drc_gdsview = >> ${userfile}
818   endif
819   if ( ${?drc_options} ) then
820      echo \# set drc_options = \"${drc_options}\" >> ${userfile}
821   else
822      echo \# set drc_options = >> ${userfile}
823   endif
824
825   if ( ${?gds_options} ) then
826      echo \# set gds_options = \"${gds_options}\" >> ${userfile}
827   else
828      echo \# set gds_options = >> ${userfile}
829   endif
830
831   echo "" >> ${userfile}
832   echo "#------------------------------------------------------------" >> ${userfile}
833   echo "" >> ${userfile}
834else
835   # project_vars.sh may contain settings that affect how qflow.sh runs, so
836   # source it here.
837   source ${userfile}
838endif
839
840if ($dosynth == 0) then
841   echo -n "# " >> ${execfile}
842endif
843if ( ${vsource} == "" ) then
844   echo "${scriptdir}/${synthesis_tool}.sh ${projectpath} ${modulename} || exit 1" >> ${execfile}
845else
846   echo "${scriptdir}/${synthesis_tool}.sh ${projectpath} ${modulename} ${vsource} || exit 1" >> ${execfile}
847endif
848
849if ($doplace == 0) then
850   echo -n "# " >> ${execfile}
851endif
852# Use -d because the user may decide not to run fanout buffering,
853# and the files generated by place2def.tcl are required for routing.
854echo "${scriptdir}/${placement_tool}.sh -d ${projectpath} ${modulename} || exit 1" >> ${execfile}
855
856set first=""
857if ($dosta == 0) then
858	echo -n "# " >> ${execfile}
859endif
860echo "${scriptdir}/${sta_tool}.sh ${first} ${projectpath} ${modulename} || exit 1" >> ${execfile}
861set first="-a"
862endif
863
864if ($doroute == 0) then
865   echo -n "# " >> ${execfile}
866endif
867echo "${scriptdir}/${router_tool}.sh ${projectpath} ${modulename} || exit 1" >> ${execfile}
868
869set first=""
870if ($dobackanno == 0) then
871    echo -n "# " >> ${execfile}
872endif
873echo "${scriptdir}/${sta_tool}.sh ${first} -d ${projectpath} ${modulename} || exit 1" >> ${execfile}
874set first="-a"
875endif
876
877if ($domigrate == 0) then
878   echo -n "# " >> ${execfile}
879endif
880echo "${scriptdir}/${migrate_tool}.sh ${projectpath} ${modulename} || exit 1" >> ${execfile}
881
882if ($dodrc == 0) then
883   echo -n "# " >> ${execfile}
884endif
885echo "${scriptdir}/${drc_tool}.sh ${projectpath} ${modulename} || exit 1" >> ${execfile}
886
887if ($dolvs == 0) then
888   echo -n "# " >> ${execfile}
889endif
890echo "${scriptdir}/${lvs_tool}.sh ${projectpath} ${modulename} || exit 1" >> ${execfile}
891
892if ($dogdsii == 0) then
893   echo -n "# " >> ${execfile}
894endif
895echo "${scriptdir}/${gds_tool}.sh ${projectpath} ${modulename} || exit 1" >> ${execfile}
896
897if ($doclean == 0) then
898   echo -n "# " >> ${execfile}
899endif
900echo "${scriptdir}/cleanup.sh ${projectpath} ${modulename} || exit 1" >> ${execfile}
901
902if ($dopurge == 0) then
903   echo -n "# " >> ${execfile}
904endif
905echo "${scriptdir}/cleanup.sh -p ${projectpath} ${modulename} || exit 1" >> ${execfile}
906
907if ($dodisplay == 0) then
908   echo -n "# " >> ${execfile}
909endif
910echo "${scriptdir}/${display_tool}.sh ${projectpath} ${modulename} || exit 1" >> ${execfile}
911
912if ( $actions == 0 ) then
913   echo "No actions specified on command line;"
914   echo "creating qflow script file ${execfile} only."
915   echo "Uncomment lines in this file and source the file to run the flow."
916endif
917
918chmod u+x ${execfile}
919
920# Note: Support legacy behavior;  ${magicrc} may be a full path or may be
921# relative to ${techdir}
922
923if ( -f ${techdir}/${magicrc} ) then
924    set magicrc=${techdir}/${magicrc}
925else if (!( -f ${magicrc} )) then
926    echo "Error:  Technology file not in ${techdir}/${magicrc} or ${magicrc}!"
927endif
928
929# Drop the magic startup file into the layout directory if it does not exist
930# If it exists but the technology directory has a newer file, or if we are
931# changing technologies, then copy the old file to a backup and create a new
932# one.
933
934if (-d ${layoutdir}) then
935   if (!(-f ${layoutdir}/.magicrc)) then
936      cp ${magicrc} ${layoutdir}/.magicrc
937   else if ( $newtech == 1 ) then
938      echo "Technology changed:  Old .magicrc file moved to .magicrc.orig"
939      cp ${layoutdir}/.magicrc ${layoutdir}/.magicrc.orig
940      cp ${magicrc} ${layoutdir}/.magicrc
941   else if ( -M ${magicrc} > -M ${layoutdir}/.magicrc ) then
942      echo -n "Technology .magicrc file has been updated.  "
943      echo "Old .magicrc file moved to .magicrc.orig"
944      cp ${layoutdir}/.magicrc ${layoutdir}/.magicrc.orig
945      cp ${magicrc} ${layoutdir}/.magicrc
946   endif
947endif
948
949# Drop the GrayWolf parameter file into the layout directory if it does not
950# exist.  Like the above, check if the techdir has a newer version, or if we
951# are changing technologies.
952
953if (-d ${layoutdir}) then
954   if (!(-f ${layoutdir}/${modulename}.par)) then
955      cp ${techdir}/${techname}.par ${layoutdir}/${modulename}.par
956   else if ( $newtech == 1 ) then
957      echo "Technology changed:  Old .par file moved to .par.orig"
958      cp ${layoutdir}/${modulename}.par ${layoutdir}/${modulename}.par.orig
959      cp ${techdir}/${techname}.par ${layoutdir}/${modulename}.par
960   else if ( -M ${techdir}/${techname}.par > -M ${layoutdir}/${modulename}.par ) then
961      echo "Technology .par file has been updated.  Old .par file moved to .par.orig"
962      cp ${layoutdir}/${modulename}.par ${layoutdir}/${modulename}.par.orig
963      cp ${techdir}/${techname}.par ${layoutdir}/${modulename}.par
964   endif
965endif
966
967# Execute the script file to run any command that has not been commented out
968exec ${execfile}
969
970exit 0
971