Commit 58e35af3 authored by John van Groningen's avatar John van Groningen
Browse files

use temporary file for optimising linker output file, use mkstemp

to prevent warnings from gcc and linker, don't start compiler if
no modules have to be compiled
parent 40f726b0
......@@ -347,13 +347,7 @@ int dos_exec (char *file_name,char **args,int use_temp_file)
#if defined (_WINDOWS_) || defined (OS2)
temp_file_name="param.$$$";
#else
temp_file_name=tempnam (NULL,"param");
#endif
if (temp_file_name==NULL)
return 1;
#ifdef OMF
# ifdef OMF
{
char *p;
......@@ -361,13 +355,23 @@ int dos_exec (char *file_name,char **args,int use_temp_file)
if (*p=='/')
*p='\\';
}
#endif
# endif
temp_file=fopen (temp_file_name,"w");
if (temp_file==NULL){
free (temp_file_name);
#else
{
static char param_tmp_file_name[]="/tmp/paramXXXXXX";
int temp_file_fd;
temp_file_fd=mkstemp (param_tmp_file_name);
if (temp_file_fd<0)
return 1;
temp_file_name=param_tmp_file_name;
temp_file=fdopen (temp_file_fd,"w");
}
# endif
if (temp_file==NULL)
return 1;
++args;
while (*args!=NULL){
......@@ -393,7 +397,6 @@ int dos_exec (char *file_name,char **args,int use_temp_file)
}
if (fclose (temp_file)!=0){
free (temp_file_name);
return 1;
}
......@@ -402,8 +405,6 @@ int dos_exec (char *file_name,char **args,int use_temp_file)
unlink (temp_file_name);
free (temp_file_name);
return r;
}
}
......@@ -1747,18 +1748,22 @@ static char *arg_v_to_arguments (char **argv)
#endif
#define CACHING_COMPILER
#ifdef CACHING_COMPILER
#include "Clean.h"
#include "cachingcompiler.h"
static int compiler_started=0;
static void start_compiler (void)
{
int r;
char cocl_file_name[PATH_NAME_STRING_SIZE];
strcpy (cocl_file_name,clean_lib_path);
strcpy (cocl_file_name,clean_lib_path);
strcat (cocl_file_name,"/cocl");
r=start_caching_compiler ((unsigned char *)cocl_file_name);
if (r < 0)
exit(r);
......@@ -1829,6 +1834,11 @@ static int call_compiler (char *cocl_file_name, char **argv)
int r;
char *args;
if (!compiler_started){
start_compiler();
compiler_started=1;
}
args=concatenate_args(argv);
if (args != NULL)
{
......@@ -2838,13 +2848,8 @@ int create_options_file (char **options_file_name_p)
#if defined (_WINDOWS_) || defined (OS2)
options_file_name="cgopt.$$$";
#else
options_file_name=tempnam (NULL,"cgopt");
#endif
if (options_file_name==NULL)
return 0;
#ifdef OMF
# ifdef OMF
{
char *p;
......@@ -2852,9 +2857,23 @@ int create_options_file (char **options_file_name_p)
if (*p=='/')
*p='\\';
}
#endif
# endif
f=fopen (options_file_name,"wb");
#else
{
static char cgopt_file_name[]="/tmp/cgoptXXXXXX";
int options_fd;
options_fd=mkstemp (cgopt_file_name);
if (options_fd<0)
return 0;
options_file_name=cgopt_file_name;
f=fdopen (options_fd,"wb");
}
#endif
if (f==NULL)
error_s ("Can't create options file %s",options_file_name);
......@@ -3038,6 +3057,10 @@ static int add_stack_and_size_resource_to_application (char *application_file_na
extern int link_application_argc_argv (int,char **);
#endif
#ifdef OPTIMISE_LINK
static char *linker_output_object_file_name;
#endif
#ifdef USE_TOOLSERVER
static char *append_string (char *s1,char *s2)
......@@ -3074,9 +3097,7 @@ static int link_project_toolserver (P_NODE first_project_node,char *options_file
if (application_file_name!=NULL){
p=append_string (p,application_file_name);
/* p=append_string (p,".xcoff"); */
} else
/* p=append_string (p,"\'hd:desktop folder:a.xcoff\'"); */
p=append_string (p,"\'hd:desktop folder:a\'");
*p++=' ';
......@@ -3104,17 +3125,13 @@ static int link_project_toolserver (P_NODE first_project_node,char *options_file
}
p=append_string (p,
/* " \'Applications:MPW:Libraries:PPCLibraries:InterfaceLib.xcoff\'" */
" \'Applications:MPW:Libraries:SharedLibraries:InterfaceLib\'"
" \'Applications:MPW:Libraries:PPCLibraries:MathLib.xcoff\'"
/* " \'Applications:MPW:Libraries:PPCLibraries:StdCLib.xcoff\'" */
" \'Applications:MPW:Libraries:SharedLibraries:StdCLib\'"
" \'Applications:MPW:Libraries:PPCLibraries:StdCRuntime.o\'"
" \'Applications:MPW:Libraries:PPCLibraries:PPCCRuntime.o\'"
# if !USE_METROWERKS_LINKER
/* " -librename InterfaceLib.xcoff=InterfaceLib" */
" -librename MathLib.xcoff=MathLib"
/* " -librename StdCLib.xcoff=StdCLib" */
# endif
" -main __start");
......@@ -3205,14 +3222,27 @@ static int link_project (P_NODE first_project_node,char *options_file_name,char
if (!silent)
printf ("Linking %s\n",main_project_node->pro_fname);
# ifdef OPTIMISE_LINK
{
static char linker_output_file_name[]="/tmp/linkerXXXXXX";
int linker_output_fd;
linker_output_fd=mkstemp (linker_output_file_name);
if (linker_output_fd<0){
error_s ("Can't create %s",linker_output_file_name);
return 0;
}
close (linker_output_fd);
linker_output_object_file_name=linker_output_file_name;
}
# ifdef OPTIMISE_LINK
arg=argv;
*arg++="linker";
*arg++=linker_output_object_file_name;
"a.o";
# if !(!defined (LINUX) && defined (SOLARIS))
need_file ("_startup",OBJECT_FILE_EXTENSION,start_up_file_name);
# endif
......@@ -3280,9 +3310,6 @@ static int link_project (P_NODE first_project_node,char *options_file_name,char
return 0;
}
# endif
arg=argv;
......@@ -3415,7 +3442,7 @@ static int link_project (P_NODE first_project_node,char *options_file_name,char
# endif
# ifdef OPTIMISE_LINK
*arg++ = "a.o";
*arg++ = linker_output_object_file_name;
# else
# if (defined (_WINDOWS_) && !defined (USE_WLINK)) || defined (OMF)
# ifdef NO_CLIB
......@@ -3710,6 +3737,11 @@ static int link_project (P_NODE first_project_node,char *options_file_name,char
}
r=wait_for_child (pid, "Linker",&status);
# ifdef OPTIMISE_LINK
unlink (linker_output_object_file_name);
# endif
return r>=0 && status==0;
}
# endif
......@@ -4389,17 +4421,16 @@ int main (int argc,char **argv)
#endif
#ifdef CACHING_COMPILER
start_compiler ();
#endif
if (make_project_to_abc_files (first_project_node)
#ifdef NB
&& make_project_to_abc_files (_system_pnode)
#endif
){
#ifdef CACHING_COMPILER
stop_compiler ();
if (compiler_started){
stop_compiler();
compiler_started=0;
}
#endif
if (only_abc_files || syntax_check)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment