.cb 文件格式

.cb 是CBuild的项目文件,语法类似nmake的makefile。

典型的.cb文件内容:

FileName=MessageBox.exe      指定输出文件名称(包含扩展名)
RuntimeLibrary=LIBCMT        指定要链接的运行库: {LIBCMT|MSVCRTXX|LIBC|MFCSTATIC|MFCDLL|NONE}, 默认值: LIBCMT
CharacterSet=UNICODE         指定要使用的字符集: {MBCS|UNICODE}, 默认值: MBCS
PrecompiledHeader=precomp.h  指定后将启用预编译,能够缩短构建时间

INCLUDES=.;..;include        指定头文件的搜索目录,多个目录可用分号分隔
MACROS=STATIC_LINK           指定预处理器宏,类似C/C++源码中的#define功能,多个宏可用分号分隔
LIBS=comctl32.lib;ole32.lib  指定要链接的.lib,多个值用分号分隔
LIBPATHS=..\lib              指定.lib的搜索目录,多个目录用分号分隔
CFLAGS=                      指定编译器参数(cl.exe)
LFLAGS=                      指定链接器参数(link.exe)
RFLAGS=                      指定资源编译器参数(rc.exe)
AFLAGS=                      指定ASM汇编器参数
AS=                          指定用哪个汇编器编译.asm文件。

NameManagling=1              指定是否重命名输出的.obj文件名。{0|1}, 默认值: 0
Sources=\                    指定源码文件
    messagebox.c \
    main.c

Projects=\                       指定其他项目列表。
    dir1 \
    dir2

PreBuild:                    指定构建前要执行的操作
    [命令 1]
    ...
    [命令 n]
    
PostBuild:                   指定构建后执行的操作 (需要指定/p参数才能执行)
    [命令 1]
    ...
    [命令 n]

语法格式:

1. A=B             将B赋值给变量A
2. A:              A为命令列表:依次执行command 1、command 2
     command 1
     command 2

3. # comment       #开头的为注释行
4. A=B\            行末尾的\为换行符,等价于 A=B C
     C
5. A=$(B)          将变量B的值赋值给变量A。$(Variable)为引用Variable的值
6. !ifdef          支持!ifdef !else !endif
安装CBuild后,你可以右键点击.dsp/.vcproj/.vcxproj来转换生成.cb文件,

或者在CBuild命令行环境下运行 cbuild create 命令自动生成.cb文件。

例子:

经典的Hello World工程:
# demo_console\build.cb
FileName=HelloWorld.exe
Sources=HelloWorld.c
汇编和C的混合工程: x264
# x264: http://www.videolan.org/developers/x264.html
# x264 CBuild 工程文件

FileName=x264.exe
RuntimeLibrary=LIBCMT
CharacterSet=MBCS
INCLUDES=.;extras
LIBS=
MACROS=HAVE_STRING_H
CFLAGS=/sdl- /wd4996
LFLAGS=-map:map.txt
AFLAGS=-O2 -Worphan-labels -DSTACK_ALIGNMENT=32 -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8
AS=YASM
NameMangling=1

Sources=\
    common/mc.c common/predict.c common/pixel.c common/macroblock.c \
    common/frame.c common/dct.c common/cpu.c common/cabac.c \
    common/common.c common/osdep.c common/rectangle.c \
    common/set.c common/quant.c common/deblock.c common/vlc.c \
    common/mvpred.c common/bitstream.c \
    encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
    encoder/set.c encoder/macroblock.c encoder/cabac.c \
    encoder/cavlc.c encoder/encoder.c encoder/lookahead.c \
    x264.c input/input.c input/timecode.c input/raw.c input/y4m.c \
    output/raw.c output/matroska.c output/matroska_ebml.c \
    output/flv.c output/flv_bytestream.c filters/filters.c \
    filters/video/video.c filters/video/source.c filters/video/internal.c \
    filters/video/resize.c filters/video/cache.c filters/video/fix_vfr_pts.c \
    filters/video/select_every.c filters/video/crop.c filters/video/depth.c \
    input/avs.c \
    input/thread.c \
    common/threadpool.c \
    common/win32thread.c \
    common/opencl.c \
    encoder/slicetype-cl.c \
    extras/getopt.c \
    common/x86/mc-c.c \
    common/x86/predict-c.c \
    common/x86/const-a.asm \
    common/x86/cabac-a.asm \
    common/x86/dct-a.asm \
    common/x86/deblock-a.asm \
    common/x86/mc-a.asm \
    common/x86/mc-a2.asm \
    common/x86/pixel-a.asm \
    common/x86/predict-a.asm \
    common/x86/quant-a.asm \
    common/x86/cpu-a.asm \
    common/x86/bitstream-a.asm \
    common/x86/sad-a.asm

!ifdef _WIN64
MACROS+=;ARCH_X86_64=1
AFlags+=-DARCH_X86_64=1
Sources+=\
    common/x86/dct-64.asm \
    common/x86/trellis-64.asm
!else
MACROS+=;ARCH_X86=1
AFlags+=-DARCH_X86_64=0 -DPREFIX 
Sources+=\
    common/x86/dct-32.asm \
    common/x86/pixel-32.asm
!endif