I'm not advocating for it to be added to the wiki, but here is how to change the default output file extension for the gcc.
Open up binutils-X.XX/ld/ldmain.c and search for
Code:
If the --force-exe-suffix is enabled, and we're making
It should be around line 450. Just below this, you'll see:
Code:
if (! link_info.relocatable && command_line.force_exe_suffix)
Remove the "&& command_line.force_exe_suffix" part. I also use a custom file extension for relocatable files, so I just change this entire statement to "if (1)". Then, shortly below this you'll see:
Code:
if (len < 4
|| (strcasecmp (output_filename + len - 4, ".exe") != 0
&& strcasecmp (output_filename + len - 4, ".dll") != 0))
and
Code:
strcat (dst_name, ".exe");
Change the extensions here to what you want. A tip, if you want shared object files to have a specific extension, there is a value called "link_info.shared" that you can check. eg. Mine is set up like:
Code:
if (!link_info.shared)
{
if (!link_info.relocatable)
strcat (dst_name, ".eo");
else
strcat (dst_name, ".ro");
}
else
strcat (dst_name, ".so");
Next, open binutils-X.XX/ld/emultempl/elf32.em and search for
Code:
gld${EMULATION_NAME}_before_parse
In this function, add the line:
Code:
output_filename = "${EXECUTABLE_NAME:-a.exe}";
changing ".exe" to whatever your executable file extension is.
Lastly, before you configure gcc, do:
Code:
export CFLAGS=-DTARGET_EXECUTABLE_SUFFIX='".exe"'
export CXXFLAGS=$CFLAGS
again replacing ".exe" with your executable suffix. GCC will only add this suffix if the output file doesn't have one, but LD will force it to have one. So if you output a file with an invalid extension, like "-o test.derp", you will actually get 2 output files, "test.derp" (from GCC) and "test.derp.exe". (from LD)
-----------------
Note: Be sure to adjust the len appropriately if you're using a file extension that is longer or shorter than 4 characters. eg.Code:
if (len < 4
|| (strcasecmp (output_filename + len - 4, ".exe") != 0
&& strcasecmp (output_filename + len - 4, ".dll") != 0))
and
Code:
char *dst_name = (char *) xmalloc (len + 5);
in mine are
Code:
if (len < 3
|| (strcasecmp (output_filename + len - 3, ".eo") != 0
&& strcasecmp (output_filename + len - 3, ".ro") != 0
&& strcasecmp (output_filename + len - 3, ".so") != 0))
and
Code:
char *dst_name = (char *) xmalloc (len + 4);