Using Makefiles
Using the make utility facilitates the building
of executables
that contain many source and library dependencies. Use make
when you want to run code without a framework like
d0user. The
following documentation will provide a simple example of how to use
Makefiles to tell make how to compile and link code. For
more detailed information on Makefiles, click
here.
You might also look at the man pages for make.
The example:
(1) We want to compile source and create a library in some directory,
~usr/example/source
(2) We want to compile source and create another library in some other directory,
~usr/example/util_source
(3) We have a root directory ( ~usr/example ) where we want to create
an executable linking these two libraries with some other source and some
cernlib libraries.
In this example, we need three Makefiles; one in each directory. The
Makefiles in ~usr/example/source and ~usr/example/util_source
will be similar. Here's what one would look like:
% cat example/source/Makefile
#
# This make file will build the example library for general use
#
FFLAGS= -check_bounds # Put fortran compile flags here.
# For a list of commands, do a 'man f77'
all: example.a # This is the library we want to build.
lib_obj=src1.o src2.o src3.o src4.o \ # Here's the list of objects
src5.o src6.o # to create if needed.
example.a: $(lib_obj) # Here's how to build the library.
rm -f example.a # Commands are tab indented.
$(AR) cr example.a $(lib_obj)
src1.o: src1.f example.inc # Here's how to compile the code.
src2.o: src2.f
src3.o: src3.f junk.inc
src4.o: src4.f example.inc
src5.o: src5.f
src6.o: src6.f junk.inc
To execute the Makefiles, simply
% make Makefile
~usr/example/source/Makefile creates the library example.a.
Similarly, ~usr/example/source_util/Makefile might create the library
example_util.a. In our top level directory, we want to link these
libraries to our main source routine and create the executable text.x.
Our ~usr/example/Makefile might look like:
% cat example/Makefile
#
# Build the test program
#
all: test.x
libs = example/source/example.a /example/util_source/example_util.a
master_libs = $(d0cernlib)/mathlib.a $(d0cernlib)/kernlib.a
objs = test.o testsrc.o
test.x: $(libs) $(objs)
f77 -o test.x $(objs) $(libs) $(master_libs)
Tutorials |
E-Mailing |
Editing |
Getting Help
D0 HOME |
D0 At Work |
UNIX at D0
Last updated 11 June 1997
J. Perkins