- 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);
+ if ((p = getenv(SDCC_INCLUDE_NAME)) != NULL)
+ addSetHead(&includeDirsSet, p);
+
+ if (options.printSearchDirs) {
+ printf("includedir:\n");
+ fputStrSet(stdout, includeDirsSet);
+ }
+}
+
+/* Set system lib path */
+static void
+setLibPath(void)
+{
+ char *p;
+
+ /*
+ * Search logic:
+ *
+ * 1. - $SDCC_LIB
+ * 2. - $SDCC_HOME/PREFIX2DATA_DIR/LIB_DIR_SUFFIX/<model>
+ * 3. - path(argv[0])/BIN2DATA_DIR/LIB_DIR_SUFFIX/<model>
+ * 4. - DATADIR/LIB_DIR_SUFFIX/<model> (only on *nix)
+ */
+
+ libDirsSet = appendStrSet(dataDirsSet, NULL, LIB_DIR_SUFFIX);
+
+ if ((p = getenv(SDCC_LIB_NAME)) != NULL)
+ addSetHead(&libDirsSet, p);
+
+ if (options.printSearchDirs) {
+ printf("libdir:\n");
+ fputStrSet(stdout, libDirsSet);
+ }
+}
+
+/* Set data path */
+static void
+setDataPaths(const char *argv0)
+{
+ char *p;
+ char buf[PATH_MAX];
+
+ /*
+ * Search logic:
+ *
+ * 1. - $SDCC_HOME/PREFIX2DATA_DIR
+ * 2. - path(argv[0])/BIN2DATA_DIR
+ * 3. - DATADIR (only on *nix)
+ */
+
+ if ((p = getenv(SDCC_DIR_NAME)) != NULL) {
+ SNPRINTF(buf, sizeof buf, "%s" PREFIX2DATA_DIR, p);
+ addSet(&dataDirsSet, Safe_strdup(buf));
+ }
+
+ if ((p = getBinPath(argv0)) != NULL) {
+ SNPRINTF(buf, sizeof buf, "%s" BIN2DATA_DIR, p);
+ addSet(&dataDirsSet, Safe_strdup(buf));
+ }
+
+#ifdef _WIN32
+ if (peekSet(dataDirsSet) == NULL) {
+ /* this should never happen... */
+ wassertl(0, "Can't get binary path");
+ }
+#else
+ addSet(&dataDirsSet, Safe_strdup(DATADIR));
+#endif
+
+ if (options.printSearchDirs) {
+ printf("datadir:\n");
+ fputStrSet(stdout, dataDirsSet);
+ }
+
+ setIncludePath();
+ setLibPath();