用mingw編譯tcc原始碼

lt發表於2016-10-12

0.在https://sourceforge.net/projects/mingw-w64/下載最新的mingw壓縮包,解壓到D:\目錄。我選擇的是win32版本。解壓後的目錄是D:\mingw32。

1.設定環境變數

set path=%path%;D:\mingw32\bin
set include=%include%;D:\mingw32\include
set lib=%lib%;D:\mingw32\lib

2.把下載的壓縮包檔案解壓縮。進入win32目錄。

D:\tcc-0.9.26\win32>dir

 D:\tcc-0.9.26\win32 的目錄

2016/10/12  08:37              .
2016/10/12  08:37              ..
2013/02/15  22:24             1,766 build-tcc.bat
2016/10/12  08:37              examples
2016/10/12  08:37              include
2016/10/12  08:37              lib
2013/02/15  22:24             4,505 tcc-win32.txt
2016/10/12  08:37              tools

3.執行批處理檔案

D:\tcc-0.9.26\win32>build-tcc

D:\tcc-0.9.26\win32>echo #define TCC_VERSION "0.9.26" 1>..\config.h

D:\tcc-0.9.26\win32>gcc -Os -s -fno-strict-aliasing -DTCC_TARGET_PE -DTCC_TARGET_I386 tools/tiny_impdef.c -o tiny_impdef.exe

D:\tcc-0.9.26\win32>gcc -Os -s -fno-strict-aliasing -DTCC_TARGET_PE -DTCC_TARGET_I386 tools/tiny_libmaker.c -o tiny_libmaker.exe

D:\tcc-0.9.26\win32>if not exist libtcc\nul mkdir libtcc

D:\tcc-0.9.26\win32>copy ..\libtcc.h libtcc\libtcc.h
已複製         1 個檔案。

D:\tcc-0.9.26\win32>gcc -Os -s -fno-strict-aliasing -DTCC_TARGET_PE -DTCC_TARGET_I386 -shared -DLIBTCC_AS_DLL -DONE_SOURCE ../libtcc.c -o libtcc.dll -
Wl,-out-implib,libtcc/libtcc.a

D:\tcc-0.9.26\win32>tiny_impdef libtcc.dll -o libtcc/libtcc.def

D:\tcc-0.9.26\win32>gcc -Os -s -fno-strict-aliasing -DTCC_TARGET_PE -DTCC_TARGET_I386 ../tcc.c -o tcc.exe -ltcc -Llibtcc
../tcc.c: In function 'execvp_win32':
../tcc.c:81:39: warning: passing argument 3 of 'spawnvp' from incompatible pointer type [-Wincompatible-pointer-types]
     int ret = spawnvp(P_NOWAIT, prog, (char const*const*)argv);
                                       ^
In file included from ../tcc.c:78:0:
D:/mingw32/i686-w64-mingw32/include/process.h:191:20: note: expected 'char * const*' but argument is of type 'const char * const*'
   intptr_t __cdecl spawnvp(int,const char *_Filename,char *const _ArgList[]) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
                    ^~~~~~~

D:\tcc-0.9.26\win32>copy ..\include\*.h include
..\include\float.h
..\include\stdarg.h
..\include\stdbool.h
..\include\stddef.h
..\include\tcclib.h
..\include\varargs.h
已複製         6 個檔案。

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/libtcc1.c

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S

D:\tcc-0.9.26\win32>goto lib32

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S

D:\tcc-0.9.26\win32>.\tcc -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/bcheck.c
../lib/bcheck.c:46: warning: #warning Bound checking does not support malloc (etc.) in this environment.

D:\tcc-0.9.26\win32>tiny_libmaker lib/libtcc1.a libtcc1.o alloca86.o alloca86-bt.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o

D:\tcc-0.9.26\win32>del *.o
D:\tcc-0.9.26\win32>dir *.exe

 D:\tcc-0.9.26\win32 的目錄

2016/10/12  09:01            17,920 tcc.exe
2016/10/12  09:00            15,872 tiny_impdef.exe
2016/10/12  09:00            15,360 tiny_libmaker.exe

4.執行tcc.exe

D:\tcc-0.9.26\win32>tcc
tcc version 0.9.26 - Tiny C Compiler - Copyright (C) 2001-2006 Fabrice Bellard
Usage: tcc [options...] [-o outfile] [-c] infile(s)...
       tcc [options...] -run infile [arguments...]
General options:
  -c          compile only - generate an object file
  -o outfile  set output filename
。。。

5.最新的tcc原始碼在http://repo.or.cz/w/tinycc.git,在win32下多了個vc2015目錄,裡面有相應的sln和proj檔案。編譯應該就更方便了。

相關文章