A Makefile Example That Explains How This Works


To demonstrate how the environment batch files work, I will use a standard makefile.

The way this build system works is that all top-level directories must contain a makefile, filelist.mk, and depend.mk files. Each file is explained in the example that follows.

The makefile should be like this:

############################################################## # #   <project> #   Copyright (C) <project> Corporation, 200x #   All rights reserved. # ############################################################## # Sample makefile default: all # need to include all important files !include filelist.mk   -> directory specific   explained below !include $(COMMON)\SRC\RULES.mk    -> system wide makefile 

RULES.mk is a global makefile that has various dependencies and nmake macros in it. It is used to keep the builds consistent.

!include depend.mk                  ->  directory specific # Additional makefiles if necessary 

Filelist.mk should contain the names of source files that you want to compile, names of libraries to link with, and so on. The following example compiles the foo.c and moo.c files and builds foo.exe.

#  Sample filelist.mk ########################################################## # #   <project> #   Copyright (C) <project> Corporation, 200x #   All rights reserved. # ########################################################## # # #   Name of target. Include an extension (.dll, .lib, .exe). #   If the target is part of the release, set RELEASE to 1. # TARGET       = foo.exe TARGET_DESCRIPTION = "Microsoft Foo Utility" NO_WINMAIN = TRUE NO_UNICODE = TRUE USE_STDCRT = TRUE # The initial .\ will be necessary (nmake bug) CFILES     = .\foo.c  \               .\moo.c   \ CFLAGS     = -DNDEBUG -DFLAT -DNO_OPTION_Z -DNT -DWIN32_API CINC       = -I. # #   Libraries and other object files to link. # LIBS       = OBJFILES    = 

If you have a directory that contains several subdirectories with source files in them, and you want to launch a build from the parent directory, include just three lines in the filelist.mk.

BASEDIR   = $(<PROJECT>) SUBDIRS = foodir moodir # End of Sample filelist.mk 

This example causes nmake to build the foodir and moodir directories in the <project> project (in the order listed), where $(<PROJECT>) is defined in the build environment.

The depend.mk file contains the dependencies. When you are building for the first time, create an empty depend.mk file.

#Sample depend.mk # Empty 

Then type nmake depend. Nmake calculates all the dependencies and stores them in the depend.mk file. To build the product, just type nmake. Products are created in the following directories. Note that these rules are defined in the RULES.mk file:

\objindx86 debug \objinrx86 retail 

If you add source files to filelist.mk, you should rebuild the depend.mk file before building the product.

Following are some useful nmake rules that are easy to add:

  • nmake clean Removes all built files.

  • nmake all Builds the project and all subprojects.

  • nmake depend Builds the dependency file. Checks it back in when you're finished.

  • nmake tree Releases the build to where the DIST environment var points.



The Build Master(c) Microsoft's Software Configuration Management Best Practices
The Build Master: Microsofts Software Configuration Management Best Practices
ISBN: 0321332059
EAN: 2147483647
Year: 2006
Pages: 186

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net