1#!/bin/tcsh -f
2#
3#-------------------------------------------------------------------------
4# checkdirs.sh
5#-------------------------------------------------------------------------
6# April 2013
7# Tim Edwards, Open Circuit Design
8#-------------------------------------------------------------------------
9#
10# This script searches for technology directories and project directories.
11# It sets variables associated with each directory for other scripts to
12# use.
13#
14# The directory hierarchy is expected to be set up as follows:
15#
16# <project> ----> source/
17#	    ----> synthesis/
18#	    ----> layout/
19#	    ----> tech/<techname>	(optional)
20#
21# "tech" is optional if the technology is in the qflow install location,
22# QFLOW_TECH_DIR/<techname>.  If there is already a technology specified
23# in the qflow_vars.sh file, then pass it as the 2nd argument and the
24# checkdirs script will only check the other directories.  Otherwise, the
25# 2nd argument should be an empty string, or may be omitted if the project
26# path is also omitted
27#
28# Optionally, techfiles may be in subdirectory <techname> without the
29# intervening "tech" directory.  i.e.,
30#
31# <project> ----> <techname>
32#
33# Optionally, "tech" may point directly to the directory containing techfile
34# data, i.e.,
35#
36# <project> ----> tech/
37#
38# If <project> is not specified on the command line, then it is assumed
39# to be the current working directory.  If any standard subdirectories
40# "source", "synthesis", or "layout" are not found, they will be set to
41# the project directory.  The techfile directory must be found, or
42# synthesis cannot proceed.
43#
44# Source this file using "source" to add variables to the existing shell
45# environment.
46#
47#-------------------------------------------------------------------------
48
49# Environment variables override everything else:
50#   QFLOW_TECH_DIR	path to technology directory
51#   QFLOW_TECH		name of technology
52#   QFLOW_PROJECT_ROOT	path to project top level directory
53#
54# The second two are checked before calling this routine so
55# that there are known values for the two arguments passed
56# to it.
57
58if ($#argv != 2 && $#argv != 3) then
59   echo "Usage:  checkdirs.sh <technology_name> <tech_path> [<project_name>]"
60   exit 1
61endif
62
63set techname=${argv[1]}
64
65if ($#argv >= 2) then
66   set techdir=${argv[2]}
67else
68   set techdir=""
69endif
70
71# Environment variable overrides the project root path in all cases
72# except when the project root path is specified on the command line
73# by -p.  If the environment variable does not exist, the project
74# root directory is assumed to be the current working directory.
75
76if ($#argv == 3) then
77   set projectpath=${argv[3]}
78else
79   set projectpath=`pwd`
80endif
81
82#-----------------------------------------------------------------
83# For portability, convert the home directory to the tilde escape
84# Note that projectpath must be quoted every time to preserve the ~
85#-----------------------------------------------------------------
86
87set projectpath="`echo $projectpath | sed -e 's,^${HOME},~,'`"
88
89#----------------------------------------------------
90# Check for standard working directories
91#----------------------------------------------------
92
93if ( -d ${projectpath}/source ) then
94   set sourcedir="${projectpath}"/source
95else
96   set sourcedir="${projectpath}"
97endif
98
99if ( -d ${projectpath}/synthesis ) then
100   set synthdir="${projectpath}"/synthesis
101else
102   set synthdir="${projectpath}"
103endif
104
105if ( -d ${projectpath}/layout ) then
106   set layoutdir="${projectpath}"/layout
107else
108   set layoutdir="${projectpath}"
109endif
110
111#----------------------------------------------------
112# Set variables from install locations here, so we
113# don't have to do it in every script separately.
114# Track path to scripts and binaries used by qflow
115#----------------------------------------------------
116
117set scriptdir=SUBST_SCRIPT_DIR
118set bindir=SUBST_BIN_DIR
119
120#----------------------------------------------------
121# Check for the techfile (see comments at top)
122#----------------------------------------------------
123
124# The environment variable overrides anything else
125set techtest=`printenv QFLOW_TECH_DIR`
126if ($techtest != "") then
127   set techdir=$techtest
128endif
129
130# Check that the technology directory points to a valid path;
131# that is, that there is a file <techname>.sh in it.
132
133if ($techdir != "") then
134   if ( !(-r ${techdir}/${techname}.sh )) then
135      if ( -d ${techdir}/${techname} ) then
136	 set techdir=${techdir}/${techname}
137      else
138	 set techdir=""
139      endif
140   endif
141endif
142
143if ($techdir != "") then
144   # Technology directory has been validated, so return with no error
145   exit 0
146endif
147
148if ( -d ${projectpath}/tech/${techname} ) then
149   set techdir="${projectpath}"/tech/${techname}
150else
151   if ( -d ${projectpath}/${techname} ) then
152      set techdir="${projectpath}"/${techname}
153   else
154      if ( -d ${projectpath}/tech && -r ${projectpath}/tech/${techname}.sh ) then
155	 set techdir="${projectpath}"/tech
156      else
157	 if ( -d SUBST_TECH_DIR/${techname} ) then
158	    set techdir=SUBST_TECH_DIR/${techname}
159	 else
160            echo "Don't know about technology '${techname}'"
161	    echo "Check SUBST_TECH_DIR/ for known technologies"
162            exit 1
163	 endif
164      endif
165   endif
166endif
167
168# Validate the technology directory
169if ($techdir != "") then
170   if ( !(-r ${techdir}/${techname}.sh )) then
171      if ( -d ${techdir}/${techname} ) then
172	 set techdir=${techdir}/${techname}
173         if ( !(-r ${techdir}/${techname}.sh )) then
174	    set techdir=""
175         endif
176      else
177	 set techdir=""
178      endif
179   endif
180endif
181
182if ($techdir != "") then
183   # Technology directory has been validated, so return with no error
184   exit 0
185endif
186
187# Technology directory was not found, so fail.
188echo "Technology directory not validated"
189exit 1
190#----------------------------------------------------
191