+ /* command line defined library paths if specified */
+ for (s = setFirstItem(libPathsSet); s != NULL; s = setNextItem(libPathsSet))
+ fprintf (lnkfile, "-k %s\n", s);
+
+ /* standard library path */
+ if (!options.nostdlib)
+ {
+ if (!(TARGET_IS_Z80 || TARGET_IS_GBZ80 || TARGET_IS_HC08)) /*Not for the z80, gbz80*/
+ {
+ switch (options.model)
+ {
+ case MODEL_SMALL:
+ c = "small";
+ break;
+ case MODEL_LARGE:
+ c = "large";
+ break;
+ case MODEL_FLAT24:
+ /* c = "flat24"; */
+ if (TARGET_IS_DS390)
+ {
+ c = "ds390";
+ }
+ else if (TARGET_IS_DS400)
+ {
+ c = "ds400";
+ }
+ else
+ {
+ fprintf(stderr,
+ "Add support for your FLAT24 target in %s @ line %d\n",
+ __FILE__, __LINE__);
+ exit(-1);
+ }
+ break;
+ case MODEL_PAGE0:
+ c = "xa51";
+ break;
+ default:
+ werror (W_UNKNOWN_MODEL, __FILE__, __LINE__);
+ c = "unknown";
+ break;
+ }
+ }
+ else /*for the z80, gbz80*/
+ {
+ if (TARGET_IS_HC08)
+ c = "hc08";
+ else if (TARGET_IS_Z80)
+ c = "z80";
+ else
+ c = "gbz80";
+ }
+ for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet))
+ mfprintf (lnkfile, getRuntimeVariables(), "-k %s{sep}%s\n", s, c);
+ }
+
+ /* command line defined library files if specified */
+ for (s = setFirstItem(libFilesSet); s != NULL; s = setNextItem(libFilesSet))
+ fprintf (lnkfile, "-l %s\n", s);
+
+ /* standard library files */
+ if (!options.nostdlib)
+ {
+#if !OPT_DISABLE_DS390
+ if (options.model == MODEL_FLAT24)
+ {
+ if (TARGET_IS_DS390)
+ {
+ fprintf (lnkfile, "-l %s\n", STD_DS390_LIB);
+ }
+ else if (TARGET_IS_DS400)
+ {
+ fprintf (lnkfile, "-l %s\n", STD_DS400_LIB);
+ }
+ else
+ {
+ fprintf(stderr,
+ "Add support for your FLAT24 target in %s @ line %d\n",
+ __FILE__, __LINE__);
+ exit(-1);
+ }
+ }
+#endif
+
+#if !OPT_DISABLE_XA51
+#ifdef STD_XA51_LIB
+ if (options.model == MODEL_PAGE0)
+ {
+ fprintf (lnkfile, "-l %s\n", STD_XA51_LIB);
+ }
+#endif
+#endif
+ if (TARGET_IS_MCS51)
+ {
+ fprintf (lnkfile, "-l mcs51\n");
+ }
+ if (!(TARGET_IS_Z80 || TARGET_IS_GBZ80
+ || TARGET_IS_HC08)) /*Not for the z80, gbz80*/
+ { /*Why the z80 port is not using the standard libraries?*/
+ fprintf (lnkfile, "-l %s\n", STD_LIB);
+ fprintf (lnkfile, "-l %s\n", STD_INT_LIB);
+ fprintf (lnkfile, "-l %s\n", STD_LONG_LIB);
+ fprintf (lnkfile, "-l %s\n", STD_FP_LIB);
+ }
+ else if (TARGET_IS_HC08)
+ {
+ fprintf (lnkfile, "-l hc08\n");
+ }
+ else if (TARGET_IS_Z80)
+ {
+ fprintf (lnkfile, "-l z80\n");
+ }
+ else if (TARGET_IS_GBZ80)
+ {
+ fprintf (lnkfile, "-l gbz80\n");
+ }
+ }
+
+ /*For the z80 and gbz80 ports, try to find where crt0.o is...
+ It is very important for this file to be first on the linking proccess
+ so the areas are set in the correct order, expecially _GSINIT*/
+ if ((TARGET_IS_Z80 || TARGET_IS_GBZ80) &&
+ !options.no_std_crt0 && !options.nostdlib) /*For the z80, gbz80*/
+ {
+ char crt0path[PATH_MAX];
+ FILE * crt0fp;
+ for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet))
+ {
+ sprintf (crt0path, "%s%s%s%scrt0.o",
+ s, DIR_SEPARATOR_STRING, c, DIR_SEPARATOR_STRING);
+
+ crt0fp=fopen(crt0path, "r");
+ if(crt0fp!=NULL)/*Found it!*/
+ {
+ fclose(crt0fp);
+ #ifdef __CYGWIN__
+ {
+ /*The CYGWIN version of the z80-gbz80 linker is getting confused with
+ windows paths, so convert them to the CYGWIN format*/
+ char posix_path[PATH_MAX];
+ void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
+ cygwin_conv_to_full_posix_path(crt0path, posix_path);
+ strcpy(crt0path, posix_path);
+ }
+ #endif
+ fprintf (lnkfile, "%s\n", crt0path);
+ break;
+ }
+ }
+ if(s==NULL) fprintf (stderr, "Warning: couldn't find crt0.o\n");
+ }
+
+ /* put in the object files */
+ if (fullSrcFileName)
+ fprintf (lnkfile, "%s%s\n", dstFileName, port->linker.rel_ext);
+
+ fputStrSet(lnkfile, relFilesSet);
+
+ fprintf (lnkfile, "\n-e\n");
+ fclose (lnkfile);
+ } /* if(port->linker.needLinkerScript) */