Skip to content

Commit 6ba5ea0

Browse files
Christian JullienEli-Zaretskii
authored andcommitted
Add support for building with Tiny C for MS-Windows
* src/config.h.W32.template (HAVE_DIRECT_H, HAVE_STRCASECMP) (HAVE_STRNCASECMP, HAVE_UMASK): Add __TINYC__ to MinGW condition. (BATCH_MODE_ONLY_SHELL): Make this the default for Tiny C. * build_w32.bat: Support building with Tiny C's tcc compiler.
1 parent 4533348 commit 6ba5ea0

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

build_w32.bat

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set COMPILER=cl.exe
3737
set O=obj
3838
set ARCH=x64
3939
set DEBUG=N
40+
set DIRENT=Y
4041

4142
if exist maintMakefile (
4243
set MAINT=Y
@@ -49,6 +50,7 @@ if "%1" == "--debug" goto SetDebug
4950
if "%1" == "--without-guile" goto NoGuile
5051
if "%1" == "--x86" goto Set32Bit
5152
if "%1" == "gcc" goto SetCC
53+
if "%1" == "tcc" goto SetTCC
5254
if "%1" == "" goto DoneSW
5355
goto Usage
5456

@@ -77,10 +79,18 @@ echo - Building with GCC
7779
shift
7880
goto ParseSW
7981

82+
:SetTCC
83+
set COMPILER=tcc
84+
set O=o
85+
echo - Building with TinyC
86+
shift
87+
goto ParseSW
88+
8089
:DoneSW
8190
if "%MAINT%" == "Y" echo - Enabling maintainer mode
8291

8392
if "%COMPILER%" == "gcc" goto FindGcc
93+
if "%COMPILER%" == "tcc" goto FindTcc
8494

8595
:: Find a compiler. Visual Studio requires a lot of effort to locate :-/.
8696
%COMPILER% >nul 2>&1
@@ -172,6 +182,7 @@ goto Build
172182
set OUTDIR=.\GccRel
173183
set LNKOUT=./GccRel
174184
set OPTS=-O2
185+
set DIRENT=N
175186
if "%DEBUG%" == "Y" set OPTS=-O0
176187
if "%DEBUG%" == "Y" set OUTDIR=.\GccDebug
177188
if "%DEBUG%" == "Y" set LNKOUT=./GccDebug
@@ -183,6 +194,21 @@ if not ERRORLEVEL 1 goto Build
183194
echo No %COMPILER% found.
184195
exit 1
185196

197+
:FindTcc
198+
set OUTDIR=.\TccRel
199+
set LNKOUT=./TccRel
200+
set OPTS=-O2
201+
if "%DEBUG%" == "Y" set OPTS=-O0
202+
if "%DEBUG%" == "Y" set OUTDIR=.\TccDebug
203+
if "%DEBUG%" == "Y" set LNKOUT=./TccDebug
204+
if "%MAINT%" == "Y" set "OPTS=%OPTS% -DMAKE_MAINTAINER_MODE"
205+
:: Show the compiler version that we found
206+
echo.
207+
%COMPILER% -v
208+
if not ERRORLEVEL 1 goto Build
209+
echo No %COMPILER% found.
210+
exit 1
211+
186212
:Build
187213
:: Clean the directory if it exists
188214
if exist %OUTDIR%\nul rmdir /S /Q %OUTDIR%
@@ -246,7 +272,8 @@ call :Compile lib/fnmatch
246272
call :Compile lib/glob
247273
call :Compile lib/getloadavg
248274

249-
if not "%COMPILER%" == "gcc" call :Compile src\w32\compat\dirent
275+
:: Compile dirent unless it is supported by compiler library (like with gcc).
276+
if "%DIRENT%" == "Y" call :Compile src\w32\compat\dirent
250277

251278
call :Link
252279

@@ -272,6 +299,7 @@ set EXTRAS=
272299
if "%2" == "GUILE" set "EXTRAS=%GUILECFLAGS%"
273300
if exist "%OUTDIR%\%1.%O%" del "%OUTDIR%\%1.%O%"
274301
if "%COMPILER%" == "gcc" goto GccCompile
302+
if "%COMPILER%" == "tcc" goto TccCompile
275303

276304
:: MSVC Compile
277305
echo on
@@ -284,6 +312,14 @@ goto CompileDone
284312
echo on
285313
%COMPILER% -mthreads -Wall -std=gnu99 -gdwarf-2 -g3 %OPTS% -I%OUTDIR%/src -I./src -I%OUTDIR%/lib -I./lib -I./src/w32/include -DWINDOWS32 -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%/%1.%O% -c %1.c
286314
@echo off
315+
goto CompileDone
316+
317+
:TccCompile
318+
:: TCC Compile
319+
echo on
320+
%COMPILER% -mthreads -Wall -std=c11 %OPTS% -I%OUTDIR%/src -I./src -I%OUTDIR%/lib -I./lib -I./src/w32/include -D_cdecl= -D_MSC_VER -DWINDOWS32 -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%/%1.%O% -c %1.c
321+
@echo off
322+
goto CompileDone
287323

288324
:CompileDone
289325
if not exist "%OUTDIR%\%1.%O%" exit 1
@@ -293,6 +329,7 @@ goto :EOF
293329
echo.
294330
echo Linking %LNKOUT%/%MAKE%.exe
295331
if "%COMPILER%" == "gcc" goto GccLink
332+
if "%COMPILER%" == "tcc" goto TccLink
296333

297334
:: MSVC Link
298335
echo %GUILELIBS% kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib >>%OUTDIR%\link.sc
@@ -309,6 +346,14 @@ echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -l
309346
@echo off
310347
goto :EOF
311348

349+
:TccLink
350+
:: TCC Link
351+
echo on
352+
echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc
353+
%COMPILER% -mthreads %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc
354+
@echo off
355+
goto :EOF
356+
312357
:ConfigSCM
313358
echo Generating config from SCM templates
314359
sed -n "s/^AC_INIT(\[GNU make\],\[\([^]]\+\)\].*/s,%%VERSION%%,\1,g/p" configure.ac > %OUTDIR%\src\config.h.W32.sed
@@ -375,12 +420,14 @@ if ERRORLEVEL 1 exit /b 1
375420
goto :EOF
376421

377422
:Usage
378-
echo Usage: %0 [options] [gcc]
423+
echo Usage: %0 [options] [gcc] OR [tcc]
379424
echo Options:
380425
echo. --without-guile Do not compile Guile support even if found
381426
echo. --debug Make a Debug build--default is Release
382427
echo. --x86 Make a 32bit binary--default is 64bit
383428
echo. --help Display these instructions and exit
429+
echo.
430+
echo. "gcc" means compile with GCC, "tcc" means compile with Tiny C's TCC
384431
goto :EOF
385432

386433
:Reset

src/config.h.W32.template

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
102102
/* Define to 1 if you have the <direct.h> header file, and it defines getcwd()
103103
and chdir().
104104
*/
105-
#if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(__INTERIX)
105+
#if (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__TINYC__)) && !defined(__INTERIX)
106106
# define HAVE_DIRECT_H 1
107107
#endif
108108

@@ -247,7 +247,7 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
247247
#define HAVE_STDLIB_H 1
248248

249249
/* Define to 1 if you have the 'strcasecmp' function. */
250-
#ifdef __MINGW32__
250+
#if defined(__MINGW32__) || defined(__TINYC__)
251251
#define HAVE_STRCASECMP 1
252252
#endif
253253

@@ -273,7 +273,7 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
273273
#define HAVE_STRING_H 1
274274

275275
/* Define to 1 if you have the 'strncasecmp' function. */
276-
#ifdef __MINGW32__
276+
#if defined(__MINGW32__) || defined(__TINYC__)
277277
#define HAVE_STRNCASECMP 1
278278
#endif
279279

@@ -305,7 +305,7 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
305305
char *ttyname (int);
306306

307307
/* Define to 1 if you have the `umask' function. */
308-
#ifdef __MINGW32__
308+
#if defined(__MINGW32__) || defined(__TINYC__)
309309
# define HAVE_UMASK 1
310310
#endif
311311

@@ -525,10 +525,14 @@ char *ttyname (int);
525525

526526
/*
527527
* If you have a shell that does not grok 'sh -c quoted-command-line'
528-
* correctly, you need this setting. Please see below for specific
529-
* shell support.
528+
* correctly, you need this setting; it is the default for tcc.
529+
* Please see below for specific shell support.
530530
*/
531+
#if defined(__TINYC__)
532+
#define BATCH_MODE_ONLY_SHELL 1
533+
#else
531534
/*#define BATCH_MODE_ONLY_SHELL 1 */
535+
#endif
532536

533537
/*
534538
* Define if you have the Cygnus "Cygwin" GNU Windows32 tool set.

0 commit comments

Comments
 (0)