| 第三章 bMake工具  bMake工具允许用户使用工程文件编译整个MDL应用。工程文件定义了组成一个MDL应用的各种宏并指定了各从属文件的编译关联。bMake工具通过判断文件创建的时间可以识别工程文件中是否有文件被改变、删除等。    一、工程文件的文件格式    · 工程文件中包含一系列描述应用将如何编译的语句,这些语句有以下几种类型:  宏(Marco)  条件(Conditionals)  Build命令  从属(Dependencies)  规则    · 工程文件的几个通用规则:  规则和从属语句之后必须有一空行;  如果一条语句分几行写,用“\”表示后续;  在任何操作系统中,目录的分隔符一律采用“/”(不用“\”);  注释用“#”符号打头。    二、宏(Macros)    宏是一种定义,它给字符串定义一个宏名,在使用时,这个宏名就代表该字符串。您可以引用已有的宏,当然也可以建立自己的宏。下面是一些预定义的宏:  表3-1、预定义的宏  宏  定义  $@  当前目标文件  $?  所有从属文件新于目标文件  $=  最新从属文件  $<  当前从属文件  $*  目标文件的基名(忽略后缀)  $%  第一个从属文件所在目录  msdos.IP32.unix.macintosh.vax.etc.  指定操作系统的各种宏      · 宏定义的几种方式:  在工程文件内定义;  工程文件以外的可被作为宏引用的环境变量;  在命令行中使用-D开关。    · 宏定义的语法:  macroname = string  例如:  BaseDir = $(MS)/mdl/example/basic    三、条件(Conditionals)    条件是工程文件中的流控制语句,条件语句必须以“%”打头。    表3-2、条件语句的关键字  条件  描述  %include文件名  包含工程头文件  %ifdef 宏 OR %if宏  如果宏已经定义,执行后面的语句  %ifndef 宏  如果宏未定义,执行后面的语句  %else  与%ifdef ,%if,%ifndef配合使用,表示其条件为假  %elif  在if条件为假时再判断另一条件  %endif  结束if条件      四、Build命令    Build命令是被从属和规则用来建立目标文件的一系列语句行。如果未定义Build命令,预定义的规则将使用mdl.mki文件中的内容。  表3-3、各种Build命令标志  标志  描述  @  命令不回显  $  强制回显,即使使用了silent模式  ~  使用内嵌的bmake命令,例如:  ~CURRENT设置目标文件的日期为当前日期  ~TIME设置目标文件的时间为当前时间  > 文件  把所有的命令行写入指定的文件中,直到出现“<”标志  <  关闭“>”标志指定的文件      五、从属(Dependencies)    从属语句指定了用那些源文件生成目标文件。当任一个源文件被改变时会执行从属语句。  从属语句的语法:    目标文件: 从属1 从属2 … 从属n [build命令]  例如:  $(o)basic.mo :$(BaseDir)basic.mc $(BaseDir)basic.h  六、规则(Rules)    “规则”用于定义如何使用给定扩展名的从属文件来建立指定扩展名的目标文件。许多规则都已经在mdl.mki中定义过了。如果一个目标文件有多个从属文件,其中第一个文件的扩展名将用来寻找规则。如果对一个目标文件使用了多个规则,只有最后一个有效。  规则的语法:  .从属文件扩展名.目标文件扩展名 :build命令  以下的mdl.mki文件显示了规则的范例  七、运行bMake    bMake命令把MDL源码文件编译成应用。在Windows NT中使用bMakeWin命令  · bMake的语法  bMake [options] 工程文件(*.mke)  bMakeWin [options] 工程文件(*.mke) # -- Windows NT平台  · bMake / bMakeWin的参数  -a 重编译所有文件  -dmacro=value 定义宏  -n 仅仅显示build命令  -Idir 设置 .mki文件路径  有两个常用的宏值得一提,它们是 -ddebug和-dproduction。设置宏-ddebug将打开编译器和链接器的调试信息生成开关,使得编译后的MDL应用中包含调试信息。相反,设置宏-dproduction将此开关关闭,运行时将不能进入MDL的调试器。  · 环境变量  BMAKE_OPT可用于指定编译命令行参数。以下是DOS & Windows NT操作系统autoexec.bat文件中的环境变量设置示范。  SET BMAKE_OPT=-I\WIN32APP\INGR\USTATION\MDL\INCLUDE    八、bMake涉及到的文件类型    在使用bMake进行编译时,除了源程序文件外,还涉及到两种类型的文件:工程文件和工程包含文件(或工程头文件)。工程文件以“.MKE”为扩展名;工程包含文件以“.MKI”为扩展名。一般而言,规则在工程文件中定义;从属在工程包含文件中定义。  在 $(MS)/mdl/inclde/目录中有一个标准的工程头文件:mdl.mki,其中包含了一些可以用于编译 MDL应用的默认设置。以下是MicroStation提供的示例程序Basic的工程文件和工程包含文件。  basic.mke文件  #----------------------------------------------------------------------  #  # MDL Make File  #  # $Workfile: basic.mke $  # $Revision: 5.3 $  # $Date: 01 Apr 1993 07:39:06 $  #  # Copyright (1993) Bentley Systems, Inc.  #  # Limited permission is hereby granted to reproduce and modify this  # copyrighted material provided that the resulting code is used only in  # conjunction with Bentley Systems products under the terms of the  # license agreement provided therein, and that this notice is retained  # in its entirety in any such reproduction or modification.  #  #----------------------------------------------------------------------  #---------------------------------------------  # Define macros specific to this example  #---------------------------------------------  BaseDir = $(MS)/mdl/examples/basic/  privateInc = $(BaseDir)    #---------------------------------------------  # mdl.mki contains the default rules for creating .rsc, .mo, etc files  # mdlexmpl.mki contains the output directory overrides used by examples  #---------------------------------------------  %include mdl.mki  %include mdlexmpl.mki    #----------------------------------------------------------------------  # Define macros for files included in our link and resource merge  #----------------------------------------------------------------------  basicObjs = \  $(o)basic.mo \  $(mdlLibs)ditemlib.ml    basicRscs = \  $(o)basic.mp \  $(o)basiccmd.rsc \  $(o)basictyp.rsc    #---------------------------------------------  # Generate command table include & resource file using rcomp  #---------------------------------------------  $(genSrc)basiccmd.h : $(BaseDir)basiccmd.r    $(o)basiccmd.rsc : $(BaseDir)basiccmd.r    #---------------------------------------------  # Create & compile the application's type resource file using rsctype  # and rcomp  #---------------------------------------------  $(o)basictyp.r : $(BaseDir)basictyp.mt $(BaseDir)basic.h    $(o)basictyp.rsc : $(o)basictyp.r $(BaseDir)basic.h    #---------------------------------------------  # Compile the MDL source file using mcomp  #---------------------------------------------  $(o)basic.mo : $(BaseDir)basic.mc $(BaseDir)basic.h    #---------------------------------------------  # Link MDL program file from basic.mo & ditemlib.ml using rlink  #---------------------------------------------  $(o)basic.mp : $(basicObjs)  $(msg)  > $(o)make.opt  $(linkOpts)  -a$@  $(basicObjs)  <  $(linkCmd) @$(o)make.opt  ~time    #---------------------------------------------  # Merge the dialog resources & MDL program file using rlib  #---------------------------------------------  $(reqdObjs)basic.mi : $(basicRscs)  $(msg)  > $(o)make.opt  -o$@  $(basicRscs)  <  $(rscLibCmd) @$(o)make.opt  ~time    # complete construction of the .ma by getting the last resource.    %include $(BaseDir)basicrsc.mki      basicrsc.mki文件  #----------------------------------------------------------------------  #  # MDL Make File  #  # $Workfile: basicrsc.mki $  # $Revision: 5.0 $  # $Date: 01 Apr 1993 07:33:12 $  #  # Copyright (1993) Bentley Systems, Inc., All rights reserved  #  # Limited permission is hereby granted to reproduce and modify this  # copyrighted material provided that the resulting code is used only in  # conjunction with Bentley Systems products under the terms of the  # license agreement provided therein, and that this notice is retained  # in its entirety in any such reproduction or modification.  #  #----------------------------------------------------------------------  basicRscs = \  $(reqdObjs)basic.mi \  $(rscObjects)basic.rsc \  $(rscObjects)basicmsg.rsc    $(rscObjects)basic.rsc : $(BaseDir)basic.r $(langSpec)basictxt.h \  $(privateInc)basic.h    $(rscObjects)basicmsg.rsc : $(langSpec)basicmsg.r $(privateInc)basic.h    $(mdlapps)basic.ma : $(basicRscs)  $(msg)  > $(rscObjects)make.opt  -o$@  $(basicRscs)  <  $(rscLibCmd) @$(rscObjects)make.opt  ~time      九、工程文件涉及到的MDL文件类型  图3-1工程文件涉及到的MDL文件类型      十、工程文件涉及到的MDL文件类型细节  图3-2工程文件涉及到的MDL文件类型细节  |
|【路桥隧】
( 湘ICP备16018960号-1 ) QQ群:
GMT+8, 2026-4-2 09:44
Powered by Discuz! X3.2
© 2001-2013 Comsenz Inc.