Saturday, February 28, 2009

Bakefile 中文版手册

Chapter 2. 入门 Tutorial

Table of Contents

Hello, world

Hello, world

By far the simplest way to generate makefiles using Bakefile is to use so-called presets which are prepared skeletons of bakefiles that get you started quickly. Let's see how it works on an example of the famous Hello, world program written in C and implemented in the hello.c file:

现在,用Bakefile生成makefile最简单的方法是,使用一些预先设定的框架 presets,它可以让你快速起步。让我们看看bakefile如何应用于这个著名的用C语言实现的Hello, world 例子,源文件是hello.c :

 #include <stdio.h>  int main() {   printf("Hello, world!\n");   return 0; } 

The bakefile needed to compile it,hello.bkl, looks like this:

Bakefile需要编译它,hello.bkl, 如下:

 <?xml version="1.0"?> <makefile>    <include file="presets/simple.bkl"/>      <exe id="hello" template="simple">     <sources>hello.c</sources>   </exe>  </makefile> 

Presets are included using the include directive. The structure of the file name is always the same: presets/NAME-OF-PRESET.bkl. In general, you can combine several presets, but in practice you must be careful when doing so. It's always a good idea to read the code for the preset before using it. The "simple" preset we include here defines a DEBUGoption and a template called simple. Generated makefiles will allow the user to build all targets that are based on this template as either debug or release build.

使用include 命令来导入preset。文件名的结构总是如下: presets/NAME-OF-PRESET.bkl 。通常,你可以合并使用多个preset,但是实际操作的时候,你最好小心点来。导入之前最好先读读preset的代码。我们这里导入的 "simple" preset 定义了一个 DEBUG option 和一个simple template 。 生成的makefile文件可以让用户基于这个template 来生成所有的target的debug 或 release build。

Let's generate some makefiles now. The bakefile command is used to do it. For example:

Le现在我们来生成makefile。bakefile命令就是干这个的,例:

bakefile -f msvc hello.bkl

That's all. This will creates VC++ makefile makefile.vc. Of course, you can change the name of output file if you don't like the default:

搞定。现在会生成VC++的makefile makefile.vc 。当然,如果你不喜欢默认的输出文件名,你可以换:

bakefile -f msvc -o makefile hello.bkl

Bakefile will also generate the Makefile.in files used by Autoconf:

Bakefile 同时可以生成 Autoconf 使用的 Makefile.in 文件:

bakefile -f autoconf hello.bkl

These are templates for makefiles. Autoconf also requires a configure.ac script (previously, configure.in), but Bakefile will not generate this for you. This script checks for platform features necessary to build the program; see the autoconf manual for details.

These are templates for makefiles. Autoconf 还需要一个 configure.ac 脚本 (之前版本 configure.in),但Bakefile不会帮你生成它。这个脚本检查系统平台是否满足build当前program,详见 autoconf 手册。

When producing autoconf format output, Bakefile will also generate a file called autoconf_inc.m4 which defines macros needed by the generated Makefile.in files. To use this, call the AC_BAKEFILE macro within your configure.ac script.

生成 autoconf format 输出的时候,Bakefile 同时会生成一个叫做 autoconf_inc.m4 的文件,它定义了生成的 Makefile.in 文件需要的宏。应用中,在 configure.ac 脚本里调用 AC_BAKEFILE 宏。

A minimal configure.ac script for our example program would look like this:

我们的示例program的最精简 configure.ac 可能格式如下:

 AC_PREREQ(2.53) AC_INIT(aclocal.m4) AC_CANONICAL_SYSTEM DEBUG=0 AC_BAKEFILE([m4_include(autoconf_inc.m4)]) AC_OUTPUT([Makefile]) 

Note the part that sets the DEBUG variable. Any options declared in your bakefile must be set to some default value before calling AC_BAKEFILE. The simple.bkl preset defines the DEBUG option, so we have to give it a default value here.

注意设置 DEBUG 变量的位置。你的bakefile定义(?)的任何option在调用 AC_BAKEFILE 之前必须给定一个默认值。 "simple.bkl" preset 定义了 DEBUG option,所以我们得给它个默认值。

While the above code will work, there's a better way to handle the debug option:

虽然上面的代码可以工作,这儿有个更好的方法来管理 debug option:

 AC_PREREQ(2.53) AC_INIT(aclocal.m4) AC_CANONICAL_SYSTEM  AC_ARG_ENABLE(debug,               [  --enable-debug          Enable debugging information],               USE_DEBUG="$enableval", USE_DEBUG="no")  if test $USE_DEBUG = yes ; then    DEBUG=1   dnl Bakefile doesn't touch {C,CPP,CXX,LD}FLAGS in autoconf format, we   dnl have to do it ourselves. This will work with many compilers   dnl (but not all, proper configure script would check if the compiler   dnl supports it):   CFLAGS="$CFLAGS -g" else   DEBUG=0 fi  AC_BAKEFILE([m4_include(autoconf_inc.m4)]) AC_OUTPUT([Makefile]) 

You are ready to generate Autoconf's configure script now:

你现在已经准备好生成 Autoconf 的 configure 脚本了:

bakefilize --copy && aclocal && autoconf

Bakefile 中文版手册

文档下载地址:


------------------------------------------------

Bakefile 手册


Table of Contents

1. 简介 Introduction
流程 Flow
2. 入门 Tutorial
Hello, world
3. Bakefile 概念 Bakefile Concepts
目标 Targets
变量 Variables
模板 Templates
选择 Options
Conditions 条件
条件变量 Conditional Variables
模组 Modules
预设定 Presets
路径 Paths
4. 目标 Targets
标准目标类型("规则") Standard Target Types ("Rules")
exe
lib
dll
module
phony
action
subproject
Common tags
5. 命令参考 Commands Reference
Makefile命令 Makefile Commands
set
unset
option
template
using
include
if
fragment
requires
error
warning
echo
扩展Bakefile的命令 Commands for Extending Bakefile
define-rule
define-tag
define-global-tag
add-target
modify-target
output
6. 常见问题 Frequently encountered issues
未修订 FIXME
7. Bakefile内置变量 Variables defined by Bakefile
格式无关变量 Format independent variables
改变Bakefile的行为 Changing Bakefile behaviour
目录 Directories
安装目录 Installation Directories
识别系统平台 Recognizing Platform
格式化功能 Format features
杂项 Miscellaneous
标准makefile变量 Standard makefile variables
专有格式变量 Format specific variables
autoconf
dmars, dmars_smake
msvs2005prj, msvs2008prj
msvs2003prj
8. Python函数 Python functions
介绍 Introduction
在Bakefile中使用Python函数 How to use a Python function in a bakefile
Python函数 Python functions
envvar
isconst
isdefined
isoption
iscondvar
ifthenelse
ref
isDeadTarget
substituteFromDict
nativePaths
addPrefixIfNotEmpty
addPrefixToList
safeSplit
fileList
removeDuplicates
9. 格式相关文档 Format specific documentation
MSVisualStudio 2005/2008 扩展功能 MS VisualStudio 2005/2008 extended functionality
Watcom format extended functionality
Install and uninstall support on Windows
10. 模模组 Modules
数据文件 datafiles
data-files
data-files-ng
script-files
script-files-ng
data-files-tree
copy-files
copy-file-to-file
mkdir
pkgconfig
pkgconfig
11. 用bakefile_gen自动生成bakefile Batch bakefile generation with bakefile_gen
介绍 Introduction
bakefile_gen tags
处理顺序 Processing order
I. 运行Bakefile Running Bakefile
bakefile — 本地makefile生成工具 native makefiles generator
bakefile_gen — 自动化生成bakefile batch bakefile generation
bakefilize — 为Autoconf用户生成Bakefile项目文件 prepare Bakefile project for use with Autoconf

Wednesday, February 4, 2009

用 VC2005 编译 Python 3.0 无法打开工程文件?


文件夹 \Python-3.0-src\PC 里面包含了支持老版本VC的工程文件。
可是,双击 VS8.0 目录下面的 pcbuild.sln 却无法正常打开。
先启动VC8,再用Open Project 才成功打开。重新保存一次后,可以正常双击自动启动VC8打开了。