Board logo

标题: [其他] 批处理版gcc编译器 [打印本页]

作者: happy886rr    时间: 2017-5-23 20:17     标题: 批处理版gcc编译器

本帖最后由 happy886rr 于 2017-5-23 20:20 编辑

城通网盘下载:https://page37.ctfile.com/fs/14274637-203903157
发个自己写的批处理版gcc编译器,仅有5M大小,对于.c或.cpp后缀的文件,直接拖拽到MinGW.cmd图标上,瞬间编译出exe文件,所编译的exe体积超小,不依赖任何运行库。该工具也是自己的主要开发工具:记事本+批处理gcc。可以开发绝大多数第三方,黑窗口比用IDE更快、更轻便。

演示:用批处理版gcc编译的pdll仅有8KB,且无dll依赖。


脚本代码:
  1. @echo off&color 0f
  2. ::*********************用户设置********************
  3. REM 用户指令
  4.   set USER_COMMAND=
  5. ::*********************高级设置********************
  6. REM 环境变量
  7.   set "PATH=%~dp0MinGW\bin;%PATH%"
  8. REM 优化参数
  9.   set "OPTIMIZATION_COMMAND=-std=gnu99 -O2 -s"
  10.   set "OPTIMIZATION_COMMAND++=-O2 -s"
  11. REM 编译器项
  12.   set "COMPILER=gcc.exe"
  13.   set "COMPILER++=g++.exe"
  14. ::*********************后缀筛选********************
  15. if /i "%~f1"==""     (goto :CMD_CONSOLE     )
  16. if /i "%~x1"==".c"   (goto :MINGW32_COMPILER)
  17. if /i "%~x1"==".cpp" (
  18. set "COMPILER=%COMPILER++%"
  19. set "OPTIMIZATION_COMMAND=%OPTIMIZATION_COMMAND++%"
  20. goto :MINGW32_COMPILER
  21. )
  22. set/p=Error: 非.c或.cpp后缀文件
  23. exit /b
  24. MINGW32_COMPILER()
  25. {
  26. :MINGW32_COMPILER
  27. pushd "%~dp1"
  28. echo ================================================================================
  29. echo  Mingw32 compiler 编译器
  30. echo ================================================================================
  31. echo  编译...
  32. %COMPILER% "%~nx1" %OPTIMIZATION_COMMAND% %USER_COMMAND% -o "%~n1.exe"
  33. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  34. echo  运行...
  35. if exist "%~n1.exe" ("%~n1.exe")
  36. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  37. echo  结束.
  38. pause>NUL
  39. exit /b
  40. }
  41. CMD_CONSOLE()
  42. {
  43. :CMD_CONSOLE
  44. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  45. echo [GCC console]
  46. set/p PCOMMANDLINE=^>
  47. %PCOMMANDLINE%
  48. echo;
  49. goto :CMD_CONSOLE
  50. }
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2