?? makefile
字號:
#-----------------------------------------------------------------------# Makefile for building CAM on various platforms.## This makefile assumes the existence the file:## Filepath The directories, listed one per line, that contain the source# code required to build CAM. This list is used the set the# VPATH variable which is used by GNU make to search for# dependencies (after it looks in the directory from which# it was invoked). This list of directories, prepended with ./,# is also used to construct the list of search directories # used by the preprocessor (as specified by -I command-line options).## The following macros may be set in the user's environment:## ROOTDIR Root directory for the CAM source distribution.# EXENAME Name to call the executable.# MODEL_EXEDIR Directory to build the executable in.# INC_NETCDF Directory location of the NetCDF include files.# LIB_NETCDF Directory location of the NetCDF library.# INC_MPI Directory location of the MPI include files.# LIB_MPI Directory location of the MPI library.# ESMF_ROOT Root directory of ESMF source tree. Default: $(ROOTDIR)/models/utils/esmf# ESMF_BLD Upper level build directory for ESMF# The ESMF .o files are built in $(ESMF_BLD)/obj# The ESMF .m files are built in arch dependent subdirs of $(ESMF_BLD)/mod# The ESMF library is built in architecture and optimization# dependent subdirectories of $(ESMF_BLD)/lib# DEBUG Set to TRUE to turn on compiler debugging options. Default: FALSE # SPMD Whether to build in SPMD mode or not. [values TRUE FALSE]# (If this variable not set then ./misc.h is checked)# USER_FC Allow user to override the default Fortran compiler specified in Makefile.# USER_CC Allow user to override the default C compiler specified in Makefile (linux only).# USER_FFLAGS Additional compiler flags that the user wishes to set.# NO_SWITCH On Compaq if the hardward switch is not available# set this env variable to "TRUE".## Defaults for all of the above are provided in the Makefile.## Note: If ROOTDIR is not set the makefile searches for it in a file called "Rootdir"## Note: The ESMF library is included in the CAM distribution in # $ROOTDIR/models/utils/esmf and is built using this makefile. #------------------------------------------------------------------------# Set up special charactersnull :=space := $(null) $(null)# Determine distribution root directoryifeq ($(ROOTDIR),$(null))ROOTDIR := $(shell cat Rootdir)endif# Check for the NetCDF library and include directories ifeq ($(LIB_NETCDF),$(null))LIB_NETCDF := /usr/local/libendififeq ($(INC_NETCDF),$(null))INC_NETCDF := /usr/local/includeendif# Check for the MPI library and include directories ifeq ($(LIB_MPI),$(null))LIB_MPI := /usr/local/libendififeq ($(INC_MPI),$(null))INC_MPI := /usr/local/includeendif# Build the ESMF libraryifeq ($(ESMF_ROOT),$(null))ESMF_ROOT := ${ROOTDIR}/models/utils/esmfendififeq ($(ESMF_BLD),$(null))ESMF_BLD := $(shell (mkdir ./esmf 2>/dev/null;cd ./esmf;pwd))endifESMF_BOPT := Oifeq ($(DEBUG),TRUE) ESMF_BOPT := gendifESMF_MOD := $(ESMF_BLD)/mod/mod$(ESMF_BOPT)ESMF_LIB := $(ESMF_BLD)/lib/lib$(ESMF_BOPT)# Check for directory in which to put executableifeq ($(MODEL_EXEDIR),$(null))MODEL_EXEDIR := .endif# Check for name of executableifeq ($(EXENAME),$(null))EXENAME := atmendif# Check if SPMD is defined in "misc.h"# Ensure that it is defined and not just "undef SPMD" set in fileifeq ($(SPMD),$(null)) SPMDSET := $(shell /bin/grep SPMD misc.h) ifneq (,$(findstring define,$(SPMDSET))) SPMD := TRUE else SPMD := FALSE endifendif# Load dependency search path.dirs := . $(shell cat Filepath)# Set cpp search path, include netcdfcpp_dirs := $(dirs) $(INC_NETCDF) $(INC_MPI)cpp_path := $(foreach dir,$(cpp_dirs),-I$(dir)) # format for command line# Expand any tildes in directory names. Change spaces to colons.VPATH := $(foreach dir,$(cpp_dirs),$(wildcard $(dir))) VPATH := $(subst $(space),:,$(VPATH)) #------------------------------------------------------------------------# Primary target: build the model#------------------------------------------------------------------------all: $(MODEL_EXEDIR)/$(EXENAME)# Get list of files and build dependency file for all .o files# using perl scripts mkSrcfiles and mkDependsSOURCES := $(shell cat Srcfiles)Depends: Srcfiles Filepath $(ROOTDIR)/models/atm/cam/bld/mkDepends Filepath Srcfiles > $@Srcfiles: Filepath $(ROOTDIR)/models/atm/cam/bld/mkSrcfiles > $@OBJS := $(addsuffix .o, $(basename $(SOURCES)))$(MODEL_EXEDIR)/$(EXENAME): $(OBJS) $(FC) -o $@ $(OBJS) -L$(LIB_NETCDF) -lnetcdf -L$(ESMF_LIB)/$(ESMF_ARCH) -lesmf $(LDFLAGS)debug: $(OBJS) echo "FFLAGS: $(FFLAGS)" echo "LDFLAGS: $(LDFLAGS)" echo "OBJS: $(OBJS)"test_fc: test_fc.o $(FC) -o $@ test_fc.o $(LDFLAGS)test_nc: test_nc.o $(FC) -o $@ test_nc.o -L$(LIB_NETCDF) -lnetcdf $(LDFLAGS)test_mpi: test_mpi.o $(FC) -o $@ test_mpi.o $(LDFLAGS)# Architecture-specific flags and rules## Determine platform UNAMES := $(shell uname -s)#------------------------------------------------------------------------# AIX#------------------------------------------------------------------------ifeq ($(UNAMES),AIX)ESMF_ARCH := rs6000_spCPP := /lib/cppCC := xlc_rCFLAGS := $(cpp_path) -O2 -DAIXFPPFLAGS := -WF,-DHIDE_SHR_MSG,-DAIX,-DNO_SHR_VMATHFFLAGS := $(cpp_path) $(FPPFLAGS) -qarch=auto -qrealsize=8 -qdpc=e -qsmp=noauto -qspillsize=2500 \ -I$(ESMF_MOD)/$(ESMF_ARCH)FREEFLAGS := -qsuffix=f=f90:cpp=F90FIXEDFLAGS := -qfixed=132LDFLAGS := -qsmp=noauto -bmaxdata:0x80000000ifeq ($(SPMD),TRUE) FC := mpxlf90_relse FC := xlf90_r FFLAGS += -WF,-DHIDE_MPIendififeq ($(DEBUG),TRUE)## Bounds checking is unreliable on the IBM.# Sometimes you can get it to go if you turn threading off (by deleting -qsmp=noauto)# FFLAGS += -g -d -qinitauto=7FF7FFFF -qflttrap=ov:zero:inv:enelse# Inline when not debugging FFLAGS += -O3 -qstrict -Qendif.SUFFIXES:.SUFFIXES: .F .F90 .c .o.F.o: $(FC) -c $(FIXEDFLAGS) $(FFLAGS) $<.F90.o: $(FC) -c $(FREEFLAGS) $(FFLAGS) $<.c.o: cc -c $(CFLAGS) $<endif#------------------------------------------------------------------------# SGI#------------------------------------------------------------------------ifeq ($(UNAMES),IRIX64)ESMF_ARCH = IRIX64FC := f90CPP := /lib/cppCPPFLAGS := -PCFLAGS := $(cpp_path) -64 -DIRIX64 -O2FFLAGS = $(cpp_path) -64 -r8 -i4 -c -cpp -extend_source -DIRIX64 \ -DNO_SHR_VMATH -I$(ESMF_MOD)/$(ESMF_ARCH)LDFLAGS = -64 -mp# WARNING: -mp and -g together cause wrong answersifeq ($(DEBUG),TRUE) FFLAGS += -g -DEBUG:trap_uninitialized=ON -Celse FFLAGS += -O2 -mpendif# WARNING: - Don't run hybrid on SGI (that's what the -= -mp is all about)ifeq ($(SPMD),TRUE) FFLAGS -= -mp FFLAGS += -I$(INC_MPI) -macro_expand LDFLAGS += -L$(LIB_MPI) -lmpi else FFLAGS += -DHIDE_MPIendif.SUFFIXES:.SUFFIXES: .F .F90 .c .o.F.o: $(FC) $(FFLAGS) $<.F90.o: $(FC) -DHIDE_SHR_MSG $(FFLAGS) $<.c.o: cc -c $(cpp_path) $(CFLAGS) $<endif#------------------------------------------------------------------------# SUN#------------------------------------------------------------------------ifeq ($(UNAMES),SunOS)ESMF_ARCH = solarisFC := f90FC77 := f77CPP := /usr/ccs/lib/cppCFLAGS := $(cpp_path) -DSUNOS -DNO_SHR_VMATHFFLAGS := $(cpp_path) -xs -stackvar -Qoption f90comp -r8const -e -DSUNOS -DHIDE_MPI \ -M$(ESMF_MOD)/$(ESMF_ARCH)LDFLAGS := -L/opt/SUNWspro/lib -lf77compat -openmp -fastSPEC_FFLAGS := $(cpp_path) -r8 -i4 -cifeq ($(DEBUG),TRUE) FFLAGS += -g -dalign SPEC_FFLAGS += -g -dalignelse# Inline code when not debugging FFLAGS += -inline=%auto -fastendififeq ($(SPMD),TRUE) FFLAGS += -I$(INC_MPI) LDFLAGS += -L$(LIB_MPI) -lmpich -lnsl -lsocketelse FFLAGS += -DHIDE_MPIendif.SUFFIXES:.SUFFIXES: .F .F90 .c .osgexx.o: sgexx.F $(FC77) $(SPEC_FFLAGS) $<fft99.o: fft99.F $(FC77) $(SPEC_FFLAGS) $<.F90.o: $(FC) -c -DHIDE_SHR_MSG $(FFLAGS) $<endif#------------------------------------------------------------------------# Linux#------------------------------------------------------------------------ifeq ($(UNAMES),Linux)ESMF_ARCH = linux# if the compiler is not specified, choose PGI pgf90ifeq ($(USER_FC),$(null))FC := pgf90elseFC := $(USER_FC)endif# if USER_CC is set, use it. Otherwise use pgcc if pgf90 is the Fortran compiler,# and cc if notifeq ($(USER_CC),$(null))ifeq ($(FC),pgf90)CC := pgccelseCC := ccendifelseCC := $(USER_CC)endif# Figure out the ESMF architecture.ifeq ($(FC),pgf90)ifeq ($(CC),pgcc)ESMF_ARCH = linux_pgielseESMF_ARCH = linux_gnupgf90endifendif# if not using pgcc, define USE_GCC to disable threading in the timing libraryCFLAGS = $(cpp_path) -c -DLINUXifeq ($(CC),pgcc)CFLAGS += -fastelseCFLAGS += -DUSE_GCCendif# pgf90# -DPGF90 is for phcs and gauaw which normally use r16 arithmetic but is unavailable under pgf90ifeq ($(FC),pgf90)FFLAGS = $(cpp_path) -c -r8 -i4 -DHIDE_SHR_MSG -Mrecursive -Mdalign -Mextend -mp -DLINUX \ -DPGF90 -I$(ESMF_MOD)/$(ESMF_ARCH)F90FLAGS = $(FFLAGS) -MfreeLDFLAGS = -mpifeq ($(DEBUG),TRUE) FFLAGS += -g -Ktrap=fp -Mbounds SPEC_FFLAGS := $(FFLAGS) else SPEC_FFLAGS := $(FFLAGS) FFLAGS += -fastendifendif# lf95## Note that as of lf95 version 6.1 threading does NOT work because of# ridiculously small per thread stacksize limits.## -CcdRR8 is an undocumented flag which promotes only vars declared "real", not "real*8"# --trace produces a call traceback on abort# --trap causes code to stop on divide by zero or overflow exceptions# --pca prevents overwriting constant arguments# --staticlink enables transportability of the executable# --chk for basic compiler checking (a,e,s,u,x)# --chkglobal for global checkingifeq ($(FC),lf95)ESMF_ARCH = linux_lf95FFLAGS = $(cpp_path) -c -CcdRR8 -DHIDE_SHR_MSG --trace --trap -DLINUX -I$(ESMF_MOD)/$(ESMF_ARCH)SPEC_FFLAGS := $(FFLAGS)F90FLAGS = $(FFLAGS)LDFLAGS = --staticlinkifeq ($(DEBUG),TRUE) FFLAGS += -g --chk --pcaelse FFLAGS += -Oendifendif# FFC f90ifeq ($(FC),f90)FFLAGS = -CcdRR8 -Cpp -X9 -fw -Am -Wa,-W $(cpp_path) -c -DHIDE_SHR_MSG -DLINUX \ -I$(ESMF_MOD)/$(ESMF_ARCH)LDFLAGS = ifeq ($(DEBUG),TRUE) FFLAGS += -g -H aseuelse FFLAGS += -Kfast,eval,fastlib,autoendifendif# Flags common to all compilersifeq ($(SPMD),TRUE) FFLAGS += -I$(INC_MPI) -DNO_SHR_VMATH LDFLAGS += -L$(LIB_MPI) -lmpichelse FFLAGS += -DHIDE_MPI -DNO_SHR_VMATHendif.SUFFIXES:.SUFFIXES: .F .F90 .c .oifeq ($(FC),pgf90)## To fix hanging problem when using sld dynamics, compile sgexx without "-fast"#sgexx.o: sgexx.F $(FC) $(SPEC_FFLAGS) $<endififeq ($(FC),lf95)# lahey fails on binary_io due to writing wrap areasbinary_io.o: binary_io.F90 $(FC) $(SPEC_FFLAGS) $<wrap_nf.o: wrap_nf.F90 $(FC) $(SPEC_FFLAGS) $<wrap_mpi.o: wrap_mpi.F90 $(FC) $(SPEC_FFLAGS) $<endif.F90.o: $(FC) $(F90FLAGS) $<.F.o: $(FC) -c $(FFLAGS) $<.c.o: $(CC) $(CFLAGS) $<endif#------------------------------------------------------------------------# OSF1#------------------------------------------------------------------------ifeq ($(UNAMES),OSF1)ESMF_ARCH := alphaCFLAGS := $(cpp_path) -DOSF1 -O2 -ompFC := f90FFLAGS := $(cpp_path) -r8 -i4 -c -omp -automatic -fpe3 -I$(ESMF_MOD)/$(ESMF_ARCH)FFLAGS_DOTF90 := -DHIDE_SHR_MSG -DOSF1 -free -fpe3 -DNO_SHR_VMATHFFLAGS_DOTF := -extend_source -omp -automaticLDFLAGS := -omp ifeq ($(DEBUG),TRUE) FFLAGS += -g3 -Celse# Inline when not debugging FFLAGS += -O3 -inline speedendififeq ($(NO_SWITCH),$(null)) NO_SWITCH := FALSEendififeq ($(SPMD),TRUE) FFLAGS += -I$(INC_MPI) LDFLAGS += -lmpielse FFLAGS += -DHIDE_MPIendififneq ($(NO_SWITCH),TRUE) LDFLAGS += -lelanendif.SUFFIXES:.SUFFIXES: .F .F90 .c .o.F.o: $(FC) $(FFLAGS) $(FFLAGS_DOTF) $<.F90.o: $(FC) $(FFLAGS) $(FFLAGS_DOTF90) $<.c.o: cc -c $(CFLAGS) $<endif#------------------------------------------------------------------------# Targets/rules that depend on architecture specific variables.#------------------------------------------------------------------------# The ESMF library is not made to be built in parallel, so specify only one job is to run.$(ESMF_LIB)/$(ESMF_ARCH)/libesmf.a: cd $(ESMF_ROOT); \ $(MAKE) -j 1 BOPT=$(ESMF_BOPT) ESMF_BUILD=$(ESMF_BLD) ESMF_DIR=$(ESMF_ROOT) ESMF_ARCH=$(ESMF_ARCH);time_manager.o : $(ESMF_LIB)/$(ESMF_ARCH)/libesmf.aRM := rm# Add user defined compiler flags if set, and replace FC if USER option set.FFLAGS += $(USER_FFLAGS)ifneq ($(USER_FC),$(null))FC := $(USER_FC)endifclean: $(RM) -r esmf $(RM) -f Depends Srcfiles *.o *.mod *.stb *.f90 $(MODEL_EXEDIR)/$(EXENAME)realclean: cleaninclude Depends
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -