Section 5.4. Make


5.4. Make

The make utility sorts out dependency relations between files, automatically determines which pieces need to be recompiled, and issues commands to recompile them. It is the biggest contribution to the UNIX development environment dating back to System V enabling easy management of large program projects. Over the years, make has been changed and enhanced. AIX still uses a version of the UNIX System V make, which is not compatible in Linux. To build code in Linux, you must use the GNU Make (gmake), which is part of the FSF GNU GCC (GNU Compiler Collection). The GNU Make includes enhanced features that are not included in the traditional make.

5.4.1. gmake Condition Statements

One of the most useful features that gmake has and regular make does not is the use of conditional statements. Example 5-1 examines this useful feature.

Example 5-1. GNU Makefile

# Gnu Makefile  CC = gcc  CXX = g++  Objects = main.o  Target = main  Source = main.c  main : $(Source) #22 ifeq ($(Source),main.c)   $(CC) -o $(Target) $(Source) #24 else   $(CXX) -o $(Target) $(Source) #26 endif 

The traditional AIX make generates the following errors:

/: > make "Makefile", line 22: make: 1254-055 Dependency line needs colon or double colon operator. "Makefile", line 24: make: 1254-055 Dependency line needs colon or double colon operator. "Makefile", line 26: make: 1254-055 Dependency line needs colon or double colon operator. make: 1254-058 Fatal errors encountered -- cannot continue. 


The same makefile builds fine with GNU Make. For a list of other enhancements, visit the official GNU home page (at the time of this writing www.gnu.org/software/make/manual/make.html).




UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175

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