文件
Paze-C-CPP-Compiler/win32/build-pcc.bat
T
Paze AI 251ee470bf feat: Paze C Compiler - 完整改造自 tcc 0.9.28rc
- 所有 tcc 文件/内容/宏改名为 pcc (tcc.c->pcc.c, tccelf.c->pccelf.c, libtcc.c->libpcc.c 等)
- 支持架构: i386, x86_64, ARM, ARM64, RISC-V, C67
- 支持格式: PE, ELF, Mach-O, COFF
- 完整预处理、代码生成、链接器、调试信息
- 构建成功: pcc.exe (x86_64 Windows)
- 功能测试通过: 递归/结构体/浮点/switch/循环
- 自编译测试通过: pcc 可以编译自身
2026-08-16 13:30:01 +08:00

209 行
6.2 KiB
Batchfile

@rem ------------------------------------------------------
@rem batch file to build pcc using mingw, msvc or pcc itself
@rem ------------------------------------------------------
@echo off
setlocal
if (%1)==(-clean) goto :cleanup
set CC=gcc -O2 -Wall
set /p VERSION= < ..\VERSION
set PCCDIR=
set BINDIR=
set DOC=no
set TX=
set SELF=%~nx0
goto :a0
:a2
shift
:a3
shift
:a0
if not (%1)==(-c) goto :a1
set CC=%~2
if (%2)==(cl) set CC=@call :cl
goto :a2
:a1
if (%1)==(-t) set T=%2&& goto :a2
if (%1)==(-v) set VERSION=%~2&& goto :a2
if (%1)==(-i) set PCCDIR=%2&& goto :a2
if (%1)==(-b) set BINDIR=%2&& goto :a2
if (%1)==(-d) set DOC=yes&& goto :a3
if (%1)==(-x) set TX=%2&& goto :a2
if (%1)==() goto :p1
:usage
echo usage: build-pcc.bat [ options ... ]
echo options:
echo -c prog use prog (gcc/pcc/cl) to compile pcc
echo -c "prog options" use prog with options to compile pcc
echo -t target set target
echo -x target build pcc cross-compiler for target
echo -v "version" set pcc version
echo -i pccdir install pcc into pccdir
echo -b bindir but install pcc.exe and libpcc.dll into bindir
echo -d create pcc-doc.html too (needs makeinfo)
echo -clean delete all previously produced files and directories
echo supported targets i386 x86_64 arm64
exit /B 1
@rem ------------------------------------------------------
@rem sub-routines
:cleanup
set LOG=echo
%LOG% removing files:
for %%f in (*pcc.exe libpcc.dll lib\*.a) do call :del_file %%f
for %%f in (..\config.h ..\config.texi) do call :del_file %%f
for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f
for %%f in (include\pcclib.h examples\libpcc_test.c) do call :del_file %%f
for %%f in (lib\*.o *.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f
%LOG% removing directories:
for %%f in (doc libpcc) do call :del_dir %%f
%LOG% done.
exit /B 0
:del_file
if exist %1 del %1 && %LOG% %1
exit /B 0
:del_dir
if exist %1 rmdir /Q/S %1 && %LOG% %1
exit /B 0
@rem ------------------------------------------------------
:cl
@echo off
set CMD=cl
:c0
set ARG=%1
set ARG=%ARG:.dll=.lib%
if (%1)==(-shared) set ARG=-LD
if (%1)==(-o) shift && set ARG=-Fe%2
set CMD=%CMD% %ARG%
shift
if not (%1)==() goto :c0
echo on
%CMD% -O2 -W2 -Zi -MT -GS- -nologo %DEF_GITHASH% -link -opt:ref,icf
@exit /B %ERRORLEVEL%
@rem ------------------------------------------------------
@rem main program
:p1
if not _%TX%_==__ set T=%TX%&&set TX=%TX%-win32-
if _%T%_%PROCESSOR_ARCHITECTURE%_==__x86_ set T=i386
if _%T%_%PROCESSOR_ARCHITECTURE%_==__ARM64_ set T=arm64
if _%T%_==__ set T=x86_64
if %T%==i386 set D=-DPCC_TARGET_PE -DPCC_TARGET_I386
if %T%==x86_64 set D=-DPCC_TARGET_PE -DPCC_TARGET_X86_64
if %T%==arm64 set D=-DPCC_TARGET_PE -DPCC_TARGET_ARM64
if "%D%"=="" echo %SELF%: error: unknown target '%T%'&&exit /B 1
@if (%CC:~0,3%)==(gcc) set CC=%CC% -s -static
@if (%BINDIR%)==() set BINDIR=%PCCDIR%
:git_hash
git.exe --version 2>nul
if not %ERRORLEVEL%==0 goto :git_done
for /f %%b in ('git.exe rev-parse --abbrev-ref HEAD') do set GITHASH=%%b
for /f %%b in ('git.exe log -1 "--pretty=format:%%cs_%GITHASH%@%%h"') do set GITHASH=%%b
git.exe diff --quiet
if %ERRORLEVEL%==1 set GITHASH=%GITHASH%*
:git_done
@echo on
:config.h
echo>..\config.h #define PCC_VERSION "%VERSION%"
@if not "%GITHASH%"=="" echo>>..\config.h #define PCC_GITHASH "%GITHASH%"
@if not _%BINDIR%_==_%PCCDIR%_ echo>>..\config.h #define CONFIG_PCCDIR "%PCCDIR:\=/%"
@if not _%TX%_==__ @echo>>..\config.h #define CONFIG_PCC_CROSSPREFIX "%TX%"
@rem echo>> ..\config.h #define CONFIG_PCC_PREDEFS 1
@rem %CC% -DC2STR ..\conftest.c -o c2str.exe
@rem .\c2str.exe ../include/pccdefs.h ../pccdefs_.h
@if not _%TX%_==__ goto :pcc_cross
@if not _%PCC_C%_==__ goto :pcc_only
@if _%LIBPCC_C%_==__ set LIBPCC_C=..\libpcc.c
@set IMPLIB=libpcc.dll
@if "%CC:~0,5%"=="clang" set IMPLIB=libpcc.lib
%CC% -o libpcc.dll -shared %LIBPCC_C% %D% -DLIBPCC_AS_DLL
@if errorlevel 1 goto :the_end
%CC% -o pcc.exe ..\pcc.c %IMPLIB% %D% -DONE_SOURCE"=0"
@if errorlevel 1 goto :the_end
@goto :compiler_done
:pcc_only
%CC% -o pcc.exe %PCC_C% %D%
@if errorlevel 1 goto :the_end
@goto :compiler_done
:pcc_cross
%CC% -o %TX%pcc.exe ..\pcc.c %D%
@if errorlevel 1 goto :the_end
@goto :compiler_done
:compiler_done
@if (%EXES_ONLY%)==(yes) goto :files_done
if not exist libpcc mkdir libpcc
if not exist doc mkdir doc
copy>nul ..\include\*.h include
copy>nul ..\pcclib.h include
copy>nul ..\libpcc.h libpcc
copy>nul ..\tests\libpcc_test.c examples
copy>nul pcc-win32.txt doc
if exist libpcc.dll .\pcc -impdef libpcc.dll -o libpcc\libpcc.def
@if errorlevel 1 goto :the_end
:lib
@call :make_lib %TX% || goto :the_end
:pcc-doc.html
@if not (%DOC%)==(yes) goto :doc-done
echo>..\config.texi @set VERSION %VERSION%
cmd /c makeinfo --html --no-split ../pcc-doc.texi -o doc/pcc-doc.html
:doc-done
:files_done
for %%f in (*.o *.def) do @del %%f
:copy-install
@if (%PCCDIR%)==() goto :the_end
if not exist %BINDIR% mkdir %BINDIR%
for %%f in (*pcc.exe *pcc.dll) do @copy>nul %%f %BINDIR%\%%f
if not exist %PCCDIR% mkdir %PCCDIR%
@if not exist %PCCDIR%\lib mkdir %PCCDIR%\lib
for %%f in (lib\*.a lib\*.o lib\*.def) do @copy>nul %%f %PCCDIR%\%%f
for %%f in (include examples libpcc doc) do @xcopy>nul /s/i/q/y %%f %PCCDIR%\%%f
:the_end
exit /B %ERRORLEVEL%
:make_lib
@set LIBPCC1=libpcc1
@if _%1_==_arm64_ set LIBPCC1=lib-arm64
.\%1pcc -B. -c ../lib/%LIBPCC1%.c
.\%1pcc -B. -c lib/crt1.c
.\%1pcc -B. -c lib/crt1w.c
.\%1pcc -B. -c lib/wincrt1.c
.\%1pcc -B. -c lib/wincrt1w.c
.\%1pcc -B. -c lib/dllcrt1.c
.\%1pcc -B. -c lib/dllmain.c
.\%1pcc -B. -c lib/winex.c
.\%1pcc -B. -c lib/chkstk.S
.\%1pcc -B. -c ../lib/alloca.S
.\%1pcc -B. -c ../lib/alloca-bt.S
.\%1pcc -B. -c ../lib/stdatomic.c
.\%1pcc -B. -c ../lib/atomic.S
.\%1pcc -B. -c ../lib/builtin.c
.\%1pcc -ar lib/%1libpcc1.a %LIBPCC1%.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o winex.o chkstk.o alloca.o alloca-bt.o stdatomic.o atomic.o builtin.o
.\%1pcc -B. -c ../lib/bcheck.c -o lib/%1bcheck.o -bt -I..
.\%1pcc -B. -c ../lib/bt-exe.c -o lib/%1bt-exe.o
.\%1pcc -B. -c ../lib/bt-log.c -o lib/%1bt-log.o
.\%1pcc -B. -c ../lib/bt-dll.c -o lib/%1bt-dll.o
.\%1pcc -B. -c ../lib/runmain.c -o lib/%1runmain.o
exit /B %ERRORLEVEL%