#============================================================
# Makefile to compile modified 5.20 version of CORSIKA.
#
# Copyright (c) J C Gonzalez, 1998
#============================================================
#
# Modified by C. Bigongiari  2001-11-06 to handle two different 
# codes for Linux and Alpha.
# Now it compiles/link Corsika version 6.005 
#
#==============================================================

DESTDIR = .

F77 = f77
CC = cc
CERNDIR = CERN
ADDFLAGS =

EXE_VERSION = c614nx

###
#   compiler & linker options section
###

# machine dependencies
SYSTEM = GENERIC

## generic (alpha)
GENERIC_CFLAGS   = -I. -I/usr/include -DJC_UNDERSCORES ${ADDFLAGS}
GENERIC_FFLAGS   = ${GENERIC_CFLAGS}
GENERIC_EXE      = ${EXE_VERSION}-generic
GENERIC_LIBS     = -lm -lc
GENERIC_CC       = cc
GENERIC_F77      = f77
GENERIC_SRC      = c614nx-osf.f 

## osf (alpha)
OSF_CFLAGS   = -I. -I/usr/include -DJC_UNDERSCORES ${ADDFLAGS}
OSF_FFLAGS   = ${OSF_CFLAGS}
OSF_EXE      = ${EXE_VERSION}-osf
OSF_LIBS     = -lm -lc
OSF_CC       = cc
OSF_F77      = f77   
OSF_SRC      = c614nx-osf.f  

## linux
LINUX_CFLAGS = -I. -I/usr/include -funderscoring -DJC_UNDERSCORES \
		-m486 -DCPU=686 ${ADDFLAGS}
LINUX_FFLAGS = ${LINUX_CFLAGS}
LINUX_EXE    = ${EXE_VERSION}-linux
LINUX_LIBS   = -lm -lc
LINUX_CC     = gcc
LINUX_F77    = g77
LINUX_SRC    = c614nx-linux.f 

# choose this machine values
F77    = ${${SYSTEM}_F77}
CC     = ${${SYSTEM}_CC}
CFLAGS = ${${SYSTEM}_CFLAGS}
FFLAGS = ${${SYSTEM}_FFLAGS}
LIBS   = ${${SYSTEM}_LIBS}
SRC    = ${${SYSTEM}_SRC}

###
#   miscelanea
###

CERNDIR = CERN

###
#   files section
###

HEADERS =

FSRCS = \
	gheisha600.f venus.f ${SRC}

CSRCS = \
	jcio.c jcdate.c timer.c atmo.c

ALLOBJS = ${FSRCS:.f=.o} ${CSRCS:.c=.o}

PROGRAM = ${${SYSTEM}_EXE}

help:
	@echo ''
	@echo 'Usage::'
	@echo ''
	@echo '  make help              shows this help            or' 
	@echo '  make clean             cleans-up garbage          or'
	@echo '  make all [ SYSTEM = { OSF | LINUX | GENERIC} ]'
	@echo '                         compiles with pre-defined flags for'
	@echo '                         OSF, Linux of Unix'
	@echo ''
	@echo 'Additionally, you can add to your command line ADDFLAGS=<flags>'
	@echo 'to include any new flag you want.'
	@echo ''
	@echo 'In case of problems, please contact to <gonzalez@mppmu.mpg.de>'
	@echo ''

all: message ${PROGRAM} 

message:
	@echo "============================================================"
	@echo " Compilation of CORSIKA ("${EXE_VERSION}")"
	@echo " Target machine => `uname -a`"
	@echo " System choosen => "${SYSTEM}
	@echo " Date: `date`"
	@echo "============================================================"
	@echo ''

${PROGRAM}: ${ALLOBJS}
	@echo -n "   . . . and linking -> "${PROGRAM}" . . . "
	$(F77) ${FFLAGS} -o ${PROGRAM} ${ALLOBJS} ${LIBS} ${XLIB}
	@echo "done."

.f.o:
	@echo "Compiling "$<" . . ."
	$(F77) -c $(FFLAGS) $< -o $@

.c.o:
	@echo "Compiling "$<" . . ."
	$(CC) -c $(CFLAGS) $< -o $@

clean: 
	@echo "Cleaning . . ."
	@rm *.o *~ core *.BAK > /dev/null 2>&1 || echo "...already clean."



















