RE: [Tinycc-devel] I want to port make on Windows using tcc compiler

"Christian Jullien" <[email protected]> Fri, 24 Jan 2020 09:13:12 +0100
Newsgroups gmane.comp.gnu.make.windows
Organization Eligis
Message-ID <[email protected]>
This is a multipart message in MIME format.

------=_NextPart_000_0015_01D5D296.810FEE90
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Ooops, Yes DIRENT is needed. I sent you an incomplete diff. Enclosed are the
right ones. This new build_w32.bat allows both tcc and cl to compile dirent.
You can replace c11 by c99 if you like. I generally use c11 which sometimes
checks about deprecated uses.

Tcc supports loadable libraries (.dll on Windows and .so on linux). If you
never heard about tcc before, I invite you to give a try and see the
phenomenal compiler speed. It makes you think you have an interpreter which
of course dramatically boost your development cycle. It even support
on-the-fly compilation with shee-band #!/usr/local/tcc. This way you can
make shell scripts in C. Compiling a working Linux kernel is a matter of sec
(see https://github.com/seyko2/tccboot)
Execution speed of this one pass compiler is fair: 30 to 50% slower than gcc
or cl. This is my main C compiler I use daily for C devel (no C++). When
code works, I polish the binaries with cl or gcc with all possible optims
for my OpenLisp Lisp compiler. This a must have on RPi for example.
 
> Would you like me to send you the form to fill to start the legal
paperwork?

For sure, I'll be glad to do so.



-----Original Message-----
From: Eli Zaretskii [mailto:[email protected]] 
Sent: Friday, January 24, 2020 08:25
To: [email protected]; Paul Smith
Cc: [email protected]
Subject: Re: [Tinycc-devel] I want to port make on Windows using tcc
compiler

> From: "Christian Jullien" <[email protected]>
> Cc: <[email protected]>
> Date: Wed, 22 Jan 2020 20:57:37 +0100
> 
> Ok here are the patches:

Thanks.  A few questions and comments below.

>  :: Find a compiler.  Visual Studio requires a lot of effort to locate
:-/.
>  %COMPILER% >nul 2>&1
> @@ -172,6 +182,7 @@
>  set OUTDIR=.\GccRel
>  set LNKOUT=./GccRel
>  set OPTS=-O2
> +set DIRENT=N

What is this part about?  Is it needed, and if so, why?

> +:TccCompile
> +:: TCC Compile
> +echo on
> +%COMPILER% -mthreads -Wall -std=c11 %OPTS% -I%OUTDIR%/src -I./src

Why are you using -std=c11 here? this is unlike all the other
compilations, which use C99.

> +:TccLink
> +:: TCC Link
> +echo on
> +echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lcomdlg32 -ladvapi32
> -lshell32 -lole32 -loleaut32 -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc
> +%COMPILER% -mthreads %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc 

Does this build the import library?  And in general, does the tcc
build support loadable modules?

Last, but not least: a contribution this large will need you to sign
legal papers assigning the copyright to the FSF.  Would you like me to
send you the form to fill to start the legal paperwork?

Paul, any comments?  The changes look reasonable to me, FWIW.

------=_NextPart_000_0015_01D5D296.810FEE90
Content-Type: application/octet-stream;
	name="config.h.W32.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="config.h.W32.patch"

--- config.h.W32.template	2020-01-22 20:16:49.000000000 +0100=0A=
+++ config.h.W32.new	2020-01-24 08:24:06.352592200 +0100=0A=
@@ -102,7 +102,7 @@=0A=
 /* Define to 1 if you have the <direct.h> header file, and it defines =
getcwd()=0A=
    and chdir().=0A=
    */=0A=
-#if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(__INTERIX)=0A=
+#if (defined(_MSC_VER) || defined(__BORLANDC__) || defined(__TINYC__)) =
&& !defined(__INTERIX)=0A=
 # define HAVE_DIRECT_H 1=0A=
 #endif=0A=
 =0A=
@@ -247,7 +247,7 @@=0A=
 #define HAVE_STDLIB_H 1=0A=
 =0A=
 /* Define to 1 if you have the 'strcasecmp' function. */=0A=
-#ifdef __MINGW32__=0A=
+#if defined(__MINGW32__) || defined(__TINYC__)=0A=
 #define HAVE_STRCASECMP 1=0A=
 #endif=0A=
 =0A=
@@ -273,7 +273,7 @@=0A=
 #define HAVE_STRING_H 1=0A=
 =0A=
 /* Define to 1 if you have the 'strncasecmp' function. */=0A=
-#ifdef __MINGW32__=0A=
+#if defined(__MINGW32__) || defined(__TINYC__)=0A=
 #define HAVE_STRNCASECMP 1=0A=
 #endif=0A=
 =0A=
@@ -305,7 +305,7 @@=0A=
 char *ttyname (int);=0A=
 =0A=
 /* Define to 1 if you have the `umask' function. */=0A=
-#ifdef __MINGW32__=0A=
+#if defined(__MINGW32__) || defined(__TINYC__)=0A=
 # define HAVE_UMASK 1=0A=
 #endif=0A=
 =0A=
@@ -525,10 +525,14 @@=0A=
 =0A=
 /*=0A=
  * If you have a shell that does not grok 'sh -c quoted-command-line'=0A=
- * correctly, you need this setting. Please see below for specific=0A=
- * shell support.=0A=
+ * correctly, you need this setting which is the default for tcc.=0A=
+ * Please see below for specific shell support.=0A=
  */=0A=
+#if defined(__TINYC__)=0A=
+#define BATCH_MODE_ONLY_SHELL 1=0A=
+#else=0A=
 /*#define BATCH_MODE_ONLY_SHELL 1 */=0A=
+#endif=0A=
 =0A=
 /*=0A=
  * Define if you have the Cygnus "Cygwin" GNU Windows32 tool set.=0A=

------=_NextPart_000_0015_01D5D296.810FEE90
Content-Type: application/octet-stream;
	name="build_w32.bat.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="build_w32.bat.patch"

--- build_w32.bat	2020-01-03 08:11:27.000000000 +0100=0A=
+++ build_w32.bat.new	2020-01-24 08:33:19.649904400 +0100=0A=
@@ -37,6 +37,7 @@=0A=
 set O=3Dobj
 set ARCH=3Dx64
 set DEBUG=3DN
+set DIRENT=3DY
=20
 if exist maintMakefile (
     set MAINT=3DY
@@ -49,6 +50,7 @@=0A=
 if "%1" =3D=3D "--without-guile" goto NoGuile
 if "%1" =3D=3D "--x86" goto Set32Bit
 if "%1" =3D=3D "gcc" goto SetCC
+if "%1" =3D=3D "tcc" goto SetTCC
 if "%1" =3D=3D "" goto DoneSW
 goto Usage
=20
@@ -77,10 +79,18 @@=0A=
 shift
 goto ParseSW
=20
+:SetTCC
+set COMPILER=3Dtcc
+set O=3Do
+echo - Building with TinyC
+shift
+goto ParseSW
+
 :DoneSW
 if "%MAINT%" =3D=3D "Y" echo - Enabling maintainer mode
=20
 if "%COMPILER%" =3D=3D "gcc" goto FindGcc
+if "%COMPILER%" =3D=3D "tcc" goto FindTcc
=20
 :: Find a compiler.  Visual Studio requires a lot of effort to locate =
:-/.
 %COMPILER% >nul 2>&1
@@ -172,6 +182,7 @@=0A=
 set OUTDIR=3D.\GccRel
 set LNKOUT=3D./GccRel
 set OPTS=3D-O2
+set DIRENT=3DN
 if "%DEBUG%" =3D=3D "Y" set OPTS=3D-O0
 if "%DEBUG%" =3D=3D "Y" set OUTDIR=3D.\GccDebug
 if "%DEBUG%" =3D=3D "Y" set LNKOUT=3D./GccDebug
@@ -183,6 +194,21 @@=0A=
 echo No %COMPILER% found.
 exit 1
=20
+:FindTcc
+set OUTDIR=3D.\TccRel
+set LNKOUT=3D./TccRel
+set OPTS=3D-O2
+if "%DEBUG%" =3D=3D "Y" set OPTS=3D-O0
+if "%DEBUG%" =3D=3D "Y" set OUTDIR=3D.\TccDebug
+if "%DEBUG%" =3D=3D "Y" set LNKOUT=3D./TccDebug
+if "%MAINT%" =3D=3D "Y" set "OPTS=3D%OPTS% -DMAKE_MAINTAINER_MODE"
+:: Show the compiler version that we found
+echo.
+%COMPILER% -v
+if not ERRORLEVEL 1 goto Build
+echo No %COMPILER% found.
+exit 1
+
 :Build
 :: Clean the directory if it exists
 if exist %OUTDIR%\nul rmdir /S /Q %OUTDIR%
@@ -246,7 +272,8 @@=0A=
 call :Compile lib/glob
 call :Compile lib/getloadavg
=20
-if not "%COMPILER%" =3D=3D "gcc" call :Compile src\w32\compat\dirent
+:: Compile dirent unless it is supported by compiler library (like with =
gcc).
+if "%DIRENT%" =3D=3D "Y" call :Compile src\w32\compat\dirent
=20
 call :Link
=20
@@ -272,6 +299,7 @@=0A=
 if "%2" =3D=3D "GUILE" set "EXTRAS=3D%GUILECFLAGS%"
 if exist "%OUTDIR%\%1.%O%" del "%OUTDIR%\%1.%O%"
 if "%COMPILER%" =3D=3D "gcc" goto GccCompile
+if "%COMPILER%" =3D=3D "tcc" goto TccCompile
=20
 :: MSVC Compile
 echo on
@@ -284,6 +312,14 @@=0A=
 echo on
 %COMPILER% -mthreads -Wall -std=3Dgnu99 -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
 @echo off
+goto CompileDone
+
+:TccCompile
+:: TCC Compile
+echo on
+%COMPILER% -mthreads -Wall -std=3Dc11 %OPTS% -I%OUTDIR%/src -I./src =
-I%OUTDIR%/lib -I./lib -I./src/w32/include -D_cdecl=3D -D_MSC_VER =
-DWINDOWS32 -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%/%1.%O% -c %1.c
+@echo off
+goto CompileDone
=20
 :CompileDone
 if not exist "%OUTDIR%\%1.%O%" exit 1
@@ -293,6 +329,7 @@=0A=
 echo.
 echo Linking %LNKOUT%/%MAKE%.exe
 if "%COMPILER%" =3D=3D "gcc" goto GccLink
+if "%COMPILER%" =3D=3D "tcc" goto TccLink
=20
 :: MSVC Link
 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 @@=0A=
 @echo off
 goto :EOF
=20
+:TccLink
+:: TCC Link
+echo on
+echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lcomdlg32 -ladvapi32 =
-lshell32 -lole32 -loleaut32 -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc
+%COMPILER% -mthreads %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc=20
+@echo off
+goto :EOF
+
 :ConfigSCM
 echo Generating config from SCM templates
 sed -n "s/^AC_INIT(\[GNU make\],\[\([^]]\+\)\].*/s,%%VERSION%%,\1,g/p" =
configure.ac > %OUTDIR%\src\config.h.W32.sed
@@ -375,7 +420,7 @@=0A=
 goto :EOF
=20
 :Usage
-echo Usage: %0 [options] [gcc]
+echo Usage: %0 [options] [gcc|tcc]
 echo Options:
 echo.  --without-guile   Do not compile Guile support even if found
 echo.  --debug           Make a Debug build--default is Release

------=_NextPart_000_0015_01D5D296.810FEE90--