eliminate need of flex
[fw/sdcc] / src / SDCCmain.c
index 3231e34c047ce37bfe4d25821df58926b9eea28b..7427f55591e52774e0782a9178a47253241fd149 100644 (file)
@@ -58,8 +58,10 @@ char *fullDstFileName;               /* full name for the output file; */
 char *dstFileName;             /* destination file name without extension */
 char *dstPath = "";            /* path for the output files; */
                                /* "" is equivalent with cwd */
-char *moduleName;              /* module name is source file without path and extension */
+char *moduleNameBase;          /* module name base is source file without path and extension */
                                 /* can be NULL while linking without compiling */
+char *moduleName;              /* module name is same as module name base, but with all */
+                               /* non-alphanumeric characters replaced with underscore */
 int currRegBank = 0;
 int RegBankUsed[4] = {1, 0, 0, 0}; /*JCF: Reg Bank 0 used by default*/
 struct optimize optimize;
@@ -606,7 +608,12 @@ processFile (char *s)
           fext--;
         }
 #endif
+      moduleNameBase = Safe_strdup ( fext );
       moduleName = Safe_strdup ( fext );
+      
+      for (fext = moduleName; *fext; fext++)
+        if (!isalnum (*fext))
+         *fext = '_';
       return;
     }
 
@@ -1010,6 +1017,7 @@ parseCmdLine (int argc, char **argv)
          if (!port->parseOption (&argc, argv, &i))
            {
              werror (W_UNKNOWN_OPTION, argv[i]);
+             continue;
            }
          else
            {
@@ -1235,11 +1243,11 @@ parseCmdLine (int argc, char **argv)
       /* use the modulename from the C-source */
       if (fullSrcFileName)
         {
-         size_t bufSize = strlen (dstPath) + strlen (moduleName) + 1;
+         size_t bufSize = strlen (dstPath) + strlen (moduleNameBase) + 1;
 
          dstFileName = Safe_alloc (bufSize);
           strncpyz (dstFileName, dstPath, bufSize);
-          strncatz (dstFileName, moduleName, bufSize);
+          strncatz (dstFileName, moduleNameBase, bufSize);
         }
       /* use the modulename from the first object file */
       else if ((s = peekSet(relFilesSet)) != NULL)
@@ -1612,18 +1620,36 @@ linkEdit (char **envp)
   if (port->linker.cmd)
     {
       char buffer2[PATH_MAX];
-      set *libSet=NULL;
+      char buffer3[PATH_MAX];
+      set *tempSet=NULL, *libSet=NULL;
 
+      strcpy(buffer3, dstFileName);
       if(TARGET_IS_PIC16) {
-         /* use $3 to set the linker include directories */
-         libSet = appendStrSet(libDirsSet, "-I\"", "\"");
-
-         /* now add the libraries from command line */
+        
+         /* use $l to set the linker include directories */
+         tempSet = appendStrSet(libDirsSet, "-I\"", "\"");
+         mergeSets(&linkOptionsSet, tempSet);
+         
+         tempSet = appendStrSet(libPathsSet, "-I\"", "\"");
+         mergeSets(&linkOptionsSet, tempSet);
+
+         /* use $3 for libraries from command line --> libSet */
          mergeSets(&libSet, libFilesSet);
+
+         tempSet = appendStrSet(relFilesSet, "", "");
+         mergeSets(&libSet, tempSet);
+//         libSet = reverseSet(libSet);
+
+       if(fullSrcFileName) {
+//             strcpy(buffer3, strrchr(fullSrcFileName, DIR_SEPARATOR_CHAR)+1);
+               /* if it didn't work, revert to old behaviour */
+               if(!strlen(buffer3))strcpy(buffer3, dstFileName);
+               strcat(buffer3, port->linker.rel_ext);
+               
+       } else strcpy(buffer3, "");
       }
       
-      buildCmdLine (buffer2, port->linker.cmd, dstFileName, scratchFileName, (libSet?joinStrSet(libSet):NULL), linkOptionsSet);
-      if(libSet)deleteSet(&libSet);
+      buildCmdLine (buffer2, port->linker.cmd, buffer3, scratchFileName, (libSet?joinStrSet(libSet):NULL), linkOptionsSet);
 
       buildCmdLine2 (buffer, sizeof(buffer), buffer2);
     }
@@ -1893,10 +1919,12 @@ setBinPaths(const char *argv0)
     addSetHead(&binPathSet, Safe_strdup(buf));
   }
 
+#if 0
   if (options.printSearchDirs) {
     printf("programs:\n");
     fputStrSet(stdout, binPathSet);
   }
+#endif
 }
 
 /* Set system include path */
@@ -1919,10 +1947,12 @@ setIncludePath(void)
   if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
     addSetHead(&includeDirsSet, p);
 
+#if 0
   if (options.printSearchDirs) {
     printf("includedir:\n");
     fputStrSet(stdout, includeDirsSet);
   }
+#endif
 }
 
 /* Set system lib path */
@@ -1945,10 +1975,12 @@ setLibPath(void)
   if ((p = getenv(SDCC_LIB_NAME)) != NULL)
     addSetHead(&libDirsSet, p);
 
+#if 0
   if (options.printSearchDirs) {
     printf("libdir:\n");
     fputStrSet(stdout, libDirsSet);
   }
+#endif
 }
 
 /* Set data path */
@@ -1985,10 +2017,12 @@ setDataPaths(const char *argv0)
   addSet(&dataDirsSet, Safe_strdup(DATADIR));
 #endif
 
+#if 0
   if (options.printSearchDirs) {
     printf("datadir:\n");
     fputStrSet(stdout, dataDirsSet);
   }
+#endif
 
   setIncludePath();
   setLibPath();
@@ -2026,6 +2060,23 @@ initValues (void)
 
 }
 
+static void doPrintSearchDirs(void)
+{
+    printf("programs:\n");
+    fputStrSet(stdout, binPathSet);
+
+    printf("datadir:\n");
+    fputStrSet(stdout, dataDirsSet);
+
+    printf("includedir:\n");
+    fputStrSet(stdout, includeDirsSet);
+
+    printf("libdir:\n");
+    fputStrSet(stdout, libDirsSet);
+    fputStrSet(stdout, libPathsSet);
+}
+
+
 static void
 sig_handler (int signal)
 {
@@ -2119,6 +2170,12 @@ main (int argc, char **argv, char **envp)
   setBinPaths(argv[0]);
   setDataPaths(argv[0]);
 
+  if(port->initPaths)
+       port->initPaths();
+  
+  if(options.printSearchDirs)
+       doPrintSearchDirs();
+
   /* if no input then printUsage & exit */
   if (!options.c1mode && !fullSrcFileName && peekSet(relFilesSet) == NULL) {
     if (!options.printSearchDirs)
@@ -2149,7 +2206,8 @@ main (int argc, char **argv, char **envp)
 
       yyparse ();
 
-      pclose(yyin);
+      if (pclose(yyin))
+        fatalError = 1;
       deleteSetItem(&pipeSet, yyin);
 
       if (fatalError) {