#----------------------------------------------------------------------- # This Makefile is for building the CCM on various platforms # # Note: If the NetCDF libraries and include files are not in /usr/local/lib # and /usr/local/include then define the environment variables # LIB_NETCDF and INC_NETCDF to point to the proper locations. # # Note: VPATH only looks in the current directory !!!! # Create file named Filepath for multiple search paths # #------------------------------------------------------------------------ # Set up special characters null := space := $(null) $(null) # Check for the NetCDF library and include directories ifeq ($(LIB_NETCDF),$(null)) LIB_NETCDF := /usr/local/lib endif ifeq ($(INC_NETCDF),$(null)) INC_NETCDF := /usr/local/include endif # Check for the MPI library and include directories ifeq ($(LIB_MPI),$(null)) # # setld put these in /usr/lib # #LIB_MPI := /usr/local/lib LIB_MPI := /usr/lib endif ifeq ($(INC_MPI),$(null)) # # setld put these in /usr/include # # INC_MPI := /usr/local/include INC_MPI := /usr/include endif # Check for directory in which to put executable ifeq ($(MODEL_EXEDIR),$(null)) MODEL_EXEDIR := . endif # Check for name of executable ifeq ($(EXENAME),$(null)) EXENAME := atm endif # Determine platform UNAMES := $(shell uname -s) UNAMEM := $(findstring CRAY,$(shell uname -m)) # Load dependency search path. dirs := . $(shell cat Filepath) # Set cpp search path, include netcdf cpp_dirs := $(dirs) $(INC_NETCDF) 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)) # Get list of files and determine objects and dependency files FIND_FILES = $(wildcard $(dir)/*.c $(dir)/*.F $(dir)/*.F90) FILES = $(foreach dir, $(dirs),$(FIND_FILES)) SOURCES := $(sort $(notdir $(FILES))) OBJS := $(addsuffix .o, $(basename $(SOURCES))) DEPS := $(addsuffix .d, $(basename $(SOURCES))) all: $(MODEL_EXEDIR)/$(EXENAME) $(MODEL_EXEDIR)/$(EXENAME): $(OBJS) $(FC) -o $@ $(OBJS) $(LDFLAGS) # Architecture-specific flags and rules # #------------------------------------------------------------------------ # Cray #------------------------------------------------------------------------ ifeq ($(UNAMEM),CRAY) # # If libncaro.a exists in /usr/local/lib, add it as well as libecmfft.a # and libmss.a to LDFLAGS # NCARO_LIB := $(strip $(wildcard /usr/local/lib/libncaro.a)) FC := f90 CPP := cpp CPPFLAGS := -N -P -DHIDE_SHR_MSG FFLAGS := -c -I$(INC_NETCDF) -align commons -align dcommons LDFLAGS := -Wl"-f indef -L $(LIB_NETCDF) -l netcdf -M ,s" ifeq ($(NCARO_LIB),/usr/local/lib/libncaro.a) LDFLAGS := $(LDFLAGS) -Wl" -L /usr/local/lib -l ncaro,ecmfft,mss" endif .SUFFIXES: .SUFFIXES: .F .F90 .c .o .F.o: $(CPP) $(cpp_path) $(CPPFLAGS) $< > $*.f $(FC) $(FFLAGS) $*.f $(RM) $*.f .F90.o: $(CPP) $(cpp_path) $(CPPFLAGS) $< > $*.f90 $(FC) $(FFLAGS) $*.f90 $(RM) $*.f90 .c.o: cc -c $(cpp_path) $< endif #------------------------------------------------------------------------ # SGI #------------------------------------------------------------------------ ifeq ($(UNAMES),IRIX64) FC := f90 CPP := /lib/cpp CPPFLAGS := -P FFLAGS := $(cpp_path) -64 -r8 -i4 -O2 -c -mp -cpp -extend_source CFLAGS := $(cpp_path) -64 LDFLAGS := -64 -mp -L$(LIB_NETCDF) -lnetcdf ifeq ($(SPMD),TRUE) FFLAGS := $(cpp_path) -I$(INC_MPI) -64 -r8 -i4 -O2 -c -extend_source -macro_expand LDFLAGS := -64 -L$(LIB_NETCDF) -lnetcdf -L$(LIB_MPI) -lmpi endif .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) FC := /opt/SUNWspro/bin/f90 FC77 := f77 CPP := /usr/ccs/lib/cpp CFLAGS := $(cpp_path) FFLAGS := $(cpp_path) -fast -xs -stackvar -Qoption f90comp -r8const LDFLAGS := -L$(LIB_NETCDF) -lnetcdf -L/opt/local/SUNWspro/lib -lf77compat SPEC_FFLAGS := $(cpp_path) -r8 -i4 -fast -c ifeq ($(SPMD),TRUE) FFLAGS := $(FFLAGS) -I$(INC_MPI) -e LDFLAGS := $(LDFLAGS) -L$(LIB_MPI) -lmpi -lnsl -lsocket endif .SUFFIXES: .SUFFIXES: .F .F90 .c .o sgexx.o: sgexx.F $(FC77) $(SPEC_FFLAGS) $< fft99.o: fft99.F $(FC77) $(SPEC_FFLAGS) $< .F90.o: $(FC) -c -DHIDE_SHR_MSG $(FFLAGS) $< endif #------------------------------------------------------------------------ # Linux # # To debug: add -g -Ktrap=fp to FFLAGS, delete -fast. May want to delete -mp to disable OMP #------------------------------------------------------------------------ ifeq ($(UNAMES),Linux) FC := pgf90 CFLAGS := $(cpp_path) -c CPPFLAGS := $(cpp_path) -F -DHIDE_SHR_MSG BASE_FFLAGS := -c -r8 -i4 -fast -Mrecursive -Mdalign -Msecond_underscore ifeq ($(SPMD),TRUE) SPMD_FFLAGS = -I$(INC_MPI) -Mextend SPMD_LDFLAGS = -L$(LIB_MPI) -lmpich FFLAGS := $(cpp_path) $(BASE_FFLAGS) $(SPMD_FFLAGS) F90FLAGS := $(BASE_FFLAGS) $(SPMD_FFLAGS) -Mfree LDFLAGS := -L$(LIB_NETCDF) -lnetcdf $(SPMD_LDFLAGS) else MP_FFLAGS := -mp FFLAGS := $(cpp_path) $(BASE_FFLAGS) $(MP_FFLAGS) F90FLAGS := $(BASE_FFLAGS) $(MP_FFLAGS) -Mfree LDFLAGS := $(MP_FFLAGS) -L$(LIB_NETCDF) -lnetcdf endif .SUFFIXES: .SUFFIXES: .F .F90 .c .o .F.o: $(FC) -c $(FFLAGS) $< # The following hack enables free form f90 source input to be run through cpp # and then compiled with pgf90 .F90.o: $(FC) $(CPPFLAGS) $< $(FC) $(F90FLAGS) $*.f .c.o: cc $(CFLAGS) $< endif #------------------------------------------------------------------------ # AIX #------------------------------------------------------------------------ ifeq ($(UNAMES),AIX) CPP := /lib/cpp CC := xlc_r CFLAGS := $(cpp_path) -O2 CPPFLAGS := -DHIDE_SHR_MSG -P -DAIX -I$(INC_MPI) FFLAGS := $(cpp_path) -I$(INC_MPI) -qarch=pwr3 -qrealsize=8 -O3 -qstrict -qdpc=e -qsmp=noauto -qspillsize=2500 LDFLAGS := -qsmp=noauto -bmaxdata:0x80000000 -L$(LIB_NETCDF) -lnetcdf FREEFLAGS := -qsuffix=f=f90:cpp=F90 ifeq ($(SPMD),TRUE) FC := mpxlf90_r FIXEDFLAGS := -qfixed=132 else FC := xlf90_r FIXEDFLAGS := -qfixed endif .SUFFIXES: .SUFFIXES: .F .F90 .c .o .F.o: $(FC) -c $(FIXEDFLAGS) $(FFLAGS) $< .F90.o: $(FC) -c $(FREEFLAGS) $(FFLAGS) $< .c.o: cc -c $(CFLAGS) $< endif #------------------------------------------------------------------------ # OSF1 #------------------------------------------------------------------------ ifeq ($(UNAMES),OSF1) CFLAGS := $(cpp_path) FC := f90 FFLAGS_DOTF90 := -DHIDE_SHR_MSG -free ifeq ($(MULTIPROC),TRUE) FFLAGS := $(cpp_path) -I$(INC_MPI) -cpp -r8 -i4 -O3 -c -automatic -align commons -align dcommons FFLAGS_DOTF := -extend_source -automatic LDFLAGS := -lfmpi -lmpi -lrt -pthread -L$(LIB_NETCDF) -L$(LIB_MPI) -lnetcdf else FFLAGS := $(cpp_path) -g -r8 -i4 -O3 -c -omp -automatic -align commons -align dcommons FFLAGS_DOTF := -extend_source -omp -automatic LDFLAGS := -omp -L$(LIB_NETCDF) -lnetcdf endif .SUFFIXES: .SUFFIXES: .F .F90 .c .o .F.o: $(FC) $(FFLAGS) $(FFLAGS_DOTF) $< .F90.o: $(FC) $(FFLAGS) $(FFLAGS_DOTF90) $< endif #------------------------------------------------------------------------ # Default rules #------------------------------------------------------------------------ RM := rm clean: $(RM) -f *.o *.mod *.stb *.f90 $(MODEL_EXEDIR)/$(EXENAME) realclean: $(RM) -f *.o *.d *.mod *.stb *.f90 $(MODEL_EXEDIR)/$(EXENAME) #------------------------------------------------------------------------ #!!!!!!!!!!!!!!!!DO NOT EDIT BELOW THIS LINE.!!!!!!!!!!!!!!!!!!!!!!!!!!!! #------------------------------------------------------------------------ # These rules cause a dependency file to be generated for each source # file. It is assumed that the tool "makdep" (provided with this # distribution in ccm/tools/makdep) has been built and is available in # the user's $PATH. Files contained in the ccm distribution are the # only files which are considered in generating each dependency. The # following filters are applied to exclude any files which are not in # the distribution (e.g. system header files like stdio.h). # # 1) Remove full paths from dependencies. This means gnumake will not break # if new versions of files are created in the directory hierarchy # specified by VPATH. # # 2) Because of 1) above, remove any file dependencies for files not in the # ccm source distribution. # # Finally, add the dependency file as a target of the dependency rules. This # is done so that the dependency file will automatically be regenerated # when necessary. # # i.e. change rule # make.o : make.c make.h # to: # make.o make.d : make.c make.h #------------------------------------------------------------------------ depgen := makdep %.d : %.c @echo "Building dependency file $@" @$(depgen) -f $(cpp_path) $< > $@ %.d : %.F @echo "Building dependency file $@" @$(depgen) -f $(cpp_path) $< > $@ %.d : %.F90 @echo "Building dependency file $@" @$(depgen) -f $(cpp_path) $< > $@ # # if goal is clean or realclean then don't include .d files # without this is a hack, missing dependency files will be created # and then deleted as part of the cleaning process # INCLUDE_DEPS=TRUE ifeq ($(MAKECMDGOALS), realclean) INCLUDE_DEPS=FALSE endif ifeq ($(MAKECMDGOALS), clean) INCLUDE_DEPS=FALSE endif ifeq ($(INCLUDE_DEPS), TRUE) -include $(DEPS) endif