- copyFile (asmFile, statsg->oFile);
- if (port->general.glue_up_main)
- fprintf (asmFile,"\tljmp\t__sdcc_program_startup\n");
-
- /* copy over code */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; code\n");
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "\t.area %s\n", port->mem.code_name);
- if (mainf && mainf->fbody) {
-
- /* entry point @ start of CSEG */
- fprintf (asmFile,"__sdcc_program_startup:\n");
-
- /* put in the call to main */
- fprintf(asmFile,"\tlcall\t_main\n");
- if (options.mainreturn) {
-
- fprintf(asmFile,";\treturn from main ; will return to caller\n");
- fprintf(asmFile,"\tret\n");
-
- } else {
-
- fprintf(asmFile,";\treturn from main will lock up\n");
- fprintf(asmFile,"\tsjmp .\n");
+ copyFile (asmFile, statsg->oFile);
+
+ if (port->general.glue_up_main && mainf && mainf->fbody)
+ {
+ /* This code is generated in the post-static area.
+ * This area is guaranteed to follow the static area
+ * by the ugly shucking and jiving about 20 lines ago.
+ */
+ tfprintf (asmFile, "\t!area\n", port->mem.post_static_name);
+ fprintf (asmFile, "\tljmp\t__sdcc_program_startup\n");
+ }
+
+ fprintf (asmFile,
+ "%s"
+ "; Home\n"
+ "%s", iComments2, iComments2);
+ tfprintf (asmFile, "\t!areahome\n", HOME_NAME);
+ copyFile (asmFile, home->oFile);
+
+ /* copy over code */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; code\n");
+ fprintf (asmFile, "%s", iComments2);
+ tfprintf (asmFile, "\t!areacode\n", CODE_NAME);
+ if (mainf && mainf->fbody)
+ {
+
+ /* entry point @ start of CSEG */
+ fprintf (asmFile, "__sdcc_program_startup:\n");
+
+ /* put in the call to main */
+ fprintf (asmFile, "\tlcall\t_main\n");
+ if (options.mainreturn)
+ {
+
+ fprintf (asmFile, ";\treturn from main ; will return to caller\n");
+ fprintf (asmFile, "\tret\n");
+
+ }
+ else
+ {
+
+ fprintf (asmFile, ";\treturn from main will lock up\n");
+ fprintf (asmFile, "\tsjmp .\n");
+ }
+ }
+ copyFile (asmFile, code->oFile);
+
+ fclose (asmFile);
+ applyToSet (tmpfileSet, closeTmpFiles);
+ applyToSet (tmpfileNameSet, rmTmpFiles);
+}
+
+/** Creates a temporary file a'la tmpfile which avoids the bugs
+ in cygwin wrt c:\tmp.
+ Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
+*/
+FILE *
+tempfile (void)
+{
+#if !defined(_MSC_VER)
+ const char *tmpdir = NULL;
+ if (getenv ("TMP"))
+ tmpdir = getenv ("TMP");
+ else if (getenv ("TEMP"))
+ tmpdir = getenv ("TEMP");
+ else if (getenv ("TMPDIR"))
+ tmpdir = getenv ("TMPDIR");
+ if (tmpdir)
+ {
+ char *name = tempnam (tmpdir, "sdcc");
+ if (name)
+ {
+ FILE *fp = fopen (name, "w+b");
+ if (fp)
+ {
+ addSetHead (&tmpfileNameSet, name);
+ }
+ return fp;