-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
135 lines (112 loc) · 3.98 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
# C compiler options.
CC ?= gcc
#CC := i686-w64-mingw32-gcc-win32
#CC := x86_64-w64-mingw32-gcc-win32
CCFLAGS := -DUSE_DOUBLE -DOPENMP -fopenmp -lm -O3 -finline-functions -funroll-loops
# Fortran compiler options.
FC ?= gfortran
#FC := i686-w64-mingw32-gfortran-win32
#FC := x86_64-w64-mingw32-gfortran-win32
FCFLAGS := -cpp -fopenmp -lgfortran -lm -O3 -finline-functions -funroll-loops
FLDFLAGS := -cpp -fopenmp -O3 -finline-functions -funroll-loops
# Apache Ant, used to compile the Java source.
ANT := ant
# Grab the current version.
VERSION :=$(shell cat VERSION)
# The name of the zip file to build for the dist target.
DIST_ZIP := ~/ecosim-$(VERSION).zip
# Doxygen, used to compile the documentation for the Fortran and Java code.
DOXYGEN := doxygen
# Determine the operating system.
OS := $(shell uname -s)
# Set operating system specific variables.
ifneq (,$(findstring mingw, $(FC)))
# Cross-compile for Windows.
CCFLAGS := $(CCFLAGS) -static -lpthread
FCFLAGS := $(FCFLAGS) -static -lpthread
MKDIR_P := mkdir -p
BINARY_EXT := .exe
DIRECTORY_SEPARATOR := /
else ifneq (,$(filter CYGWIN windows, $(OS)))
# CygWin and GnuWin.
CCFLAGS := $(CCFLAGS) -static -lpthread
FCFLAGS := $(FCFLAGS) -static -lpthread
MKDIR_P := mkdir
BINARY_EXT := .exe
DIRECTORY_SEPARATOR := \\
else ifneq (,$(filter Linux, $(OS)))
# Linux.
MKDIR_P := mkdir -p
BINARY_EXT :=
DIRECTORY_SEPARATOR := /
else ifneq (,$(filter Darwin, $(OS)))
# OS X and Darwin.
MKDIR_P := mkdir -p
BINARY_EXT :=
DIRECTORY_SEPARATOR := /
endif
BUILD_DIR := build$(DIRECTORY_SEPARATOR)
SOURCE_DIR := src$(DIRECTORY_SEPARATOR)
BIN_DIR := bin$(DIRECTORY_SEPARATOR)
DOCS_DIR := docs$(DIRECTORY_SEPARATOR)
# C configuration.
C_SOURCE_FILES := fasttree.c
C_BUILD_DIR := $(BUILD_DIR)c$(DIRECTORY_SEPARATOR)
C_SOURCE_DIR := $(SOURCE_DIR)c$(DIRECTORY_SEPARATOR)
# Fortran configuration.
FORTRAN_SOURCE_FILES := hillclimb.f90 npopCI.f90 omegaCI.f90 sigmaCI.f90 demarcation.f90
FORTRAN_INCLUDE_FILES := darray.f90 ziggurat.f90 methods.f90 simplexmethod.f90
FORTRAN_BUILD_DIR := $(BUILD_DIR)fortran$(DIRECTORY_SEPARATOR)
FORTRAN_SOURCE_DIR := $(SOURCE_DIR)fortran$(DIRECTORY_SEPARATOR)
# Files to be created.
C_BINARY_FILES := $(patsubst %.c, $(C_BUILD_DIR)%$(BINARY_EXT), $(C_SOURCE_FILES))
FORTRAN_BINARY_FILES := $(patsubst %.f90, $(FORTRAN_BUILD_DIR)%$(BINARY_EXT), $(FORTRAN_SOURCE_FILES))
FORTRAN_OBJECT_FILES := $(patsubst %.f90, $(FORTRAN_BUILD_DIR)%.o, $(FORTRAN_INCLUDE_FILES))
FORTRAN_MOD_FILES := $(patsubst %.f90, %.mod, $(FORTRAN_INCLUDE_FILES))
# List of phony build targets.
.PHONY: all clean install uninstall docs check dist
# The main entry point for building.
all: $(C_BINARY_FILES) $(FORTRAN_BINARY_FILES)
$(ANT)
# Remove the old build files.
clean:
rm -f Doxyfile.log
rm -f $(FORTRAN_MOD_FILES)
rm -Rf $(BUILD_DIR)
rm -Rf $(DOCS_DIR)
# Install the binary files to the appropriate location.
install: $(C_BINARY_FILES) $(FORTRAN_BINARY_FILES)
@$(MKDIR_P) $(BIN_DIR)
cp -f $(C_BINARY_FILES) $(BIN_DIR)
cp -f $(FORTRAN_BINARY_FILES) $(BIN_DIR)
$(ANT) install
# Remove the binary files from their installed location.
uninstall:
rm -Rf $(BIN_DIR)
$(ANT) uninstall
# Build the documentation.
docs:
@$(MKDIR_P) $(DOCS_DIR)
$(DOXYGEN) ecosim.doxy
# Run the unit tests.
check:
$(ANT) check
# Build the distribution zip file.
dist: uninstall install docs clean
rm -Rf dist $(DIST_ZIP)
@$(MKDIR_P) dist
rsync -a --exclude='*.git*' --exclude dist . dist
perl -i -ne 's/\%ECOSIM_VERSION\%/'$(VERSION)'/g; print;' dist/help/about.xhtml
cd dist && zip -9 -r $(DIST_ZIP) .
# Build the c binary files.
$(C_BUILD_DIR)%$(BINARY_EXT): $(C_SOURCE_DIR)%.c
@$(MKDIR_P) $(C_BUILD_DIR)
$(CC) $^ $(CCFLAGS) -o $@
# Build the fortran binary files.
$(FORTRAN_BUILD_DIR)%$(BINARY_EXT): $(FORTRAN_SOURCE_DIR)%.f90 $(FORTRAN_OBJECT_FILES)
@$(MKDIR_P) $(FORTRAN_BUILD_DIR)
$(FC) $^ $(FCFLAGS) -o $@
# Build the fortran object files.
$(FORTRAN_BUILD_DIR)%.o: $(FORTRAN_SOURCE_DIR)%.f90
@$(MKDIR_P) $(FORTRAN_BUILD_DIR)
$(FC) -c $^ $(FLDFLAGS) -o $@