creating a library



Hello friends,
This is not really a fortran problem, but more a unix problem, i
guess.
I want to use a standard code as library. The corresponding makefile
is:

##################################################################
#
# makefile for updating LMTO-program system.
#
# done by getmakefile
#
# version 25.02.1997 g.k. and a.b.
#
##################################################################
#
# compiler to be used:
FC=ifort
CC=cc
#
# compiler options
FFLAGS = -O2 #-g -w
CCFLAGS =
PGFLAGS= -lX11 -lm /usr/local/server/pgplot/AIX/libpgplot.a
#
#
# maybe this path must be adapted
#
LMPATH = ./
#
#PROGRAMS = lm.run lmstr.run lmhart.run lmbnd.run lmdos.run
\
lmovl.run lmclean.run lmctl.run lmes.run lmscell.run
\
lmnghbr.run lminit.run gnudos.run


# SUBDIRS = ATOM BLAS BNDASA DENS EISP EXTENS FINDES HARTREE
IOLIB \
IOCTRL LATTICE LINP LMIO MAD MAINA RHONS SAMPLE SYM
\
TBSTR TETRA
#
# Here all single object-files e.g., atomsc.o,...
# in a directory e.g., ATOM are referred by a single name
# e.g. ATOMOBJ ,which is called a object-group.
# In princip here each single subroutine used in one of the
# programs should be listed below.
#
ATOMOBJ= ATOM/atetot.o ATOM/atompp.o ATOM/atomsc.o \
ATOM/atscet.o ATOM/dfphi.o ATOM/enutpp.o ATOM/fctp.o \
ATOM/fctp0.o ATOM/getq.o ATOM/gintsr.o ATOM/initec.o \
ATOM/mixrho.o ATOM/mkcoef.o ATOM/mkgfac.o ATOM/mkrhot.o \
ATOM/mkrofi.o ATOM/mktauc.o ATOM/newrho.o ATOM/norm1g.o \
ATOM/perdew.o ATOM/phidot.o ATOM/poiss0.o ATOM/polcoe.o \
ATOM/potpar.o ATOM/radgra.o ATOM/rhocor.o ATOM/rmesh.o \
ATOM/rseq.o ATOM/rsq1.o ATOM/rsq2.o ATOM/xcepmu.o \
ATOM/xcloc1.o ATOM/xcloc2.o ATOM/xcnlc1.o ATOM/xcnlc2.o \
ATOM/xcpot.o ATOM/xperdew.o ATOM/optical.o ATOM/atompp1.o \
ATOM/potpar1.o
#
#
BLASOBJ= BLAS/dasum.o BLAS/daxpy.o BLAS/dcopy.o \
BLAS/ddot.o BLAS/dscal.o BLAS/dsum.o BLAS/dswap.o \
BLAS/idamax.o BLAS/isum.o
#
#
BNDASAOBJ= BNDASA/atfold.o BNDASA/bandwt.o BNDASA/bloch.o \
BNDASA/bndasa.o BNDASA/chkafm.o BNDASA/copafm.o BNDASA/diagno.o \
BNDASA/efrang.o BNDASA/hmltnm.o BNDASA/hmltns.o BNDASA/i3cnto.o \
BNDASA/i3cntr.o BNDASA/makbet.o BNDASA/makdia.o BNDASA/makdsd.o \
BNDASA/makidx.o BNDASA/makipt.o BNDASA/makoal.o BNDASA/makovc.o \
BNDASA/makpph.o BNDASA/makrcz.o BNDASA/makvec.o BNDASA/makwts.o \
BNDASA/mkbdot.o BNDASA/mkbnds.o BNDASA/moment.o BNDASA/ortrep.o \
BNDASA/pptrns.o BNDASA/secmat.o BNDASA/shffle.o BNDASA/trs.o \
BNDASA/trsdot.o BNDASA/veloc.o
#
#
DENSOBJ= DENS/addcor.o DENS/dcon.o DENS/dens.o \
DENS/densym.o DENS/fifido.o DENS/fmesh.o DENS/getvec.o \
DENS/locato.o DENS/maktrm.o DENS/mto.o DENS/rasgen.o \
DENS/trmat.o DENS/xgx.o
#
#
EISPOBJ= EISP/bbak.o EISP/bchd.o EISP/binvit.o \
EISP/bred.o EISP/btribk.o EISP/btridi.o EISP/imtql2.o \
EISP/imtqlv.o
#
#
EXTENSOBJ= EXTENS/ainit.o EXTENS/amix.o EXTENS/bessl.o \
EXTENS/bessl2.o EXTENS/chinit.o EXTENS/chkher.o EXTENS/cpusrt.o \
EXTENS/d1mach.o EXTENS/dcsevl.o EXTENS/delsqf.o EXTENS/derfc.o \
EXTENS/di3int.o EXTENS/dinit.o EXTENS/dmpy.o EXTENS/dpmpy.o \
EXTENS/dshel2.o EXTENS/dshell.o EXTENS/etime.o EXTENS/findsq.o \
EXTENS/i1mach.o EXTENS/icopy.o EXTENS/iinit.o EXTENS/initds.o \
EXTENS/ishel2.o EXTENS/ishell.o EXTENS/ivers.o EXTENS/linit.o \
EXTENS/ll.o EXTENS/mytime.o EXTENS/sylm.o EXTENS/sylmnc.o \
EXTENS/vmem.o EXTENS/wkinit.o EXTENS/ympy.o EXTENS/zcconj.o \
EXTENS/zerfc.o EXTENS/zhmul.o EXTENS/zmul.o EXTENS/zmult.o
#
#
FINDESOBJ= FINDES/addes.o FINDES/bigges.o FINDES/chkes.o \
FINDES/distes.o FINDES/fillat.o FINDES/findes.o FINDES/mdesat.o \
FINDES/mdeses.o FINDES/rsmesh.o FINDES/symes.o
#
#
HARTREEOBJ= HARTREE/freeat.o HARTREE/getwsr.o HARTREE/nghbr2.o \
HARTREE/potmax.o HARTREE/potsum.o HARTREE/potxn.o
#
#
IOLIBOBJ= IOLIB/chcase.o IOLIB/chrpos.o IOLIB/disply.o \
IOLIB/errmsg.o IOLIB/fexit.o IOLIB/finits.o IOLIB/fopna.o \
IOLIB/getcat.o IOLIB/getfmt.o IOLIB/ietol.o IOLIB/initlg.o \
IOLIB/iprint.o IOLIB/lcnvt.o IOLIB/lscat.o IOLIB/lsequ.o \
IOLIB/parstr.o IOLIB/partok.o IOLIB/query.o IOLIB/rdstrn.o \
IOLIB/skipbl.o IOLIB/strcat.o IOLIB/strcop.o IOLIB/strcp2.o \
IOLIB/tocast.o IOLIB/wrcast.o
#
#
IOCTRLOBJ= IOCTRL/ctrlbz.o IOCTRL/ctrlch.o IOCTRL/ctrlcl.o \
IOCTRL/ctrldm.o IOCTRL/ctrlds.o IOCTRL/ctrles.o IOCTRL/ctrlew.o \
IOCTRL/ctrlhd.o IOCTRL/ctrlht.o IOCTRL/ctrlio.o IOCTRL/ctrlop.o \
IOCTRL/ctrlpl.o IOCTRL/ctrlrf.o IOCTRL/ctrlsc.o IOCTRL/ctrlsg.o \
IOCTRL/ctrlsi.o IOCTRL/ctrlsl.o IOCTRL/ctrlsr.o IOCTRL/ctrlst.o \
IOCTRL/ctrlsy.o IOCTRL/ctrluc.o IOCTRL/ctrlvs.o IOCTRL/ctrlxx.o \
IOCTRL/getcls.o IOCTRL/ioctrl.o
#
#
LATTICEOBJ= LATTICE/bsort1.o LATTICE/bsort2.o LATTICE/bzmesh.o \
LATTICE/c2plat.o LATTICE/cosvec.o LATTICE/cpplat.o LATTICE/cross.o \
LATTICE/curcar.o LATTICE/curpol.o LATTICE/cvplat.o LATTICE/d3nrm2.o \
LATTICE/danrm2.o LATTICE/ddet33.o LATTICE/dinv33.o LATTICE/drr2.o \
LATTICE/getirr.o LATTICE/gtpmin.o LATTICE/latlim.o LATTICE/latpar.o \
LATTICE/latrel.o LATTICE/lattc.o LATTICE/latvec.o LATTICE/lctoff.o \
LATTICE/lgen.o LATTICE/makirr.o LATTICE/mkplat.o LATTICE/nrmliz.o \
LATTICE/prodln.o LATTICE/reducv.o LATTICE/roplat.o LATTICE/stplat.o
#
#
LINPOBJ= LINP/cdiv.o LINP/dcabs2.o LINP/dgedi.o \
LINP/dgefa.o LINP/dgesl.o LINP/dspfa.o LINP/dspsl.o \
LINP/iyamax.o LINP/yhifa.o LINP/yhisl.o
#
#
LMIOOBJ= LMIO/aiocor.o LMIO/aiogen.o LMIO/aiomom.o \
LMIO/aioovc.o LMIO/aiopar.o LMIO/aiophi.o LMIO/aiopot.o \
LMIO/aiorho.o LMIO/aiotau.o LMIO/ioband.o LMIO/iobnd2.o \
LMIO/iodmat.o LMIO/iodos.o LMIO/iostr.o LMIO/iostr2.o \
LMIO/rdcor.o LMIO/rdctrl.o LMIO/rdferm.o LMIO/rdphi.o \
LMIO/rdpot.o LMIO/rdrho.o LMIO/wrbnds.o LMIO/wrif3d.o \
LMIO/wrlmfs.o LMIO/wrmatc.o LMIO/wrsyml.o LMIO/wrteig.o \
LMIO/writepp.o LMIO/wrmom1.o LMIO/wrmom2.o LMIO/wrmom_atom.o \
LMIO/wrmom_mix.o LMIO/writves1.o LMIO/writves2.o LMIO/wrmom3.o
#

MADOBJ= MAD/kalph1.o MAD/kewald.o MAD/madmat.o \
MAD/madpot.o MAD/maksk.o MAD/mstrx4.o MAD/strx00.o


MAINAOBJ= MAINA/allocm.o MAINA/atmoms.o MAINA/avwsr.o \
MAINA/blowup.o MAINA/broyden.o MAINA/bzlabs.o MAINA/chkdis.o \
MAINA/chkwsr.o MAINA/defcnf.o MAINA/defidn.o MAINA/deflmx.o \
MAINA/defmom.o MAINA/defpp.o MAINA/defsyl.o MAINA/defwsr.o \
MAINA/enutcg.o MAINA/freebn.o MAINA/fremom.o MAINA/frewsr.o \
MAINA/frstbz.o MAINA/getmtz.o MAINA/gtname.o MAINA/iclbas.o \
MAINA/makbk.o MAINA/mixpq.o MAINA/mixpqa.o MAINA/mixpqb.o \
MAINA/nghbr1.o MAINA/nghbr3.o MAINA/ovlchk.o MAINA/renam.o \
MAINA/sclwsr.o MAINA/smclas.o MAINA/supcel.o MAINA/timres.o \
MAINA/volsph.o MAINA/wribas.o MAINA/xxcell.o MAINA/xxcls.o \
MAINA/zclabl.o
#
#
RHONSOBJ= RHONS/getcof.o RHONS/getdof.o RHONS/geteps.o \
RHONS/gtemom.o RHONS/momsym.o RHONS/rhofit.o RHONS/rhons.o
#
#
SAMPLEOBJ= SAMPLE/delstp.o SAMPLE/inswts.o SAMPLE/sfermi.o \
SAMPLE/spldos.o SAMPLE/splnos.o SAMPLE/splwts.o
#
#
SYMOBJ= SYM/addbas.o SYM/adjust.o SYM/bravsy.o \
SYM/chkcel.o SYM/chkcls.o SYM/chksym.o SYM/cnvsop.o \
SYM/cnvvec.o SYM/compop.o SYM/copyop.o SYM/gengrp.o \
SYM/gtcsym.o SYM/gtorig.o SYM/makgen.o SYM/multop.o \
SYM/nwplat.o SYM/ordbas.o SYM/ordcls.o SYM/pntgrp.o \
SYM/rotlat.o SYM/rotmat.o SYM/shifto.o SYM/shosym.o \
SYM/spcgrp.o SYM/symcry.o SYM/symlat.o
#
#
TBSTROBJ= TBSTR/addtos.o TBSTR/afromd.o TBSTR/alwats.o \
TBSTR/f100.o TBSTR/f102.o TBSTR/gndiml.o TBSTR/makdna.o \
TBSTR/makdni.o TBSTR/maked.o TBSTR/maksp0.o TBSTR/mkalph.o \
TBSTR/mkdiag.o TBSTR/mkisd1.o TBSTR/mkisd2.o TBSTR/mknalp.o \
TBSTR/mktral.o TBSTR/mstrx2.o TBSTR/mstrx3.o TBSTR/nghbr0.o \
TBSTR/sadot0.o TBSTR/salph0.o TBSTR/salph1.o TBSTR/scals.o \
TBSTR/scg.o TBSTR/shoorb.o TBSTR/shostr.o TBSTR/sitab.o \
TBSTR/strrs.o TBSTR/symstr.o TBSTR/writef.o TBSTR/xival.o \
TBSTR/print4h.o
#
#
TETRAOBJ= TETRA/ccutup.o TETRA/fswgts.o TETRA/mxmymz.o \
TETRA/sliny.o TETRA/slinz.o TETRA/symwgt.o TETRA/tetdos.o \
TETRA/tetirr.o TETRA/tetnos.o TETRA/tetwts.o TETRA/tfermi.o
#
#
#PLOTOBJ= PLOT/chrpos.o PLOT/getorb.o PLOT/getrot.o \
PLOT/getwts.o PLOT/kintg.o PLOT/kvec.o PLOT/lsequ.o \
PLOT/parstr.o PLOT/plot.o PLOT/point2.o PLOT/rband.o \
PLOT/rotate.o PLOT/skipbl.o PLOT/sshel2.o PLOT/strcop.o \
PLOT/strcp2.o PLOT/symbol.o PLOT/trapez.o PLOT/xrot.o \
PLOT/yrot.o PLOT/zrot.o
#
#
#
# Now the object files for the individual programs are
# referred under a single name e.g., lmstrobj.
# Normally not all object-groups are necessary in this list,
# they may be deleted if none of their object-files is used
# in the program.
#
lmobj=\
$(ATOMOBJ) $(BLASOBJ) $(BNDASAOBJ) $(DENSOBJ)\
$(EISPOBJ) $(EXTENSOBJ) $(FINDESOBJ) $(HARTREEOBJ)\
$(IOLIBOBJ) $(IOCTRLOBJ) $(LATTICEOBJ) $(LINPOBJ)\
$(LMIOOBJ) $(MADOBJ) $(MAINAOBJ) $(RHONSOBJ)\
$(SAMPLEOBJ) $(SYMOBJ) $(TBSTROBJ) $(TETRAOBJ)
#
# now define dependencies and activities
#
..f.o:
$(FC) -c $(PREFLAGS) $(FFLAGS) $<
mv $(*F).o $(*D)
#
..c.o:
$(CC) $(CCFLAGS) -c $<
mv $(*F).o $(*D)


liblm.a:MAIN/lm.f $(lmobj)
$(FC) $(LFLAGS) MAIN/lm.f $(lmobj)
ar r liblm.a lm.o $(lmobj)

what i want to do is to change the "main" of the code, lm.f to a
subroutine so that the library is callable from my other program. So,
this make file do not contain any "main".
while make-ing, i am getting following error:

In function `main':
/users/nbtester/x86linux_nightly/branch-11_0/20090319_000000/libdev/
frtl/src/libfor/for_main.c:(.text+0x4d): undefined reference to
`MAIN__'
make: *** [liblm.a] Error 1

If i am keeping lm.f as the main, it is not showing this problem, but
i can not call this library. So, what is the way out?
.