forked from regine/meltmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
150 lines (117 loc) · 3.2 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
# Handy global variables
MODEL_SRC = ./src
MODEL_BUILD_TMP = ./build
BINARY_DIR = ./bin
df = $(MODEL_BUILD_TMP)/$(*F)
# Compiler Flags
CC=gcc
CFLAGS = -Wall -Wextra -O0
# Forces 32-bit compilation on 32-bit kernels
# prevents segfaults caused by gcc defaulting to x86_64 when a 32-bit kernel is
# running on an x_86_64 processor (OS X 10.7, for instance)
ifneq ($(OS),Windows_NT)
UNAME_M := $(shell uname -m)
ifneq ($(filter %86,$(UNAME_M)),)
CFLAGS += -m32
endif
endif
LDFLAGS = -lm
MAKEDEPEND = gcc -MM -MT '$(MODEL_BUILD_TMP)/$*.o' $(CPPFLAGS) -o $(MODEL_BUILD_TMP)/$*.d $<
.PHONY: clean\
all\
debam\
detim\
models\
utils\
shading\
ascigrid\
gridasci\
gridtools\
#### Model Building Stuff ####
# Generic object file build rule
$(MODEL_BUILD_TMP)/%.o: $(MODEL_SRC)/%.c
@mkdir -p $(MODEL_BUILD_TMP)
$(MAKEDEPEND)
@cp $(df).d $(df).P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
rm -f $(df).d
@echo "Building $@"
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
## DETIM
## Source-files Required by DETIM
DETIM_SOURCES = closeall.c \
discharg.c \
disopt.c \
globcor.c \
grid.c \
initial.c \
input.c \
radiat.c \
snowinput.c \
snowmodel.c \
skintemperature.c \
tindex.c \
turbul.c\
userfile.c \
writeout.c \
retreat.c \
detim.c
-include $(addprefix $(MODEL_BUILD_TMP)/, $(DETIM_SOURCES:.c=.P))
DETIM_OBJECTS = $(addprefix $(MODEL_BUILD_TMP)/, $(DETIM_SOURCES:.c=.o))
$(BINARY_DIR)/detim: $(DETIM_OBJECTS)
@mkdir -p $(BINARY_DIR)
@echo "Building DETiM:"
$(CC) $(CFLAGS) $(DETIM_OBJECTS) -o $(BINARY_DIR)/detim $(LDFLAGS)
detim: $(BINARY_DIR)/detim
## DEBAM
## Source-files requires by DEBaM
DEBAM_SOURCES = closeall.c \
discharg.c \
disopt.c \
globcor.c \
grid.c \
initial.c \
input.c \
radiat.c \
snowinput.c \
snowmodel.c \
skintemperature.c \
turbul.c \
userfile.c \
retreat.c \
writeout.c \
debam.c
-include $(addprefix $(MODEL_BUILD_TMP)/, $(DEBAM_SOURCES:.c=.P))
DEBAM_OBJECTS = $(addprefix $(MODEL_BUILD_TMP)/, $(DEBAM_SOURCES:.c=.o))
$(BINARY_DIR)/debam: $(DEBAM_OBJECTS)
@mkdir -p $(BINARY_DIR)
@echo "Building DEBAM:"
$(CC) $(CFLAGS) $(DEBAM_OBJECTS) -o $(BINARY_DIR)/debam $(LDFLAGS)
debam: $(BINARY_DIR)/debam
models: debam detim
#### Utility Programs ####
# Grid tools
$(BINARY_DIR)/ascigrid: ./util/grid_tools/ascigrid.c
@mkdir -p $(BINARY_DIR)
@echo "Building ascigrid"
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
ascigrid: $(BINARY_DIR)/ascigrid
$(BINARY_DIR)/gridasci: util/grid_tools/gridasci.c
@mkdir -p $(BINARY_DIR)
@echo "Building gridasci"
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
gridasci: $(BINARY_DIR)/gridasci
gridtools: ascigrid gridasci
# Shading calculator
$(BINARY_DIR)/shading: ./util/shading/shading.c
@mkdir -p $(BINARY_DIR)
@echo "Building shading"
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
shading: $(BINARY_DIR)/shading
utils: gridtools shading
#### Big/Std targets ####
all: models utils
clean:
-rm -r $(MODEL_BUILD_TMP)
-rm -r $(BINARY_DIR)