make and Makefile

 

What is make?

 

Make is a tool which controls the generation of executables of a program from the program's source files.

 

Make gets its knowledge of how to build your program from a file called the makefile.

 

Comments

 

Comments are any text beginning with the pound (#) sign. A comment can start anywhere on a line and continue until the end of the line. For example:

 

# This program is used for preprocessing.

 

Macros

 

Macros are defined in a Makefile as = pairs. For example:

 

F77= pathf90

F90= pathf90

CC= gcc

C++= c++

CFLAGS= -c -O -lm

FFLAGS= -O3 -fftw3

 

Environment variables (variables defined in Linux Shell) are exported into the make as macros.

 

Make rules and targets

 

Target: dependencies

            commands

           

 

For example:

 

fft: fft.f90

       $(F90) fft.f90 o fft $(FFLAGS)

 

 

Continuation of lines

 

run:

            mpirun -np 1 -nolocal -machinefile machine `which smva.x` \

par=parmig propagator=ssft tilt=1                                     \

            input_prefix='../vel/vrotate/v' input_suffix='.bin'                  \

output_prefix='image/image' output_suffix='.bin'

 

 

 

Examples

 

Makefile for program compilation:

 

FCC = ifort

OBJ = segy.o reader.o datatype.o sinc.o io.o math.o util.o

FFTW3LIB=/home/hgrg/appli/UTILITIES2/fftw-3.1/intel-8.1/i686/

FFTW=/home/t02654/FFTW/i686

MPIROOT=/home/hgrg/appli/UTILITIES2/mpich-1.2.6/intel-8.1/i686/

LIB = $(MPIROOT)/lib/

INCLUDE = $(MPIROOT)/include/

FLAGS = -c

 

 

all : fft_wvfld.x combine.x convel.x transpose.x encode.x

 

%.x: $(OBJ) %.o

            $(FCC) -o $@ $^ -L$(FFTW)/lib -lfftw3f -L$(LIB) -lmpich \

-lmpichf90 -lmpichf90nc

            mv $@ $(BIN)

 

%.o: %.f

            $(FCC) $(FLAGS) $< -I$(FFTW)/include -I$(INCLUDE)

 

%.o: %.f90

            $(FCC) $(FLAGS) $< -I$(FFTW)/include -I$(INCLUDE)

 

clean :

            rm -f *.o

 

 

Makefile for a step-by-step process:

 

run: fft encode migrate visualize

 

fft:

            fft_data input=csg.bin nt=2000 dt=0.001 ng=500 ns=300 output=csg_fft.bin \

            f_min=5 f_max=30

 

encode:

            encoding input=csg_fft.bin nw=110 np=100 pmax=70 output=csg_encode.bin

 

migrate:

            wem input=csg_encode.bin nw=110 nx=500 np=110 output=image.bin

 

visualize:

            ximage < image.bin n1=500 perc=99&