next up previous contents index
Next: Writing the C Client Up: Minimal Makefiles: static linked Previous: Writing the C++ Implementation   Contents   Index


Writing the Fortran 90 Implementation

Before writing the client, let's generate a Fortran implementation as well. It is highly instructive to see how the makefiles differ between the different language bindings. From within the minimal/libCxx directory we do.

% cd ../libF90
% babel -sF90 ../../hello.sidl

This time there's even more files generated (Fortran 90 bindings are harder after all), and we need to add our implementation to the Hello_World_Impl.F90 file. The modified code will look like this.


   1 !
   2 ! Method:  getMsg[]
   3 !
   4 
   5 recursive subroutine Hello_World_getMsg_mi(self, retval, exception)
   6   use sidl
   7   use sidl_BaseInterface
   8   use sidl_RuntimeException
   9   use Hello_World
  10   use Hello_World_impl
  11   ! DO-NOT-DELETE splicer.begin(Hello.World.getMsg.use)
  12   ! Insert-Code-Here {Hello.World.getMsg.use} (use statements)
  13   ! DO-NOT-DELETE splicer.end(Hello.World.getMsg.use)
  14   implicit none
  15   type(Hello_World_t) :: self ! in
  16   character (len=*) :: retval ! out
  17   type(sidl_BaseInterface_t) :: exception ! out
  18  
  19 ! DO-NOT-DELETE splicer.begin(Hello.World.getMsg)
  20 retval='Hello from Fortran 90!'
  21 ! DO-NOT-DELETE splicer.end(Hello.World.getMsg)
  22 end subroutine Hello_World_getMsg_mi
  23  

Note that the C function appears as a subroutine in Fortran. What was the return value appears here as the argument retval (line 5). For Fortran 90 there are also two splicer blocks per subroutine, one for use statements (lines 11-13) and another for the actual implementation (lines 19-21). This is where we put our implementation by setting retval to the string we want.

There are important differences in this Makefile from the C++ implementation, so we reproduce it in its entirety here.


   1 # A minimal makefile for Fortran 90 Babel Impl
   2 # Assumes babel-config is in the current path
   3 # Assumes babel -sF90 ../../hello.sidl is already run
   4 
   5 include babel.make
   6 
   7 OBJS = $(IORSRCS:.c=.o) $(TYPEMODULESRCS:.F90=.o) \
   8 	$(SKELSRCS:.c=.o) $(STUBMODULESRCS:.F90=.o) $(STUBSRCS:.c=.o) \
   9 	$(IMPLMODULESRCS:.F90=.o) $(IMPLSRCS:.F90=.o) 
  10 
  11 all: libhello.a	
  12 
  13 .SUFFIXES:
  14 .SUFFIXES: .F90 .c .o
  15 .F90.o:
  16 	gcc -E -traditional -P -o $*.tmp -x c  \
  17 		`babel-config --includes-f90` $<
  18 	sed -e 's/^#pragma.*$$//' < $*.tmp > $*.f90
  19 	gfortran -c -o $@ `babel-config --includes-f90-mod` $*.f90
  20 	rm -f $*.f90 $*.tmp
  21 
  22 .c.o:
  23 	gcc `babel-config --includes` `babel-config --includes-f90` -c $< 
  24 
  25 libhello.a: $(OBJS)
  26 	ar cru $@ $(OBJS) 
  27 	ranlib $@
  28 
  29 .PHONY:  clean new
  30 
  31 clean:
  32 	$(RM) *.o *.mod *~ babel.make.depends babel.make.package
  33 
  34 new: clean
  35 	$(RM) $(IORHDRS) $(IORSRCS) $(TYPEMODULESRCS) $(SKELSRCS) \
  36 	$(STUBMODULESRCS) $(STUBSRCS) $(STUBHDRS) libhello.a

line 5:
Again Babel will generate a babel.make file, but we will see that its contents are different.
lines 7-9:
Are building a $(OBJS) variable like before, but this time we see suffix substitutions for more kinds of files. We caution the reader that Fortran 90's use of MOD files5.4 makes the ordering of these items very important. (Not Babel's fault, blame the Fortran 90 language designers.) C/C++ has no such constraint on the order that individual units of compilation are performed. As long as Fortran 90 programmers stick with the ordering shown in these lines, they should not encounter compiler complaints about dependent MOD files not found.
lines 16-20:
This bit of code admittedly looks very strange, but the explanation is simple. We preprocess our Fortran 90 source to workaround the 31 character limit specified in the language. Check out Chapter 9 for more details about this issue.
lines 17 & 19:
Note that we use babel-config to generate the proper flag for the preprocessor to find the Babel Fortran headers, and the compiler to find the Babel MOD files.
line 23:
When compiling C source in this directory, we use babel-config to generate include directives for both the default (C) and Fortran include directories.
lines 25-end:
The rest of the makefile is almost identical. Note that we do not clean up the Hello_World_Mod.F90 or the CodeHello_World_Impl.F90 files.

Again, we simply type make, and should end up with another libhello.a file.


next up previous contents index
Next: Writing the C Client Up: Minimal Makefiles: static linked Previous: Writing the C++ Implementation   Contents   Index


babel-0.99.0
users_guide Last Modified 2006-06-27

http://www.llnl.gov/CASC/components
components@llnl.gov