forked from dtarb/TauDEM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (127 loc) · 6.19 KB
/
Makefile
File metadata and controls
142 lines (127 loc) · 6.19 KB
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
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
# Determine Linux architecture triplet
ifeq ($(UNAME_M),x86_64)
LINUX_TRIPLET := x86_64-linux-gnu
else ifeq ($(UNAME_M),aarch64)
LINUX_TRIPLET := aarch64-linux-gnu
else
LINUX_TRIPLET := $(UNAME_M)-linux-gnu
endif
# Default build type
BUILD_TYPE ?= Debug
# Directories
BUILD_DIR_DEBUG = build/debug
BUILD_DIR_RELEASE = build/release
CONFIG_FILE = config.cmake
# Build commands
.PHONY: all debug release dk-debug dk-release dk-install dk-run-tests clean install uninstall help
# Default target
all: debug
# Function to check compiler and set options
check_compiler = $(if $(COMPILER),\
$(if $(filter $(COMPILER),linux macos clang gcc-apple),\
$(eval CMAKE_GENERATOR="Unix Makefiles")\
$(eval CMAKE_COMPILER_OPTIONS=$(call get_compiler_options,$(COMPILER))),\
$(error Unknown compiler specified. Use COMPILER=linux, macos, clang, gcc-apple)\
),\
$(error COMPILER is required for build targets. Use COMPILER=linux, macos, clang, gcc-apple)\
)
# Function to get compiler options
define get_compiler_options
$(if $(filter linux,$1),\
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DMPI_C_COMPILER=/usr/bin/mpicc \
-DMPI_CXX_COMPILER=/usr/bin/mpicxx \
-DMPI_C_LIBRARIES=/usr/lib/$(LINUX_TRIPLET)/libmpi.so \
-DMPI_CXX_LIBRARIES=/usr/lib/$(LINUX_TRIPLET)/libmpi.so \
-DMPI_C_INCLUDE_PATH=/usr/lib/$(LINUX_TRIPLET)/openmpi/include \
-DMPI_CXX_INCLUDE_PATH=/usr/lib/$(LINUX_TRIPLET)/openmpi/include \
-DMPI_CXX_FOUND=TRUE,\
$(if $(filter macos,$1),-DCMAKE_C_COMPILER=/opt/homebrew/bin/gcc-15 -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/g++-15 \
-DMPI_C_COMPILER=/opt/homebrew/opt/open-mpi/bin/mpicc \
-DMPI_CXX_COMPILER=/opt/homebrew/opt/open-mpi/bin/mpicxx \
-DMPI_C_LIBRARIES=/opt/homebrew/opt/open-mpi/lib/libmpi.dylib \
-DMPI_CXX_LIBRARIES=/opt/homebrew/opt/open-mpi/lib/libmpi.dylib \
-DMPI_C_INCLUDE_PATH=/opt/homebrew/opt/open-mpi/include \
-DMPI_CXX_INCLUDE_PATH=/opt/homebrew/opt/open-mpi/include \
-DMPI_CXX_FOUND=TRUE,\
$(if $(filter clang,$1),-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++,\
$(if $(filter gcc-apple,$1),-DCMAKE_C_COMPILER=/opt/homebrew/bin/aarch64-apple-darwin24-gcc-15 -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/aarch64-apple-darwin24-g++-15 \
-DMPI_C_COMPILER=/opt/homebrew/opt/open-mpi/bin/mpicc \
-DMPI_CXX_COMPILER=/opt/homebrew/opt/open-mpi/bin/mpicxx \
-DMPI_C_LIBRARIES=/opt/homebrew/opt/open-mpi/lib/libmpi.dylib \
-DMPI_CXX_LIBRARIES=/opt/homebrew/opt/open-mpi/lib/libmpi.dylib \
-DMPI_C_INCLUDE_PATH=/opt/homebrew/opt/open-mpi/include \
-DMPI_CXX_INCLUDE_PATH=/opt/homebrew/opt/open-mpi/include \
-DMPI_CXX_FOUND=TRUE,))))
endef
# Function to check OS compatibility
check_os_compatibility = $(if $(COMPILER),\
$(if $(and $(filter linux,$(COMPILER)),$(filter Darwin,$(UNAME_S))),\
$(error Linux compiler is not suitable on macOS. Use COMPILER=clang, macos, or gcc-apple),\
$(if $(and $(filter macos clang gcc-apple,$(COMPILER)),$(filter Linux,$(UNAME_S))),\
$(error macOS compilers are not suitable on Linux. Use COMPILER=linux))),\
$(error COMPILER is required for build targets. Use COMPILER=linux, macos, clang, gcc-apple)\
)
# Build targets
debug:
$(warning COMPILER is $(COMPILER))
$(warning UNAME_S is $(UNAME_S))
$(call check_os_compatibility)
$(call check_compiler)
@echo "Building in Debug mode with $(COMPILER) compiler..."
@mkdir -p $(BUILD_DIR_DEBUG)
@cd $(BUILD_DIR_DEBUG) && cmake ../.. -C ../../$(CONFIG_FILE) -DCMAKE_BUILD_TYPE=Debug $(CMAKE_COMPILER_OPTIONS) -G $(CMAKE_GENERATOR)
$(if $(TARGET),\
@echo "Building specific target: $(TARGET)" && cd $(BUILD_DIR_DEBUG) && make $(TARGET),\
@echo "Building all targets" && cd $(BUILD_DIR_DEBUG) && make\
)
release:
$(warning COMPILER is $(COMPILER))
$(warning UNAME_S is $(UNAME_S))
$(call check_os_compatibility)
$(call check_compiler)
@echo "Building in Release mode with $(COMPILER) compiler..."
@mkdir -p $(BUILD_DIR_RELEASE)
@cd $(BUILD_DIR_RELEASE) && cmake ../.. -C ../../$(CONFIG_FILE) -DCMAKE_BUILD_TYPE=Release $(CMAKE_COMPILER_OPTIONS) -G $(CMAKE_GENERATOR)
$(if $(TARGET),\
@echo "Building specific target: $(TARGET)" && cd $(BUILD_DIR_RELEASE) && make $(TARGET),\
@echo "Building all targets" && cd $(BUILD_DIR_RELEASE) && make\
)
# This target is used to run the tests in the Docker container built from the Dockerfile-run.tests Dockerfile
dk-run-tests:
@echo "Running tests..."
@cd /home/taudem-docker/workspace/TauDEM-Test-Data/Input && \
./taudem-tests.sh
clean:
@echo "Cleaning build directories..."
@rm -rf $(BUILD_DIR_DEBUG) $(BUILD_DIR_RELEASE)
install:
@echo "Installing TauDEM to $(or $(PREFIX),/usr/local)/taudem..."
@if [ ! -d "$(BUILD_DIR_RELEASE)" ]; then \
echo "Error: Release build directory not found. Please run 'make release' first."; \
exit 1; \
fi
@cd $(BUILD_DIR_RELEASE) && cmake . -DCMAKE_INSTALL_PREFIX=$(or $(PREFIX),/usr/local)
@cd $(BUILD_DIR_RELEASE) && make install
@echo "=== Validating installation ==="
@test -f "$(or $(PREFIX),/usr/local)/taudem/pitremove" || (echo "ERROR: pitremove not installed" && exit 1)
@echo "SUCCESS: TauDEM installation validated"
uninstall:
@echo "Uninstalling TauDEM..."
@rm -rf $(or $(PREFIX),/usr/local)/taudem
help:
@echo "Makefile usage:"
@echo " make debug COMPILER=<compiler> - Build in Debug mode with specified compiler (linux, macos, clang, gcc-apple)"
@echo " make debug COMPILER=<compiler> TARGET=<target> - Build specific target in Debug mode with specified compiler (linux, macos, clang, gcc-apple)"
@echo " make release COMPILER=<compiler> - Build in Release mode with specified compiler (linux, macos, clang, gcc-apple)"
@echo " make release COMPILER=<compiler> TARGET=<target> - Build specific target in Release mode with specified compiler (linux, macos, clang, gcc-apple)"
@echo " make dk-run-tests - Run TauDEM tests in Docker environment"
@echo " make clean - Clean build directories"
@echo " make install [PREFIX=<path>] - Install TauDEM (default: /usr/local)"
@echo " make uninstall - Remove TauDEM installation"
@echo " make help - Show this help message"
@echo ""
@echo "Note: For Windows builds, use build-windows.bat instead"