Rework naming in `staging_install.py` to clearer.

 * `-finalpath` is where the files are installed to on the file system.
 * `-writeto` is where the files will be written.

Signed-off-by: Tim 'mithro' Ansell <me@mith.ro>
diff --git a/common/staging_install.py b/common/staging_install.py
index f02e66f..e840fe0 100755
--- a/common/staging_install.py
+++ b/common/staging_install.py
@@ -25,19 +25,19 @@
   -staging <path>    Path to staging top level directory that the files
                      will be installed from.
 
-  -target <path>     Final install path in system file system.
+  -finalpath <path>  Final install path in system file system.
 
                      Normally, '$(prefix)/pdks/<unique pdk name>'.
 
-                     If -local is not given, this will be the top level
+                     If -writeto is not given, this will be the top level
                      directory location the files are installed too.
 
-  -local <path>      Actual file system location to write the files too.
+  -writeto <path>    Actual file system location to write the files too.
                      The result can then be packaged and distributed.
 
                      For usage with things like package managers and other
                      administrator installation tooling.  The resulting
-                     files still need to be installed at '-target' on the
+                     files still need to be installed at '-finalpath' on the
                      final system.
 
                      Think 'DESTDIR', see
@@ -82,19 +82,19 @@
         st = os.stat(filepath)
         os.chmod(filepath, st.st_mode | stat.S_IWUSR)
 
-# Filter files to replace all strings matching "stagingdir" with "localdir" for
+# Filter files to replace all strings matching "stagingdir" with "finaldir" for
 # every file in "tooldir".  If "tooldir" contains subdirectories, then recursively
 # apply the replacement filter to all files in the subdirectories.  Do not follow
 # symbolic links.
 
-def filter_recursive(tooldir, stagingdir, localdir):
+def filter_recursive(tooldir, stagingdir, finaldir):
     # Add any non-ASCII file types here
     bintypes = ['.gds', '.gds2', '.gdsii', '.png', '.swp']
 
     # Also do substitutions on strings containing the stagingdir parent
-    # directory (replace with the localdir parent directory).
+    # directory (replace with the finaldir parent directory).
     stagingparent = os.path.split(stagingdir)[0]
-    localparent = os.path.split(localdir)[0]
+    localparent = os.path.split(finaldir)[0]
 
     if not os.path.exists(tooldir):
         return 0
@@ -113,7 +113,7 @@
         if os.path.islink(filepath):
             continue
         elif os.path.isdir(filepath):
-            total += filter_recursive(filepath, stagingdir, localdir)
+            total += filter_recursive(filepath, stagingdir, finaldir)
         else:
             with open(filepath, 'r') as ifile:
                 try:
@@ -128,7 +128,7 @@
             modified = False
             with open(filepath, 'w') as ofile:
                 for line in flines:
-                    newline = line.replace(stagingdir, localdir)
+                    newline = line.replace(stagingdir, finaldir)
                     newline = newline.replace(stagingparent, localparent)
                     print(newline, file=ofile)
                     if newline != line:
@@ -263,11 +263,12 @@
     newopt = []
 
     stagingdir = None
-    targetdir = None
     link_from = None
-    localdir = None
     variable = None
 
+    writedir = None  # Directory to write the files to.
+    finaldir = None  # Directory files will end up installed to.
+
     ef_format = False
     do_install = True
 
@@ -316,12 +317,12 @@
         elif option[0] == 'staging' or option[0] == 'source':
             optionlist.remove(option)
             stagingdir = option[1]
-        elif option[0] == 'target':
+        elif option[0] == 'writeto':
             optionlist.remove(option)
-            targetdir = option[1]
-        elif option[0] == 'local':
+            writedir = option[1]
+        elif option[0] == 'finalpath':
             optionlist.remove(option)
-            localdir = option[1]
+            finaldir = option[1]
         elif option[0] == 'variable':
             optionlist.remove(option)
             variable = option[1]
@@ -331,17 +332,17 @@
         print("No staging directory specified.  Exiting.")
         sys.exit(1)
 
-    if not targetdir:
-        print("No target directory specified.  Exiting.")
+    if not finaldir:
+        print("No final install directory specified.  Exiting.")
         sys.exit(1)
 
-    # If localdir is not specified, then it is the same as the parent
+    # If finaldir is not specified, then it is the same as the parent
     # of the target (local installation assumed)
-    if not localdir:
-        localdir = targetdir
+    if not writedir:
+        writedir = finaldir
 
     # Take the target PDK name from the target path last component
-    pdkname = os.path.split(targetdir)[1]
+    pdkname = os.path.split(writedir)[1]
 
     # If link source is a PDK name, if it has no path, then pull the
     # path from the target name.
@@ -350,14 +351,14 @@
         if link_from != 'source':
             if link_from.find('/', 0) < 0:
                 link_name = link_from
-                link_from = os.path.split(localdir)[0] + '/' + link_name
+                link_from = os.path.split(finaldir)[0] + '/' + link_name
         else:
             # If linking from source, convert the source path to an
             # absolute pathname.
             stagingdir = os.path.abspath(stagingdir)
 
-        # If link_from is the same as localdir, then set link_from to None
-        if link_from == localdir:
+        # If link_from is the same as finaldir, then set link_from to None
+        if link_from == finaldir:
             link_from = None
 
     # checkdir is the DIST target directory for the PDK pointed
@@ -365,24 +366,24 @@
     # symbolic links to the (not yet existing) final install location.
 
     if link_name:
-        checkdir = os.path.split(targetdir)[0] + '/' + link_name
+        checkdir = os.path.split(writedir)[0] + '/' + link_name
     else:
         checkdir = ''
 
     # Diagnostic
     if do_install:
-        print("Installing in target directory " + targetdir)
+        print("Installing in target directory " + writedir)
     else:
-        print("Uninstalling from target directory " + targetdir)
+        print("Uninstalling from target directory " + writedir)
         print("(Method not yet implemented)")
 
     # Create the top-level directories
 
-    os.makedirs(targetdir, exist_ok=True)
-    os.makedirs(targetdir + '/libs.tech', exist_ok=True)
-    os.makedirs(targetdir + '/libs.ref', exist_ok=True)
+    os.makedirs(writedir, exist_ok=True)
+    os.makedirs(writedir + '/libs.tech', exist_ok=True)
+    os.makedirs(writedir + '/libs.ref', exist_ok=True)
     if os.path.isdir(stagingdir + '/libs.priv'):
-        os.makedirs(targetdir + '/libs.priv', exist_ok=True)
+        os.makedirs(writedir + '/libs.priv', exist_ok=True)
         has_priv = True
     else:
         has_priv = False
@@ -398,27 +399,27 @@
     # as they will be used to reference the target area to know which
     # files need to be checked and/or modified.
 
-    if not os.path.isdir(targetdir):
+    if not os.path.isdir(writedir):
         try:
-            os.makedirs(targetdir, exist_ok=True)
+            os.makedirs(writedir, exist_ok=True)
         except:
-            print('Fatal error:  Cannot make target directory ' + targetdir + '!')
+            print('Fatal error:  Cannot make target directory ' + writedir + '!')
             exit(1)
 
     # Remove any files from the target directory that are going to be replaced
     print('Removing files from target')
-    remove_target(stagingdir, targetdir)
+    remove_target(stagingdir, writedir)
 
     print('Copying staging files to target')
-    # print('Diagnostic:  copy_tree ' + stagingdir + ' ' + targetdir)
-    copy_tree(stagingdir, targetdir, preserve_symlinks=True)
+    # print('Diagnostic:  copy_tree ' + stagingdir + ' ' + writedir)
+    copy_tree(stagingdir, writedir, preserve_symlinks=True)
     print('Done.')
 
     # Magic and qflow setup files have references to the staging area that have
     # been used by the vendor install;  these need to be changed to the target
     # directory.
 
-    print('Changing local path references from ' + stagingdir + ' to ' + localdir)
+    print('Changing local path references from ' + stagingdir + ' to ' + finaldir)
     print('Part 1:  Tools')
 
     needcheck = ['ngspice']
@@ -427,9 +428,9 @@
         techdirs.append('/libs.priv/')
 
     for techdir in techdirs:
-        tools = os.listdir(targetdir + techdir)
+        tools = os.listdir(writedir + techdir)
         for tool in tools:
-            tooldir = targetdir + techdir + tool
+            tooldir = writedir + techdir + tool
 
             # There are few enough tool setup files that they can just all be
             # filtered directly.  This code only looks in the directory 'tooldir'.
@@ -440,7 +441,7 @@
             # no attempt to check for possible symlinks to link_from if link_from
             # is a base PDK.
 
-            total = filter_recursive(tooldir, stagingdir, localdir)
+            total = filter_recursive(tooldir, stagingdir, finaldir)
             if total > 0:
                 substr = 'substitutions' if total > 1 else 'substitution'
                 print('      ' + tool + ' (' + str(total) + ' ' + substr + ')')
@@ -451,14 +452,14 @@
     # generally small and deemed unnecessary to make symbolic links).
 
     if link_from not in ['source', None]:
-        thispdk = os.path.split(targetdir)[1]
+        thispdk = os.path.split(writedir)[1]
 
         # Only create links for PDKs other than the one we are making links to.
         if thispdk != link_from:
             print('Replacing files with symbolic links to ' + link_from + ' where possible.')
             for techdir in techdirs:
                 for tool in needcheck:
-                    tooldir = targetdir + techdir + tool
+                    tooldir = writedir + techdir + tool
                     srctooldir = link_from + techdir + tool
                     if checkdir != '':
                         checktooldir = checkdir + techdir + tool
@@ -471,13 +472,13 @@
                             print('      ' + tool + ' (' + str(total) + ' ' + symstr + ')')
 
     # In .mag files in mag/ and maglef/, also need to change the staging
-    # directory name to localdir.  If "-variable" is specified in the options,
-    # the replace the staging path with the variable name, not localdir.
+    # directory name to finaldir.  If "-variable" is specified in the options,
+    # the replace the staging path with the variable name, not finaldir.
 
     if variable:
         localname = '$' + variable
     else:
-        localname = localdir
+        localname = finaldir
 
     needcheck = ['mag', 'maglef']
     refdirs = ['/libs.ref/']
@@ -489,7 +490,7 @@
         for refdir in refdirs:
             for filetype in needcheck:
                 print('   ' + filetype)
-                filedir = targetdir + refdir + filetype
+                filedir = writedir + refdir + filetype
                 if os.path.isdir(filedir):
                     libraries = os.listdir(filedir)
                     for library in libraries:
@@ -501,11 +502,11 @@
     else:
         print('Part 2:  Libraries')
         for refdir in refdirs:
-            libraries = os.listdir(targetdir + refdir)
+            libraries = os.listdir(writedir + refdir)
             for library in libraries:
                 print('   ' + library)
                 for filetype in needcheck:
-                    filedir = targetdir + refdir + library + '/' + filetype
+                    filedir = writedir + refdir + library + '/' + filetype
                     total = filter_recursive(filedir, stagingdir, localname)
                     if total > 0:
                         substr = 'substitutions' if total > 1 else 'substitution'
@@ -521,14 +522,14 @@
         print('Replacing files with symbolic links to source where possible.')
         for refdir in refdirs:
             if ef_format:
-                filedirs = os.listdir(targetdir + refdir)
+                filedirs = os.listdir(writedir + refdir)
                 for filedir in filedirs:
                     print('   ' + filedir)
-                    dirpath = targetdir + refdir + filedir
+                    dirpath = writedir + refdir + filedir
                     if os.path.isdir(dirpath):
                         libraries = os.listdir(dirpath)
                         for library in libraries:
-                            libdir = targetdir + refdir + filedir + '/' + library
+                            libdir = writedir + refdir + filedir + '/' + library
                             libfiles = os.listdir(libdir)
                             if 'sources.txt' in libfiles:
                                 libfiles = glob.glob(libdir + '/*')
@@ -541,12 +542,12 @@
                                     symstr = 'symlinks' if total > 1 else 'symlink'
                                     print('      ' + library + ' (' + str(total) + ' ' + symstr + ')')
             else:
-                libraries = os.listdir(targetdir + refdir)
+                libraries = os.listdir(writedir + refdir)
                 for library in libraries:
                     print('   ' + library)
-                    filedirs = os.listdir(targetdir + refdir + library)
+                    filedirs = os.listdir(writedir + refdir + library)
                     for filedir in filedirs:
-                        libdir = targetdir + refdir + library + '/' + filedir
+                        libdir = writedir + refdir + library + '/' + filedir
                         if os.path.isdir(libdir):
                             libfiles = os.listdir(libdir)
                             if 'sources.txt' in libfiles:
@@ -566,7 +567,7 @@
     # if the file contents match.
 
     elif link_from:
-        thispdk = os.path.split(targetdir)[1]
+        thispdk = os.path.split(writedir)[1]
 
         # Only create links for PDKs other than the one we are making links to.
         if thispdk != link_from:
@@ -575,14 +576,14 @@
 
             for refdir in refdirs:
                 if ef_format:
-                    filedirs = os.listdir(targetdir + refdir)
+                    filedirs = os.listdir(writedir + refdir)
                     for filedir in filedirs:
                         print('   ' + filedir)
-                        dirpath = targetdir + refdir + filedir
+                        dirpath = writedir + refdir + filedir
                         if os.path.isdir(dirpath):
                             libraries = os.listdir(dirpath)
                             for library in libraries:
-                                libdir = targetdir + refdir + filedir + '/' + library
+                                libdir = writedir + refdir + filedir + '/' + library
                                 srclibdir = link_from + refdir + filedir + '/' + library
                                 if checkdir != '':
                                     checklibdir = checkdir + refdir + filedir + '/' + library
@@ -594,12 +595,12 @@
                                         symstr = 'symlinks' if total > 1 else 'symlink'
                                         print('      ' + library + ' (' + str(total) + ' ' + symstr + ')')
                 else:
-                    libraries = os.listdir(targetdir + refdir)
+                    libraries = os.listdir(writedir + refdir)
                     for library in libraries:
                         print('   ' + library)
-                        filedirs = os.listdir(targetdir + refdir + library)
+                        filedirs = os.listdir(writedir + refdir + library)
                         for filedir in filedirs:
-                            libdir = targetdir + refdir + library + '/' + filedir
+                            libdir = writedir + refdir + library + '/' + filedir
                             srclibdir = link_from + refdir + library + '/' + filedir
                             if checkdir != '':
                                 checklibdir = checkdir + refdir + library + '/' + filedir
@@ -618,14 +619,14 @@
 
     for refdir in refdirs:
         if ef_format:
-            filedirs = os.listdir(targetdir + refdir)
+            filedirs = os.listdir(writedir + refdir)
             for filedir in filedirs:
                 if os.path.islink(filedir):
                     continue
                 elif os.path.isdir(filedir):
-                    libraries = os.listdir(targetdir + refdir + filedir)
+                    libraries = os.listdir(writedir + refdir + filedir)
                     for library in libraries:
-                        libdir = targetdir + refdir + filedir + '/' + library
+                        libdir = writedir + refdir + filedir + '/' + library
                         libfiles = os.listdir(libdir)
                         for libfile in libfiles:
                             filepath = libdir + '/' + libfile
@@ -640,11 +641,11 @@
                             elif os.path.splitext(libfile)[1] == '.swp':
                                 os.remove(filepath)
         else:
-            libraries = os.listdir(targetdir + refdir)
+            libraries = os.listdir(writedir + refdir)
             for library in libraries:
-                filedirs = os.listdir(targetdir + refdir + library)
+                filedirs = os.listdir(writedir + refdir + library)
                 for filedir in filedirs:
-                    filepath = targetdir + refdir + library + '/' + filedir
+                    filepath = writedir + refdir + library + '/' + filedir
                     if os.path.islink(filepath):
                         continue
                     elif os.path.isdir(filepath):
diff --git a/sky130/Makefile.in b/sky130/Makefile.in
index 627a6b0..c8e19c9 100644
--- a/sky130/Makefile.in
+++ b/sky130/Makefile.in
@@ -398,7 +398,7 @@
 # copying or linking the foundry vendor files to the target directory.
 STAGE = set -f ; ../common/foundry_install.py ${EF_FORMAT}
 ifneq ($(DESTDIR), )
-INSTALL = ../common/staging_install.py -local $(DESTDIR) ${EF_FORMAT}
+INSTALL = ../common/staging_install.py -writeto $(DESTDIR) ${EF_FORMAT}
 else
 INSTALL = ../common/staging_install.py ${EF_FORMAT}
 endif
@@ -1406,7 +1406,7 @@
 	echo "Starting SKY130 PDK migration on "`date` > ${SKY130A}_install.log
 	${INSTALL} \
 		-source ${STAGING_PATH}/${SKY130A} \
-		-target ${SHARED_PDKS_PATH}/${SKY130A} \
+		-finalpath ${SHARED_PDKS_PATH}/${SKY130A} \
 		-variable PDKPATH \
 		-link_from ${LINK_TARGETS} 2>&1 | tee -a ${SKY130A}_install.log
 	echo "Ended SKY130 PDK migration on "`date` >> ${SKY130A}_install.log