Makefile for compiling multiple source files

Satish Balay balay at mcs.anl.gov
Mon May 14 10:31:01 CDT 2007


On Mon, 14 May 2007, Vijay M wrote:

> Hi,
> 
> I've been trying to use PETSc for one of my projects lately and I was
> wondering how to create the makefile to compile multiple source files
> with and without PETSc calls in fortran efficiently. I am sure it is a
> newbie question but I could not find much information about this
> anywhere.
> 
> For example, you could take 4 files. A.f90, B.f90 without petsc calls
> and C.f90 and D.f90 with petsc calls. If I were to compile them I have
> to use

If C, D are PETSc sources, then they should be C.F90, D.F90 [not .f90
sufix]

> 
> f90 -c A.f90 -o A.o
> f90 -c B.f90 -o B.o
> cpp C.f90 -I<include dir> > Ctemp.f90
> f90 -c Ctemp.f90 -o C.o
> cpp  D.f90 -I<include dir> > Dtemp.f90
> f90 -c Dtemp.f90 -o D.o
> 
> g77 <PETSC options> A.o B.o C.o D.o -o out.exe

this assumes A.o has the main subroutine - if not - you should list
the corresponding .o file first.

> 
> PETSc is configured to use g77 as the linker in my server but since I
> am compiling each file separately, I cannot quite use the linker
> directly (It treats the source as a linker script). Is there a
> simplified way to do this or have I missed something vital ?!


I'm attaching a suitable PETSc makefile for your config.

Satish

> I would appreciate any kind of help you can provide. If you need more
> information, let me know. Thanks.
> 
> vijay
> 
> 
-------------- next part --------------

CFLAGS	         =
FFLAGS	         =
CPPFLAGS         =
FPPFLAGS         =
CLEANFILES       = executable

include ${PETSC_DIR}/bmake/common/base

OBJS = A.o B.o C.o D.o

executable: ${OBJS}  chkopts
	-${FLINKER} -o executable ${OBJS} ${PETSC_LIB}
	${RM} ${OBJS}


More information about the petsc-users mailing list