+ /* 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;
+ }