build-tcc.bat 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. @rem ------------------------------------------------------
  2. @rem batch file to build tcc using mingw, msvc or tcc itself
  3. @rem ------------------------------------------------------
  4. @echo off
  5. setlocal
  6. if (%1)==(-clean) goto :cleanup
  7. set CC=gcc
  8. set /p VERSION= < ..\VERSION
  9. set INST=
  10. set BIN=
  11. set DOC=no
  12. set EXES_ONLY=no
  13. goto :a0
  14. :a2
  15. shift
  16. :a3
  17. shift
  18. :a0
  19. if not (%1)==(-c) goto :a1
  20. set CC=%~2
  21. if (%2)==(cl) set CC=@call :cl
  22. goto :a2
  23. :a1
  24. if (%1)==(-t) set T=%2&& goto :a2
  25. if (%1)==(-v) set VERSION=%~2&& goto :a2
  26. if (%1)==(-i) set INST=%2&& goto :a2
  27. if (%1)==(-b) set BIN=%2&& goto :a2
  28. if (%1)==(-d) set DOC=yes&& goto :a3
  29. if (%1)==(-x) set EXES_ONLY=yes&& goto :a3
  30. if (%1)==() goto :p1
  31. :usage
  32. echo usage: build-tcc.bat [ options ... ]
  33. echo options:
  34. echo -c prog use prog (gcc/tcc/cl) to compile tcc
  35. echo -c "prog options" use prog with options to compile tcc
  36. echo -t 32/64 force 32/64 bit default target
  37. echo -v "version" set tcc version
  38. echo -i tccdir install tcc into tccdir
  39. echo -b bindir optionally install binaries into bindir elsewhere
  40. echo -d create tcc-doc.html too (needs makeinfo)
  41. echo -x just create the executables
  42. echo -clean delete all previously produced files and directories
  43. exit /B 1
  44. @rem ------------------------------------------------------
  45. @rem sub-routines
  46. :cleanup
  47. set LOG=echo
  48. %LOG% removing files:
  49. for %%f in (*tcc.exe libtcc.dll lib\*.a) do call :del_file %%f
  50. for %%f in (..\config.h ..\config.texi) do call :del_file %%f
  51. for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f
  52. for %%f in (include\tcclib.h examples\libtcc_test.c) do call :del_file %%f
  53. for %%f in (*.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f
  54. %LOG% removing directories:
  55. for %%f in (doc libtcc) do call :del_dir %%f
  56. %LOG% done.
  57. exit /B 0
  58. :del_file
  59. if exist %1 del %1 && %LOG% %1
  60. exit /B 0
  61. :del_dir
  62. if exist %1 rmdir /Q/S %1 && %LOG% %1
  63. exit /B 0
  64. :cl
  65. @echo off
  66. set CMD=cl
  67. :c0
  68. set ARG=%1
  69. set ARG=%ARG:.dll=.lib%
  70. if (%1)==(-shared) set ARG=-LD
  71. if (%1)==(-o) shift && set ARG=-Fe%2
  72. set CMD=%CMD% %ARG%
  73. shift
  74. if not (%1)==() goto :c0
  75. echo on
  76. %CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
  77. @exit /B %ERRORLEVEL%
  78. @rem ------------------------------------------------------
  79. @rem main program
  80. :p1
  81. if not %T%_==_ goto :p2
  82. set T=32
  83. if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
  84. if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
  85. :p2
  86. if "%CC:~-3%"=="gcc" set CC=%CC% -Os -s -static
  87. set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
  88. set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
  89. set P32=i386-win32
  90. set P64=x86_64-win32
  91. if %T%==64 goto :t64
  92. set D=%D32%
  93. set DX=%D64%
  94. set PX=%P64%
  95. goto :p3
  96. :t64
  97. set D=%D64%
  98. set DX=%D32%
  99. set PX=%P32%
  100. goto :p3
  101. :p3
  102. @echo on
  103. :config.h
  104. echo>..\config.h #define TCC_VERSION "%VERSION%"
  105. echo>> ..\config.h #ifdef TCC_TARGET_X86_64
  106. echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a"
  107. echo>> ..\config.h #else
  108. echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a"
  109. echo>> ..\config.h #endif
  110. for %%f in (*tcc.exe *tcc.dll) do @del %%f
  111. :compiler
  112. %CC% -o libtcc.dll -shared ..\libtcc.c %D% -DLIBTCC_AS_DLL
  113. @if errorlevel 1 goto :the_end
  114. %CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
  115. %CC% -o %PX%-tcc.exe ..\tcc.c %DX%
  116. @if (%EXES_ONLY%)==(yes) goto :files-done
  117. if not exist libtcc mkdir libtcc
  118. if not exist doc mkdir doc
  119. copy>nul ..\include\*.h include
  120. copy>nul ..\tcclib.h include
  121. copy>nul ..\libtcc.h libtcc
  122. copy>nul ..\tests\libtcc_test.c examples
  123. copy>nul tcc-win32.txt doc
  124. .\tcc -impdef libtcc.dll -o libtcc\libtcc.def
  125. @if errorlevel 1 goto :the_end
  126. :libtcc1.a
  127. @set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o bcheck.o
  128. .\tcc -m32 -c ../lib/libtcc1.c
  129. .\tcc -m32 -c lib/crt1.c
  130. .\tcc -m32 -c lib/crt1w.c
  131. .\tcc -m32 -c lib/wincrt1.c
  132. .\tcc -m32 -c lib/wincrt1w.c
  133. .\tcc -m32 -c lib/dllcrt1.c
  134. .\tcc -m32 -c lib/dllmain.c
  135. .\tcc -m32 -c lib/chkstk.S
  136. .\tcc -m32 -w -c ../lib/bcheck.c
  137. .\tcc -m32 -c ../lib/alloca86.S
  138. .\tcc -m32 -c ../lib/alloca86-bt.S
  139. .\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
  140. @if errorlevel 1 goto :the_end
  141. .\tcc -m64 -c ../lib/libtcc1.c
  142. .\tcc -m64 -c lib/crt1.c
  143. .\tcc -m64 -c lib/crt1w.c
  144. .\tcc -m64 -c lib/wincrt1.c
  145. .\tcc -m64 -c lib/wincrt1w.c
  146. .\tcc -m64 -c lib/dllcrt1.c
  147. .\tcc -m64 -c lib/dllmain.c
  148. .\tcc -m64 -c lib/chkstk.S
  149. .\tcc -m64 -w -c ../lib/bcheck.c
  150. .\tcc -m64 -c ../lib/alloca86_64.S
  151. .\tcc -m64 -c ../lib/alloca86_64-bt.S
  152. .\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
  153. @if errorlevel 1 goto :the_end
  154. :tcc-doc.html
  155. @if not (%DOC%)==(yes) goto :doc-done
  156. echo>..\config.texi @set VERSION %VERSION%
  157. cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
  158. :doc-done
  159. :files-done
  160. for %%f in (*.o *.def) do @del %%f
  161. :copy-install
  162. @if (%INST%)==() goto :the_end
  163. if not exist %INST% mkdir %INST%
  164. @if (%BIN%)==() set BIN=%INST%
  165. if not exist %BIN% mkdir %BIN%
  166. for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BIN%\%%f
  167. @if not exist %INST%\lib mkdir %INST%\lib
  168. for %%f in (lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
  169. for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f
  170. :the_end
  171. exit /B %ERRORLEVEL%