The make utility. Basics



Similar documents
How to Write a Simple Makefile

Offline Image Viewer Guide

Eventia Log Parsing Editor 1.0 Administration Guide

Forensic Analysis of Internet Explorer Activity Files

Introduction to Python

Managing Code Development Using CCS Project Manager

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Programming Languages CIS 443

Applications Development

Specifications of Paradox for Windows

Integrating VoltDB with Hadoop

Command Line - Part 1

PL / SQL Basics. Chapter 3

Table Of Contents. iii

Getting Started with the Internet Communications Engine

List of FTP commands for the Microsoft command-line FTP client

Hands-On UNIX Exercise:

Install Java Development Kit (JDK) 1.8

X1 Professional Client

Hands-on Exercise 1: VBA Coding Basics

WS_FTP Professional 12

CLC Server Command Line Tools USER MANUAL

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Setting Up the Site Licenses

While You Were Sleeping - Scheduling SAS Jobs to Run Automatically Faron Kincheloe, Baylor University, Waco, TX

GNU Make. A Program for Directing Recompilation GNU make Version 3.80 July Richard M. Stallman, Roland McGrath, Paul Smith

Creating a Simple Macro

Xcode User Default Reference. (Legacy)

Sybase Adaptive Server Enterprise

Moving from CS 61A Scheme to CS 61B Java

Understand for FORTRAN

While You Were Sleeping - Scheduling SAS Jobs to Run Automatically Faron Kincheloe, Baylor University, Waco, TX

Tutorial 3 Maintaining and Querying a Database

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Simply Accounting Intelligence Tips and Tricks Booklet Vol. 1

Access Tutorial 3 Maintaining and Querying a Database. Microsoft Office 2013 Enhanced

Hypercosm. Studio.

A Method for Cleaning Clinical Trial Analysis Data Sets

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Command Line Interface User Guide for Intel Server Management Software

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

RIT Installation Instructions

Access Queries (Office 2003)

DiskPulse DISK CHANGE MONITOR

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

OLH: Oracle Loader for Hadoop OSCH: Oracle SQL Connector for Hadoop Distributed File System (HDFS)

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

How To Set Up A Scopdial On A Pc Or Macbook Or Ipod (For A Pc) With A Cell Phone (For Macbook) With An Ipod Or Ipo (For An Ipo) With Your Cell Phone Or

Training Module 4: Document Management

KMx Enterprise: Integration Overview for Member Account Synchronization and Single Signon

SAS Macros as File Management Utility Programs

Job Cost Report JOB COST REPORT

InterBase 6. API Guide. Borland/INPRISE. 100 Enterprise Way, Scotts Valley, CA

Lecture 5: Java Fundamentals III

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

1001ICT Introduction To Programming Lecture Notes

7 Why Use Perl for CGI?

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

Intel System Event Log (SEL) Viewer Utility

SnapLogic Tutorials Document Release: October 2013 SnapLogic, Inc. 2 West 5th Ave, Fourth Floor San Mateo, California U.S.A.

Professional. SlickEdif. John Hurst IC..T...L. i 1 8 О 7» \ WILEY \ Wiley Publishing, Inc.

Microsoft Access 2010 Part 1: Introduction to Access

Data Presentation. Paper Using SAS Macros to Create Automated Excel Reports Containing Tables, Charts and Graphs

Mimer SQL. Programmer s Manual. Version 8.2 Copyright 2000 Mimer Information Technology AB

Importing and Exporting With SPSS for Windows 17 TUT 117

create-virtual-server creates the named virtual server

Offline Payment Methods

Paper An Introduction to SAS PROC SQL Timothy J Harrington, Venturi Partners Consulting, Waukegan, Illinois

PHP Integration Kit. Version User Guide

Essential Project Management Reports in Clinical Development Nalin Tikoo, BioMarin Pharmaceutical Inc., Novato, CA

CRM Global Search: Installation & Configuration

Command Line Interface Specification Linux Mac

Winsock RCP/RSH/REXEC for Win32. DENICOMP SYSTEMS Copyright? 2002 Denicomp Systems All rights reserved. INTRODUCTION...1 REQUIREMENTS...

The Basics of Querying in FoxPro with SQL SELECT. (Lesson I Single Table Queries)

Chapter 13 - The Preprocessor

A Transend Corporation White Paper Preparing Microsoft Exchange Server for Migration

Prescribed Specialised Services 2015/16 Shadow Monitoring Tool

Searching in CURA. mindscope Staffing and Recruiting Software

Evaluator s Guide. PC-Duo Enterprise HelpDesk v5.0. Copyright 2006 Vector Networks Ltd and MetaQuest Software Inc. All rights reserved.

Using ORACLE in the CSLab

3.GETTING STARTED WITH ORACLE8i

Informatica e Sistemi in Tempo Reale

FrontStream CRM Import Guide Page 2

ProxiBlue Dynamic Category Products

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

Introduction to UNIX and SFTP

Create a New Database in Access 2010

Data Tool Platform SQL Development Tools

TECHNICAL REFERENCE GUIDE

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

A database is a collection of data organised in a manner that allows access, retrieval, and use of that data.

The information presented in this manual is subject to change without notice.

Architecting the Future of Big Data

This is a training module for Maximo Asset Management V7.1. It demonstrates how to use the E-Audit function.

Transcription:

The make utility Basics make is a utility that helps keep the executable versions of programs current. It automatically updates a target file when changes are made to the files used to build the target. make keeps a target program up-to-date by reading a makefile and making the target selected from it. By default the makefile is named makefile. In its simplest form, a makefile is a sequence of explicit rules, each of the form (where brackets enclose optional parts): f: [f1... fn] [command1] [command2]... f is said to be the target of the rule and to directly depend on the sources f1...fn. Each command is a command for the shell from which make is invoked. A target is said to (indirectly) depend on g if one of its sources either is g or one indirectly depends on g. It is required that no target depend on itself (autodependency). Each target must appear in exactly one rule. To make a target f, make performs the following steps: 1: for each target f1 in sources of f s rule do 2: make f1; 3: if target file f does not exist or 4: f has no sources or 5: any source file is more recent than target file f or 6: any commands have been performed to make sources in step 2 7: then execute commands in f s rule (if any) Note that make performs a sort of postorder visit of the directed acyclic graph textually represented by the makefile s rules. make f fails ( don t know how to make f ) if f is not an existing file or a target for some rule or is a target for a rule with neither source nor commands. 1

Structure of rules Full explicit rules An explicit rule can also have multiple targets. This is equivalent to a set of rules, one for each target, having all the same body. The full syntax is: where: target [target]...: [[{path}] source]... [command] [command]... line separations are significant; blank lines are ignored; target must start in column 1; the first source must be preceded by at least one space or tab after the colon; commands must be indented, by some whitespace; target and source file names can contain complete path names and wildcards, path is a list of directories where make should look for the source following {path}. It is possible to have multiple explicit rules with the same target, followed by two colons. These tell make to expect and perform (rather than ignore) additional explicit rules for the current target. Implicit Rules Implicit rules apply to all files that have certain identifying extensions. The syntax is: [{source-dir}].source-extension.[{target-dir}]target-extension: [command]... This defines any file name.target-extension to be a target for file name.source-extension, for all name. Moreover: {source-dir} tells make to search for source files in source-dir; the period before source-extension must not be preceded by white space; {target-dir} tells make to place target files in source-dir To determine the sources for target name.t, make uses an implicit rule.s.t: if and only if: commands an explicit rule with target name.t either does not exist or has no commands, name.s exists as a file or is a target in an explicit or implicit rule of the makefile If no rule with target name.t exists, make behaves as with the explicit rule: 2

name.t: name.s commands If there is a rule with no commands name.t: sources make behaves as though this rule were: name.t: sources name.s commands If several implicit rules are eligible to make a target, make chooses the first, and make -N the last, unless a.suffixes directive gives a higher priority to the extension starting another implicit rule. Command Prefixes A command can take the following prefixes: @, -num, - and &. @ prevents make from displaying command before executing it. If command terminates with an error exit code err, make stops processing and deletes the current target file. With the prefix -num, this happens only if err num. With -, make does not stop. & causes make to execute the command that the $** or $? macros in an explicit rule expand to. Command Body The command body is any shell command. Borland C s make supports <, >, and >> redirection, but not pipes, and adds the << and && operators. The && operator is used for a command in a makefile thus: command args && line 1... line N moreargs This causes make to create a temporary file maken.$$$ and execute command args maken.$$$ moreargs Any character can be used as a delimiter in lieu of. The << operator is similar, but the temporary file acts as the standard input to the command. All temporary files are deleted unless make has a specific command line option. Comments and special characters indicates that the rest of the line is a comment. \ as the last character in a line acts as a line continuation character. (Does not apply to comments.) 3

Directives A makefile can contain the following directives: Name.autodepend.noautodepend!error!if!elif!else!endif!ifdef!ifndef!undef.ignore.noignore!include.path.ext.precious.silent.nosilent.swap.noswap.suffixes Action turns on autodependency checking causes make to stop and print an error message expressions with macros / C-like syntax depends on macro definitions forget definition for a specified macro ignore return value of a command specifies a file to include in the makefile path is searched for files with extension.ext do not delete specified target even if commands to build it fail do not print commands before executing them. (only for real mode make): swap make in and out of memory specifies a list of extensions Macros Macro definitions take the form macro-name = expansion-text where: macro-name should be a string of letters and digits with no whitespace in it. Case is significant in macros. There can be whitespace between macro-name and the equal sign. expansion-text is any arbitrary string containing letters, digits, whitespace, and punctuation. If macro-name has previously been defined, either by a macro definition in the makefile or by the -D option on the make command line, the new definition replaces the old. Macros are invoked in the makefile by: $(macro-name); parentheses are always needed, except for predefined macros) When make finds a macro invocation, it replaces the invocation by the macro s expansion-text. If the macro is not defined, make replaces it with the null string, or, if the macro name is a shell environment variable with the relevant definition string. 4

Macro expansion issues Macros cannot be invoked on the left side of a macro definition. They can be used on the right side, but they are not expanded until the macro being defined is invoked. Macro invocations are expanded immediately in rule lines. Macro invocations are expanded immediately in!if and!elif directives. If the macro being invoked in the directive is not currently defined, it is expanded to the value 0 (FALSE). Macro invocations in commands are expanded when the command is executed. The macro invocation $(macro-name:text1=text2) (no spaces around : and =) is replaced by the definition string for macro-name with every occurrence of text1 replaced by text2. Predefined macros make comes with the following built-in macros. Macro Expands To $d 1 if following macro name is defined; 0 if not $* base file name (no ext, with path, if generated) $< full file name (with ext, with path, if generated) $: file path (no name/ext) $. file name and extension (no path) $& file name only (no path, no ext) $@ full target name with path $** all dependents $? all out of date dependents MSDOS 1 if running make under DOS MAKE make s version number in hex MAKE make s executable filename FLAGS any options used on the make command line MAKEDIR directory from which make was run In an explicit/implicit rule $* $< $: $. $& refer to target/dependent. If there isn t a predefined filename macro to give the needed parts of a filename, macro modifiers can be used extract any part of a filename macro. The format is: $(macro[d F B R]) where the modifiers are: Mod What part of the filename Example D drive and directory $(<D) = C:\OBJS\ F base and extension $(<F) = BOB.OBJ B base only $(<B) = BOB R drive, directory, and base $(<R) = C:\OBJS\BOB Invoking make make [option option...] target target... 5

Command-line options are introduced by a - or a /. Case is significant. Option -? or -h prints a help message (default options followed by + -a automatic dependency check -B builds all targets regardless of file dates -ddir sets dir for swap file (must be used with -S -Didentifier defines identifier to string consisting only of character 1 -Diden=string defines iden to string (which cannot have whitespace) -e environment variables take precedence on macros with same name -ffilename makefile is filename, or filename.mak if filename does not exist and has no extension. The space after -f is optional -i continues regardless of exit status of commands -Idir search for include files in dir (in addition to current directory) -K do not delete temporary files -m display date and time stamp of each file as it is processed -n prints commands but do not perform them -N increase make s compatibility with Microsoft s nmake -P display macro definitions and implicit rules before executing makefile -r ignore builtins.mak -s do not print commands before executing -S Swaps real mode make out of memory while executing commands. This makes room for very large modules to be compiled. -Uidentifier undefines any previous definitions of identifier -W write current non-string command line options to make.exe Examples Builtins.mak CC = BCC AS = TASM RC = RC.asm.obj: $(AS) $(AFLAGS) $&.asm.c.exe: $(CC) $(CFLAGS) $&.c.c.obj: $(CC) $(CFLAGS) /c $&.c.cpp.obj: $(CC) $(CPPFLAGS) /c $&.cpp.rc.res: $(RC) $(RFLAGS) /r $&.suffixes:.exe.obj.asm.c.res.rc 6

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This makefile was generated by the utility PRJ2MAK.EXE PRJ2MAK converts project files (filename.prj) into.mak files. The.PRJ file for this example is in the EXAMPLES directory of the Container Class Library. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *.AUTODEPEND *Translator Definitions* CC = bcc +DIRECTRY.CFG TASM = TASM TLIB = tlib TLINK = tlink LIBPATH =..\..\LIB;..\LIB INCLUDEPATH =..\..\INCLUDE;..\INCLUDE *Implicit Rules*.c.obj: $(CC) -c {$< }.cpp.obj: $(CC) -c {$< } *List Macros* EXE_dependencies = \ directry.obj \ filedata.obj \ testdir.obj \..\lib\tclasss.lib *Explicit Rules* directry.exe: directry.cfg $(EXE_dependencies) $(TLINK) /v/x/c/p-/l$(libpath) @&& c0s.obj+ directry.obj+ filedata.obj+ testdir.obj directry no map file..\lib\tclasss.lib+ graphics.lib+ emu.lib+ maths.lib+ 7

cs.lib *Individual File Dependencies* directry.obj: directry.cfg directry.cpp filedata.obj: directry.cfg filedata.cpp testdir.obj: directry.cfg testdir.cpp *Compiler Configuration File* directry.cfg: directry.mak copy && -v -vi -w-ret -w-nci -w-inl -w-par -w-cpt -w-dup -w-pia -w-ill -w-sus -w-ext -w-ias -w-ibc -w-pre -w-nst -I$(INCLUDEPATH) -L$(LIBPATH) directry.cfg 8