Section 4.7. Make


4.7. Make

The make development tool in Linux is GNU Make. As of this writing, the latest version of GNU Make is 3.8, which this section is based on. The GNU Make home page is located at www.gnu.org/software/make/. Note that GNU Make 3.8 is also available on Solaris and can be downloaded from www.istec.org/sunfreeware/. Porting the build environment from Solaris to Linux means using GNU Make and making sure that the makefiles used to build the application are correctly ported to build all necessary application modules. Because both Solaris and GNU Make conform to the POSIX.2 standard, similarities between Solaris and GNU makefile syntax abound. However, there are still some differences, which are covered in this section. The first difference to take note of is the command-line switches. Table 4-9 shows a comparison between Solaris and GNU Make command-line switches.

Table 4-9. Make Command-Line Switches

Solaris Flag

GNU Make Equivalent

Description[15]

-d

-d

Displays the reasons why Make chooses to rebuild a target. Make displays any and all dependencies that are newer. In addition, Make displays options read in from the MAKEFLAGS environment variable.

-dd

N/A

Displays the dependency check and processing in vast detail.

-D

N/A

Displays the text of the makefiles read in.

-DD

N/A

Displays the text of the makefiles, make.rules file, and all hidden-dependency reports.

-e

-e

Environment variables override assignments within makefiles.

-f makefile

-f makefile

Uses the specified makefile.

-i

-i

Ignores error codes returned by commands.

-k

-k

When a nonzero error status is returned by a rule, or when Make cannot find a rule, abandons work on the current target, but continues with other dependency branches that do not depend on it.

-K statefile

N/A

Uses the state file statefile.

-n

-n

No execution mode. Prints commands, but does not execute them. Even lines beginning with an @ are printed. However, if a command line contains a reference to the $(MAKE) macro, that line is always executed. When in POSIX mode, lines beginning with a + are executed.

-p

-p

Prints the complete set of macro definitions and target descriptions.

-P

N/A

Only reports dependencies, rather than building them.

-q

-q

Question mode.

-r

-r

Does not read in the default makefile /usr/share/lib/make/make.rules.

-s

-s

Silent mode. Does not print command lines before executing them. Equivalent to the special-function target .SILENT:.

-S

-S

Undoes the effect of the -k option. Stops processing when a nonzero exit status is returned by a command.

-t

-t

Touches the target files (bringing them up to date) rather than performing their rules. Warning: This can be dangerous when files are maintained by more than one person. When the .KEEP_STATE: target appears in the makefile, this option updates the state file just as if the rules had been performed. When in POSIX mode, lines beginning with a + are executed.

-V

N/A

Puts make into SysV mode.


[15] Solaris man pages

4.7.1. Built-In Makefile Variables for C++

The built-in makefile variable to specify a default C++ compiler in Solaris native Make is CCC, whereas for the GNU Make it is CXX. Similarly, the default compiler flag changes from CCFLAGS to CXXFLAGS.

4.7.2. Library Dependencies

On Solaris, a target name of the form lib(( symbol )) refers to the member of a randomized object library that defines the entry point named symbol. The GNU Make equivalent is lib(file.o).

4.7.3. Empty Rules

Empty rules are suffix rules specified without a command. To specify an empty rule in GNU Make, put a semicolon immediately after the dependency:

Solaris:

.c.a:

GNU:

Make: .c.a:;


4.7.4. Current Targets

In Solaris makefiles, the symbol $$@ is used in a dependency list to refer to the current target:

Solaris:

$(targets):$$@.o


In GNU Make, you have to use the following:

GNU Make:

$(targets):%:%.o


4.7.5. SCCS and RCS Files

Suffix rules that handle System V makefiles to support SCCS files that contain ~ are not recognized by GNU Make. In Solaris, the suffix rule .c~.o creates the file x.o from the SCCS file s.n.c. GNU Make handles SCCS and RCS files differently by applying two pattern rules for extraction from SCCS or RCS in combination with general rules of rule chaining.

4.7.6. Conditional Macro Assignment

$(targets) := special_flags = -g 


On Solaris, when any target in $(targets) is processed, set $(special_flags) equal to -g. The equivalent on Linux is this:

$(targets) : special_flags= -g 


4.7.7. Pattern-Replacement Macro References

Solaris allows any number of percent metacharacters to appear after the equal sign. On the other hand, Linux only allows one. Here is an example:

ORG=one two NEW=$(ORG:%=integer/%.o integer/%_backup.o) all:       @echo ORG is $(ORG)       @echo NEW is $(NEW) 


On Solaris, the output from the make command is as follows:

ORG is one two NEW is integer/one.o integer/one_backup.o integer/two.o integer/two_backup.o 


For Linux, you will get this output instead:

ORG is one two NEW is integer/one.o integer/%_backup.o integer/two.o integer/%_backup.o 


A possible workaround for Linux is this:

NEW=$(ORG:%=integer/%.o) $(ORG:%=integer/%_backup.o) 


4.7.8. VPATH

If a target or a dependency file is found using VPATH, any occurrences of the word that is the same as the target name in the subsequent rules will be substituted with the actual name of the target derived from VPATH. For example:

VPATH=./subdir foo.o : foo.c       cc -c foo.c -o foo.o 


On Solaris, if file.c is located in ./subdir, the following command will be executed:

cc -c ./subdir/foo.c -o foo.o 


However, on Linux, this command will be executed instead:

cc -c foo.c -o foo.o 


4.7.9. Command Execution

Solaris Make invokes the shell with the -e argument. This flag instructs the shell to exit immediately if any program it runs returns a nonzero status. This is not true for GNU Make. However, with the -S option in GNU Make, we can achieve the same effect.

4.7.10. Special Targets

Special targets are called by different names on various platforms. In Solaris, they are called special-function targets. In GNU Make, they are called special built-in targets. When special targets are incorporated in a makefile, they perform special functions. Consult the GNU Make manual for the meaning of special targets.

Table 4-10 compares the special targets on Solaris and GNU.

Table 4-10. Special Targets

Special Target

Solaris

GNU

.DEFAULT

Yes

Yes

.DELETE_ON_ERROR

No

Yes

.DONE

Yes

No

.EXPORT_ALL_VARIABLES

No

Yes

.FAILED

Yes

No

.GET_POSIX

Yes

No

.IGNORE

Yes

Yes

.INIT

Yes

No

.INTERMEDIATE

No

Yes

.KEEP_STATE

Yes

No

.KEEP_STATE_FILE

Yes

No

.LOW_RESOLUTION_TIME

No

Yes

.MAKE_VERSION

Yes

No

.NOTPARALLEL

No

Yes

.NO_PARALLEL

Yes

No

.PARALLEL

Yes

No

.PHONY

No

Yes

.POSIX

Yes

No

.PRECIOUS

Yes

Yes

.SCCS_GET

Yes

No

.SCCS_GET_POSIX

Yes

No

.SECONDARY

No

Yes

.SILENT

Yes

Yes

.SUFFIXES

Yes

Yes

.WAIT

Yes

No


4.7.11. Environment Variables

Here we list environment variables that affect the execution of GNU Make and Solaris Make. Table 4-11 compares environment variables between Solaris and Linux.

Table 4-11. Make Environment Variables

Variable

Solaris

GNU

KEEP_STATE

Yes

No

USE_SVR4_MAKE

Yes

No

MAKEFLAGS

Yes

Yes

PROJECTDIR

Yes

No

VPATH

No[16]

Yes


[16] VPATH is a special-purpose macro in Solaris.

4.7.12. Exit Status

Table 4-12 provides the differences between Make exit status on Solaris and Linux.

Table 4-12. Make Exit Status
 

With -q Solaris

GNU

without -q Solaris

GNU

Successful completion

0

0

0

0

The target was not up-to-date

1

1

An error occurred

>1

2

>0

2





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