# --------------------------------------------------------------------------- #
# Make file for Garfield, written for Linux.                                  #
# Author: Jeff Templon <templon@studbolt.physast.uga.edu>                     #
# Compilation options from Florin Cotorobai <Florin.Cotorobai@cern.ch>        #
# Based on a file from Michel Roethlisberger, IBM Switzerland.                #
# --------------------------------------------------------------------------- #
FC = g77
LF= `cernlib graflib/X11,kernlib,mathlib,packlib`
# FF= -O
FF= -O3 -malign-double -malign-loops=2 -malign-jumps=2 -malign-functions=2\
-fno-init-local-zero -ffast-math -fno-f2c\
-fforce-mem -fforce-addr -fcaller-saves -fstrength-reduce\
-funroll-loops -frerun-cse-after-loop \
 -g -fdebug-kludge
# G77_LIB_DIR=/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3
# LF=-m elf_i386 -dynamic-linker /lib/ld-linux.so.1 -s -x -L$(G77_LIB_DIR)
# LNKPRE=/usr/lib/crt1.o /usr/lib/crti.o $(G77_LIB_DIR)/crtbegin.o
# LNKEPI=-lf2c -lm -lgcc -lc -lgcc $(G77_LIB_DIR)/crtend.o /usr/lib/crtn.o
# LNKCERN=`/cern/pro/bin/cernlib graflib/X11,kernlib,mathlib,packlib`

garfield-7: main-7.o
	$(FC) -o garfield-7 *.o $(LF)
	rm *.o

main-7.o: main-7.f
	$(FC) -c $(FF) *.f
	rm *.f

main-7.f: garfield-7.f
	fcasplit garfield-7.f
	-rm garfield-7.f garfield-7.mkfca garfield-7.shfca y.lis
	mv main.f main-7.f

garfield-7.f: garfield-7.car magboltz-2.car heed101garf.car garfield-7.cra
	-rm *.f *.o
	./patchy_step garfield-7

libgarfield-7.a: garfield-7.f
	fcasplit garfield-7.f
	rm main.f garfield-7.f garfield-7.mkfca garfield-7.shfca y.lis
	$(FC) -c $(FF) *.f
	ar crv libgarfield-7.a *.o 
	ranlib libgarfield-7.a

garfield: main.o
	$(FC) -o garfield *.o $(LF)
	rm *.o

# garfield: main.o
#	ld $(LF) -o garfield  *.o $(LNKPRE) $(LNKCERN) $(LNKEPI)

main.o: main.f
	$(FC) -c $(FF) *.f
	rm *.f

# main.o: main.f
#	$(FC) -c *.f
#	rm *.f

main.f: garfield.f
	fcasplit garfield.f
	rm garfield.f garfield.mkfca garfield.shfca y.lis

garfield.f: garfield.car maggarf.car heed101garf.car garfield.cra
	-rm *.f *.o
	./patchy_step garfield

garfield.car:
	copy_garfield

maggarf.car:
	copy_maggarf

heed101garf.car:
	copy_heed

help: garfield.rawhelp
	-rm garfield.packhelp
	./garfield-7 -noinput -noterminal -metafile  < help_input
	rm garfield.metafile
 
interface: interface.a
	echo Done making interface.a.

interface.f: garfield.car interface.cra
	-rm interface.f
	patchy_step interface
	rm y.lis

interface.a: interface.f
	g77 -c $(FF) -o interface.o interface.f
	-rm interface.a
	ar -q interface.a interface.o
	ranlib interface.a
	rm interface.f
	rm interface.o
