终于揭开了makefile之神秘面纱。。。

首先说一下sources文件,例如

!if 0
Copyright (c) Microsoft Corporation.  All rights reserved.
!endif
!if 0
Use of this sample source code is subject to the terms of the Microsoft
license agreement under which you licensed this sample source code. If
you did not accept the terms of the license agreement, you are not
authorized to use this sample source code. For the terms of the license,
please see the license agreement between you and Microsoft or, if applicable,
see the LICENSE.RTF on your install media or the root of your tools installation.
THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
!endif
!if 0
Use of this source code is subject to the terms of the Microsoft end-user
license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
If you did not accept the terms of the EULA, you are not authorized to use
this source code. For a copy of the EULA, please see the LICENSE.RTF on your
install media.



!endif

SYNCHRONIZE_DRAIN=1

TARGETNAME=NULLCAM
TARGETTYPE=LIBRARY
TARGETDEFNAME=$(TARGETNAME)
DEFFILE=$(TARGETDEFNAME).def
WINCETARGETFILE0=$(_RELEASELIBDIR)\$(DEFFILE)

TARGETLIBS= \
	$(_COMMONSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib \


INCLUDES=$(INCLUDES)\
	$(_PUBLICROOT)\directx\sdk\inc

SOURCES= \
        CameraDevice.cpp \
        CameraDriver.cpp \
        PinDevice.cpp    \
        PinDriver.cpp    \
        PinHardware.cpp



总体而言,sources文件包含了一些用户的宏定义,这些宏定义会被Makefile和Nmake使用,来编译项目的源代码。我们知道,Nmake程序要通过使用Makefile来知道如何对源代码进行编译,如果对于每个目录、每个项目,都要写自己的Makefile,虽然灵活性很高但是工作量非常大。有没有一种简单的方法来使用makefile呢?比较简单的办法是可把一些makefile中对所有项目都通用的部分提取出来,对某个特定项目,只需把不同的内容添加进来,这样就简化了对makefile的使用。sources文件就是出于此种目的而诞生的。

下图展示了makefile与sources之间的关系。

在要被构建的目录中,如果该目录包含sources文件,那么在相同目录一定还会有另外一个makefile文件。通常,此makefile值包含一行内容,如下所示:

!if 0
Copyright (c) Microsoft Corporation.  All rights reserved.
!endif
!if 0
Use of this sample source code is subject to the terms of the Microsoft
license agreement under which you licensed this sample source code. If
you did not accept the terms of the license agreement, you are not
authorized to use this sample source code. For the terms of the license,
please see the license agreement between you and Microsoft or, if applicable,
see the LICENSE.RTF on your install media or the root of your tools installation.
THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
!endif

#
# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source
# file to this component.  This file merely indirects to the real make file
# that is shared by all the components of Windows CE
#
!INCLUDE $(_MAKEENVROOT)\makefile.def




 _MAKEENVROOT是wince.bat设置的一个环境变量,通常指向wince.bat所在的目录,也就是 %_PUBLICROOT%\COMMON\OAK\MISC下。makefile.def文件几乎有3000行,是被所有windows CE项目共享的公用makefile模板,在makefile.def中定义了很多宏的具体用法和推导规则。同时,在makefile.def中还有这样一条语句(wince5.0中第200行):



!INCLUDE.\sources.



这样makefile.def就包含本地的sources文件。因此,当构建系统在某个目录中调用Nmake时,Nmake会去使用该目录中的makefile,然后makefile把makefile.def展开到本地,makefile.def还会把本地的sources文件包含进了。这样,本地sources文件中定义的宏与makefile.def中的宏共同起了作用,形成了一份完整的可悲Nmake使用的makefile。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值