+ else
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+_discoverPaths (const char *argv0)
+{
+ /* Logic:
+ 1. Try the SDCCDIR environment variable.
+ 2. If (1) fails, and if the argv[0] includes a path, attempt to find the include
+ and library paths with respect to that. Note that under win32
+ argv[0] is always the full path to the program.
+ 3. If (1) and (2) fail, fall back to the compile time defaults.
+
+ Detecting assumes the same layout as when configured. If the
+ directories have been further moved about then discovery will
+ fail.
+ */
+
+ /* Some input cases:
+ "c:\fish\sdcc\bin\sdcc"
+ "../bin/sdcc"
+ "/home/fish/bin/sdcc"
+
+ Note that ./sdcc is explicitly not supported as there isn't
+ enough information.
+ */
+ /* bindir is handled differently to the lib and include directories.
+ It's rather unfortunate, but required due to the different
+ install and development layouts. Logic is different as well.
+ Sigh.
+ */
+ if (strchr (argv0, DIR_SEPARATOR_CHAR))
+ {
+ strcpy (scratchFileName, argv0);
+ *strrchr (scratchFileName, DIR_SEPARATOR_CHAR) = '\0';
+ setMainValue ("bindir", scratchFileName);
+ ExePathList[0] = Safe_strdup (scratchFileName);
+ }
+ else if (getenv (SDCCDIR_NAME) != NULL)
+ {
+ getPathDifference (buffer, PREFIX, BINDIR);
+ strcpy (scratchFileName, getenv (SDCCDIR_NAME));
+ strcat (scratchFileName, buffer);
+ setMainValue ("bindir", scratchFileName);
+ ExePathList[0] = Safe_strdup (scratchFileName);
+ }
+ else
+ {
+ setMainValue ("bindir", BINDIR);
+ ExePathList[0] = BINDIR;
+ }
+
+ do
+ {
+ /* Case 1 */
+ if (getenv (SDCCDIR_NAME) != NULL)
+ {
+ if (_setPaths (getenv (SDCCDIR_NAME)))
+ {
+ /* Successfully set. */
+ break;
+ }
+ else
+ {
+ /* Include and lib weren't where expected. */
+ }
+ }
+ /* Case 2 */
+ if (strchr (argv0, DIR_SEPARATOR_CHAR))
+ {
+ char *pbase = getPrefixFromBinPath (argv0);
+
+ if (pbase == NULL)
+ {
+ /* A bad path. Skip. */
+ }
+ else
+ {
+ if (_setPaths (pbase))
+ {
+ /* Successfully set. */
+ break;
+ }
+ else
+ {
+ /* Include and lib weren't where expected. */
+ }
+ }
+ }
+ /* Case 3 */
+ setMainValue ("includedir", SDCC_INCLUDE_DIR);
+ setMainValue ("libdir", SDCC_LIB_DIR);
+ } while (0);
+}
+
+static void
+initValues (void)
+{
+ populateMainValues (_baseValues);
+ setMainValue ("port", port->target);
+ setMainValue ("objext", port->linker.rel_ext);
+ setMainValue ("asmext", port->assembler.file_ext);
+
+ setMainValue ("fullsrcfilename", fullSrcFileName ? fullSrcFileName : "fullsrcfilename");
+ setMainValue ("srcfilename", srcFileName ? srcFileName : "srcfilename");