forked from dmidk/Icepack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
180 lines (155 loc) · 6.32 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#-------------------------------------------------------------------------------
# CVS $Id: Makefile.std,v 1.1 2004/02/09 18:13:52 lipscomb Exp $
# CVS $Source: /home/climate/CVS-COSIM/cice/bld/Makefile.std,v $
# CVS $Name: $
#-------------------------------------------------------------------------------
# Common Makefile: a framework for building all CCSM components and more
#
# Command-line variables
# MACFILE=<file> ~ the macros definition file to use/include
# EXEC=<name> ~ name given to executable, default is a.out
# VPATH=<vpath> ~ VPATH , default is . (cwd only)
# SRCS=<files> ~ list of src files, default is all .c .F .F90 files in VPATH
# VPFILE=<file> ~ file with list of dirs, used to create VPATH
# SRCFILE=<file> ~ file with list of src files, used to create SRCS
# DEPGEN=<exec> ~ dependency generator utility, default is makdep
#
# <macro defns> ~ any macro definitions found in this file or the included
# MACFILE will be over-riden by cmd-line macro definitions
# MODEL=<model> ~ a standard macro definition, often found in the included
# MACFILE, used to trigger special compilation flags
#
# Usage examples:
# % gmake MACFILE=Macros.AIX VPFILE=Filepath MODEL=ccm3 EXEC=atm
# % gmake MACFILE=Macros.AIX VPFILE=Filepath SRCFILE=Srclist EXEC=pop
# % gmake MACFILE=Macros.C90 VPATH="dir1 dir2" SRCS="file1.c file2.F90"
# % gmake MACFILE=Macros.SUN SRCS="test.F"
#-------------------------------------------------------------------------------
# Make sure that bash is chosen over /bin/sh, which may only be dash compatible
SHELL=/bin/bash
#-------------------------------------------------------------------------------
# parse cmd-line and establish values for EXEC, VPATH, SRCS, OBJS, etc
#-------------------------------------------------------------------------------
EXEC := a.out
MACFILE := NONE
MODEL := NONE
VPFILE := NONE
VPATH := .
SRCFILE := NONE
SRCS := NONE
DEPGEN := ./makdep # an externally provided dependency generator
ifneq ($(VPATH),.)
# this variable was specified on cmd line or in an env var
else
ifneq ($(VPFILE),NONE)
# explicit list of VPATH dirs is provided
VPATH := $(wildcard . $(shell cat $(VPFILE) ) )
endif
endif
ifneq ($(SRCS),NONE)
# this variable was specified on cmd line or in an env var
else
ifneq ($(SRCFILE),NONE)
# explicit list of src files is provided
SRCS := $(shell cat $(SRCFILE) )
else
# list of src files is all .F90 .F .c files in VPATH
SRCS := $(wildcard $(addsuffix /*.F90 , $(VPATH)) \
$(addsuffix /*.[cF], $(VPATH)) )
endif
endif
OBJS := $(addsuffix .o, $(sort $(basename $(notdir $(SRCS)))))
DEPS := $(addsuffix .d, $(sort $(basename $(notdir $(SRCS)))))
INCS := $(patsubst %,-I%, $(VPATH) )
RM := rm
MODDIR:= -I.
.SUFFIXES:
.SUFFIXES: .F90 .F .c .o
all: $(EXEC)
#-------------------------------------------------------------------------------
# include the file that provides macro definitions required by build rules
# note: the MACFILE may not be needed for certain goals
#-------------------------------------------------------------------------------
ifneq ($(MAKECMDGOALS), db_files)
-include $(MACFILE)
endif
#-------------------------------------------------------------------------------
# echo file names, paths, compile flags, etc. used during build
#-------------------------------------------------------------------------------
db_files:
@echo " "
@echo "* EXEC := $(EXEC)"
@echo "* MACFILE := $(MACFILE)"
@echo "* VPFILE := $(VPFILE)"
@echo "* VPATH := $(VPATH)"
@echo "* SRCFILE := $(SRCFILE)"
@echo "* INCS := $(INCS)"
@echo "* MODDIR := $(MODDIR)"
@echo "* SRCS := $(SRCS)"
@echo "* OBJS := $(OBJS)"
@echo "* DEPS := $(DEPS)"
db_flags:
@echo " "
@echo "* cpp := $(CPP) $(CPPFLAGS) $(CPPDEFS) $(INCLDIR)"
@echo "* cc := $(CC) -c $(CFLAGS) $(INCLDIR)"
@echo "* .F.o := $(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(INCLDIR)"
@echo "* .F90.o := $(FC) -c $(FFLAGS) $(FREEFLAGS) $(MODDIR) $(INCLDIR)"
#-------------------------------------------------------------------------------
# build rule for makdep: MACFILE, cmd-line, or env vars must provide
# the needed macros
#-------------------------------------------------------------------------------
$(DEPGEN): $(ICE_CASEDIR)/makdep.c
$(SCC) -o $@ $(CFLAGS_HOST) $<
#-------------------------------------------------------------------------------
# build rules: MACFILE, cmd-line, or env vars must provide the needed macros
#-------------------------------------------------------------------------------
$(EXEC): $(OBJS)
$(LD) -o $(EXEC) $(LDFLAGS) $(OBJS) $(ULIBS) $(SLIBS)
.c.o:
$(CC) $(CFLAGS) $(CPPDEFS) $(INCLDIR) $<
.F.o:
$(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(CPPDEFS) $(INCLDIR) $<
.F90.o:
$(FC) -c $(FFLAGS) $(FREEFLAGS) $(CPPDEFS) $(MODDIR) $(INCLDIR) $<
mostlyclean:
$(RM) -f *.f *.f90
clean:
$(RM) -f *.f *.f90 *.d *.mod *.o $(EXEC)
# $(RM) -f *.f *.f90 *.d *.$(MOD_SUFFIX) $(OBJS)
realclean:
$(RM) -f *.f *.f90 *.d *.$(MOD_SUFFIX) $(OBJS) $(EXEC)
#-------------------------------------------------------------------------------
# Build & include dependency files
#-------------------------------------------------------------------------------
# ASSUMPTIONS:
# o an externally provided dependency generator, $(DEPGEN), is available,
# its cmd line syntax is compatible with the build rules below. Eg, for
# each .o file, there is a corresponding .d (dependency) file, and both
# will be dependent on the same src file, eg. foo.o foo.d : foo.F90
# Also, the dependancy genorator's capabilities, limitations, and assumptions
# are understood & accepted.
#-------------------------------------------------------------------------------
%.d : %.c
@ echo "Building dependency for $@"
@ $(DEPGEN) -f $(INCS) $< | head -3 > $@
%.d : %.F
@ echo "Building dependency for $@"
@ $(DEPGEN) -f $(INCS) $< > $@
%.d : %.F90
@ echo "Building dependency for $@"
@ $(DEPGEN) -f $(INCS) $< > $@
%.d : %.H
@ echo "Building dependency for $@"
@ $(DEPGEN) -f $(INCS) $< > $@
# the if-tests prevent DEPS files from being created when they're not needed
ifneq ($(MAKECMDGOALS), db_files)
ifneq ($(MAKECMDGOALS), db_flags)
ifneq ($(MAKECMDGOALS), mostlyclean)
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), realclean)
-include $(DEPS)
endif
endif
endif
endif
endif