Skip to content
Snippets Groups Projects
Commit 6cb75887 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Build a console .com and Windows .exe file and shared DLL

This allows running syncterm from cmd.exe using just "syncterm"
to run in console mode, but using the .exe to run in Windows mode.

It should now be possible to run SyncTERM in ANSI or console mode
inside of SyncTERM in GDI mode.
parent 38b2cefb
No related branches found
No related tags found
No related merge requests found
Pipeline #7625 passed
......@@ -351,7 +351,7 @@ else
EXEFILE :=
endif
endif
ifeq ($(os),win32)
ifdef win
SOFILE := .dll
else
SOFILE := .so
......
......@@ -40,13 +40,14 @@ else
endif
ifdef win
CFLAGS += -I${3RDP_ROOT}/win32.release/libjxl/include -DJXL_THREADS_STATIC_DEFINE -DJXL_STATIC_DEFINE
CFLAGS += -I${3RDP_ROOT}/win32.release/libjxl/include -DJXL_THREADS_STATIC_DEFINE -DJXL_STATIC_DEFINE -DDLLIFY
LDFLAGS += -L${3RDP_ROOT}/${os}.release/libjxl/lib -static-libstdc++ -static-libgcc
EXTRA_LIBS += -ljxl
EXTRA_LIBS += -ljxl_threads
EXTRA_LIBS += -lbrotlidec
EXTRA_LIBS += -lbrotlicommon
EXTRA_LIBS += -lhwy
EXTRA_LIBS += -mdll
CFLAGS += -DWITH_JPEG_XL -DWITH_STATIC_JXL
CFLAGS += -DWITH_JPEG_XL_THREADS
OBJS += $(MTOBJODIR)$(DIRSEP)libjxl$(OFILE)
......@@ -157,6 +158,10 @@ $(MTOBJODIR)$(DIRSEP)ciolib_res$(OFILE): ${CIOLIB-MT}
$(SYNCTERM): $(CRYPT_DEPS) $(EXEODIR) $(OBJS) $(BUILD_DEPENDS)
@echo Linking $@
${QUIET}$(CXX) $(LDFLAGS) $(MT_LDFLAGS) $(OBJS) -o $@ $(UIFC-MT_LIBS) $(EXTRA_LIBS) $(CIOLIB-MT_LIBS) $(XPDEV-MT_LIBS) $(ENCODE_LIBS) $(HASH_LIBS)
ifdef win
${QUIET}$(CXX) $(LDFLAGS) $(MT_LDFLAGS) win32_stub.c -o $(EXEODIR)/syncterm.exe -L$(EXEODIR) -lsyncterm -mwindows
${QUIET}$(CXX) $(LDFLAGS) $(MT_LDFLAGS) win32_stub.c -o $(EXEODIR)/syncterm.com -L$(EXEODIR) -lsyncterm -mconsole
endif
ifeq ($(os),darwin)
-${QUIET}mkdir $(EXEODIR)/SyncTERM.app
-${QUIET}mkdir $(EXEODIR)/SyncTERM.app/Contents
......
......@@ -2328,3 +2328,43 @@ ciolib_to_screen(int ciolib)
}
return SCREEN_MODE_CURRENT;
}
#if defined(_WIN32) && defined(DLLIFY)
__declspec(dllexport) int __cdecl stub_main(int argc, char *argv[], char **env)
{
int n;
char *bufp, *appname;
/* Get the class name from argv[0] */
appname = argv[0];
if ( (bufp=strrchr(argv[0], '\\')) != NULL ) {
appname = bufp+1;
} else
if ( (bufp=strrchr(argv[0], '/')) != NULL ) {
appname = bufp+1;
}
if ( (bufp=strrchr(appname, '.')) == NULL )
n = strlen(appname);
else
n = (bufp-appname);
bufp = (char *)alloca(n+1);
if ( bufp == NULL ) {
return 1;
}
strncpy(bufp, appname, n);
bufp[n] = '\0';
ciolib_appname = bufp;
/* Run the application main() code */
n=CIOLIB_main(argc, argv);
/* Exit cleanly, calling atexit() functions */
exit(n);
/* Hush little compiler, don't you cry... */
return(n);
}
#endif
ifdef win
SYNCTERM = $(EXEODIR)$(DIRSEP)syncterm$(SOFILE)
else
SYNCTERM = $(EXEODIR)$(DIRSEP)syncterm$(EXEFILE)
endif
all: xpdev-mt ciolib-mt uifc-mt sftp-mt $(MTOBJODIR) $(EXEODIR) $(SYNCTERM)
......
/*
SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98
The WinMain function -- calls your program's main() function
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <malloc.h> /* For _alloca() */
#include <direct.h>
extern "C" {
__declspec(dllimport) int __cdecl stub_main(int, char **, char **);
}
/* Parse a command line buffer into arguments */
static int ParseCommandLine(char *cmdline, char **argv)
{
char *bufp;
int argc;
argc = 0;
for ( bufp = cmdline; *bufp; ) {
/* Skip leading whitespace */
while ( isspace(*bufp) ) {
++bufp;
}
/* Skip over argument */
if ( *bufp == '"' ) {
++bufp;
if ( *bufp ) {
if ( argv ) {
argv[argc] = bufp;
}
++argc;
}
/* Skip over word */
while ( *bufp && (*bufp != '"') ) {
++bufp;
}
} else {
if ( *bufp ) {
if ( argv ) {
argv[argc] = bufp;
}
++argc;
}
/* Skip over word */
while ( *bufp && ! isspace(*bufp) ) {
++bufp;
}
}
if ( *bufp ) {
if ( argv ) {
*bufp = '\0';
}
++bufp;
}
}
if ( argv ) {
argv[argc] = NULL;
}
return(argc);
}
HINSTANCE WinMainHInst;
/* This is where execution begins [windowed apps] */
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
HINSTANCE handle;
char **argv;
int argc;
char *cmdline;
char *bufp;
WinMainHInst = hInst;
/* Start up DDHELP.EXE before opening any files, so DDHELP doesn't
keep them open. This is a hack.. hopefully it will be fixed
someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
*/
handle = LoadLibrary(TEXT("DDRAW.DLL"));
if ( handle != NULL ) {
FreeLibrary(handle);
}
/* Grab the command line (use alloca() on Windows) */
bufp = GetCommandLine();
cmdline = (char *)alloca(strlen(bufp)+1);
if ( cmdline == NULL ) {
return 1;
}
strcpy(cmdline, bufp);
/* Parse it into argv and argc */
argc = ParseCommandLine(cmdline, NULL);
argv = (char **)alloca((argc+1)*(sizeof *argv));
if ( argv == NULL ) {
return 1;
}
ParseCommandLine(cmdline, argv);
/* Run the main program (after a little SDL initialization) */
return(stub_main(argc, argv, _environ));
}
int main(int argc, char **argv, char **e)
{
return(stub_main(argc, argv, e));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment