Skip to content

Commit

Permalink
clink.pl: move default linker options for MSVC=1 builds
Browse files Browse the repository at this point in the history
Move the default `-ENTRY` and `-SUBSYSTEM` arguments for
MSVC=1 builds from `config.mak.uname` into `clink.pl`.
These args are constant for console-mode executables.

Add support to `clink.pl` for generating a Win32 GUI application
using the `-mwindows` argument (to match how GCC does it).  This
changes the `-ENTRY` and `-SUBSYSTEM` arguments accordingly.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Sep 18, 2024
1 parent 236daaa commit 5723dd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions compat/vcbuild/scripts/clink.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
my @lflags = ();
my $is_linking = 0;
my $is_debug = 0;
my $is_gui = 0;
while (@ARGV) {
my $arg = shift @ARGV;
if ("$arg" eq "-DDEBUG") {
Expand Down Expand Up @@ -124,11 +125,21 @@
# let's ignore those
} elsif ("$arg" eq "-fno-stack-protector") {
# eat this
} elsif ("$arg" eq "-mwindows") {
$is_gui = 1;
} else {
push(@args, $arg);
}
}
if ($is_linking) {
if ($is_gui) {
push(@args, "-ENTRY:wWinMainCRTStartup");
push(@args, "-SUBSYSTEM:WINDOWS");
} else {
push(@args, "-ENTRY:wmainCRTStartup");
push(@args, "-SUBSYSTEM:CONSOLE");
}

push(@args, @lflags);
unshift(@args, "link.exe");
} else {
Expand Down
2 changes: 1 addition & 1 deletion config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ endif
compat/win32/trace2_win32_process_info.o \
compat/win32/dirent.o
COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY -DENSURE_MSYSTEM_IS_SET -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -ENTRY:wmainCRTStartup -SUBSYSTEM:CONSOLE
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO
# invalidcontinue.obj allows Git's source code to close the same file
# handle twice, or to access the osfhandle of an already-closed stdout
# See https://msdn.microsoft.com/en-us/library/ms235330.aspx
Expand Down

0 comments on commit 5723dd0

Please sign in to comment.