-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
260 lines (233 loc) · 10 KB
/
Copy pathMakefile
File metadata and controls
260 lines (233 loc) · 10 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# Makefile for ComChemKit
# Enhanced Safety Edition v0.000.1
# Directory structure
SRC_DIR = src
BUILD_DIR = build
TEST_DIR = tests
# Compiler settings
# Allow CXX override from environment, otherwise auto-detect
ifndef CXX
# Auto-detect compiler. Prefers Intel compilers (icpx, icpc, icc) over GCC (g++).
COMPILER_LIST := icpx icpc icc g++
CXX := $(firstword $(foreach c,$(COMPILER_LIST),$(if $(shell command -v $(c)),$(c))))
endif
# Fallback to a default if no compiler is found in PATH and print a warning.
ifeq ($(CXX),)
$(warning "No supported compiler (icpx, icpc, icc, g++) found in PATH. Defaulting to g++.")
CXX = g++
endif
$(info Using compiler: $(CXX))
CXXFLAGS = -std=c++17 -Wall -Wextra -O3 -pthread -I$(SRC_DIR)
# Add Intel-specific flags if using Intel compiler
ifneq ($(filter icpx icpc icc,$(CXX)),)
CXXFLAGS += -fp-model=precise
endif
DEBUGFLAGS = -g -DDEBUG_BUILD -fsanitize=address -fno-omit-frame-pointer
LDFLAGS = -pthread
# Add Intel-specific linking flags after LDFLAGS definition
ifneq ($(filter icpx icpc icc,$(CXX)),)
# Intel compilers often require explicit TBB linking for parallel algorithms
# Add TBB library if available, with error handling
LDFLAGS += -ltbb
# Use -static-libstdc++ to avoid loading library
#LDFLAGS += -ltbb -static-libstdc++
# Note: If TBB is not available, the compilation will fail with a clear error
# In such cases, users should install Intel TBB or use GCC instead
$(info Intel compiler detected. Adding TBB library linking.)
$(info If compilation fails with TBB errors, please install Intel TBB or use GCC.)
endif
# Platform detection
ifeq ($(OS),Windows_NT)
UNAME_S := Windows
else
UNAME_S := $(shell uname -s)
endif
ifeq ($(UNAME_S),Linux)
LDFLAGS += -lrt -lstdc++fs
endif
ifeq ($(UNAME_S),Darwin)
# macOS specific flags if needed
endif
# Source files
SOURCES = $(SRC_DIR)/main.cpp \
$(SRC_DIR)/commands/signal_handler.cpp \
$(SRC_DIR)/extraction/qc_extractor.cpp \
$(SRC_DIR)/job_management/job_scheduler.cpp \
$(SRC_DIR)/commands/command_system.cpp \
$(SRC_DIR)/job_management/job_checker.cpp \
$(SRC_DIR)/utilities/config_manager.cpp \
$(SRC_DIR)/utilities/metadata.cpp \
$(SRC_DIR)/high_level/high_level_energy.cpp \
$(SRC_DIR)/extraction/coord_extractor.cpp \
$(SRC_DIR)/input_gen/parameter_parser.cpp \
$(SRC_DIR)/utilities/utils.cpp \
$(SRC_DIR)/ui/interactive_mode.cpp \
$(SRC_DIR)/input_gen/create_input.cpp \
$(SRC_DIR)/ui/help_utils.cpp \
$(SRC_DIR)/thermo/thermo.cpp \
$(SRC_DIR)/thermo/calc.cpp \
$(SRC_DIR)/thermo/loadfile.cpp \
$(SRC_DIR)/thermo/util.cpp \
$(SRC_DIR)/thermo/atommass.cpp \
$(SRC_DIR)/thermo/symmetry.cpp \
$(SRC_DIR)/thermo/help_utils.cpp \
$(SRC_DIR)/commands/command_registry.cpp \
$(SRC_DIR)/commands/extract_command.cpp \
$(SRC_DIR)/commands/checker_command.cpp \
$(SRC_DIR)/commands/high_level_command.cpp \
$(SRC_DIR)/commands/extract_coords_command.cpp \
$(SRC_DIR)/commands/create_input_command.cpp \
$(SRC_DIR)/commands/thermo_command.cpp \
$(SRC_DIR)/commands/ivcoord_command.cpp \
$(SRC_DIR)/ivcoord/gaussian_ivcoord_parser.cpp \
$(SRC_DIR)/ivcoord/ivcoord_runner.cpp
HEADERS = $(SRC_DIR)/commands/signal_handler.h \
$(SRC_DIR)/extraction/qc_extractor.h \
$(SRC_DIR)/job_management/job_scheduler.h \
$(SRC_DIR)/commands/command_system.h \
$(SRC_DIR)/job_management/job_checker.h \
$(SRC_DIR)/utilities/config_manager.h \
$(SRC_DIR)/utilities/metadata.h \
$(SRC_DIR)/high_level/high_level_energy.h \
$(SRC_DIR)/extraction/coord_extractor.h \
$(SRC_DIR)/input_gen/parameter_parser.h \
$(SRC_DIR)/utilities/utils.h \
$(SRC_DIR)/utilities/version.h \
$(SRC_DIR)/ui/interactive_mode.h \
$(SRC_DIR)/input_gen/create_input.h \
$(SRC_DIR)/ui/help_utils.h \
$(SRC_DIR)/thermo/thermo.h \
$(SRC_DIR)/thermo/calc.h \
$(SRC_DIR)/thermo/loadfile.h \
$(SRC_DIR)/thermo/util.h \
$(SRC_DIR)/thermo/atommass.h \
$(SRC_DIR)/thermo/symmetry.h \
$(SRC_DIR)/thermo/chemsys.h \
$(SRC_DIR)/thermo/help_utils.h \
$(SRC_DIR)/commands/icommand.h \
$(SRC_DIR)/commands/command_registry.h \
$(SRC_DIR)/commands/extract_command.h \
$(SRC_DIR)/commands/checker_command.h \
$(SRC_DIR)/commands/high_level_command.h \
$(SRC_DIR)/commands/extract_coords_command.h \
$(SRC_DIR)/commands/create_input_command.h \
$(SRC_DIR)/commands/thermo_command.h \
$(SRC_DIR)/commands/ivcoord_command.h \
$(SRC_DIR)/ivcoord/ivcoord_data.h \
$(SRC_DIR)/ivcoord/ivcoord_parser_base.h \
$(SRC_DIR)/ivcoord/gaussian_ivcoord_parser.h \
$(SRC_DIR)/ivcoord/ivcoord_runner.h
OBJECTS = $(SOURCES:%.cpp=$(BUILD_DIR)/%.o)
TARGET = $(BUILD_DIR)/bin/cck
# Ensure build directory structure exists (cross-platform fallback using CMake)
MKDIR_P = cmake -E make_directory $1
$(shell $(call MKDIR_P,$(BUILD_DIR)/bin))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/extraction))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/high_level))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/input_gen))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/job_management))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/ui))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/utilities))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/thermo))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/commands))
$(shell $(call MKDIR_P,$(BUILD_DIR)/$(SRC_DIR)/ivcoord))
# Default target
all: $(TARGET)
# Build the main executable
$(TARGET): $(OBJECTS)
$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
# Compile source files to object files
$(BUILD_DIR)/%.o: %.cpp $(HEADERS)
@$(call MKDIR_P,$(dir $@))
$(CXX) $(CXXFLAGS) -c $< -o $@
# Debug build with additional safety checks
debug: CXXFLAGS += $(DEBUGFLAGS)
debug: LDFLAGS += -fsanitize=address
debug: clean $(TARGET)
# Release build with optimizations
release: CXXFLAGS += -O3 -DNDEBUG -march=native
release: clean $(TARGET)
# Cluster-safe build (conservative optimizations)
cluster: CXXFLAGS += -O2 -DCLUSTER_BUILD
cluster: clean $(TARGET)
# Clean build artifacts
clean:
cmake -E rm -rf $(BUILD_DIR) $(TARGET)
# Install to system (requires sudo)
install: $(TARGET)
mkdir -p /usr/local/bin
cp $(TARGET) /usr/local/bin/
chmod +x /usr/local/bin/$(TARGET)
# Install to user's local bin
install-user: $(TARGET)
mkdir -p ~/bin
cp $(TARGET) ~/bin/
chmod +x ~/bin/$(TARGET)
# Create a test build with maximum warnings
test-build: CXXFLAGS += -Wpedantic -Wcast-align -Wcast-qual -Wctor-dtor-privacy \
-Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op \
-Wmissing-declarations -Wmissing-include-dirs -Wnoexcept \
-Wold-style-cast -Woverloaded-virtual -Wredundant-decls \
-Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel \
-Wstrict-overflow=5 -Wswitch-default -Wundef
test-build: clean $(TARGET)
# Quick test with sample files
test: $(TARGET)
@echo "Testing ComChemKit..."
@if [ -f $(TEST_DIR)/data/test-1.log ] && [ -f $(TEST_DIR)/data/test-2.log ]; then \
./$(TARGET) --resource-info; \
./$(TARGET) -q -f csv; \
echo "Test completed. Check output files."; \
else \
echo "Test files not found. Please ensure test files exist in $(TEST_DIR)/data/"; \
fi
# Check for memory leaks (requires valgrind)
memcheck: debug
@if command -v valgrind >/dev/null 2>&1; then \
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes \
./$(TARGET) -q; \
else \
echo "Valgrind not found. Install valgrind for memory checking."; \
fi
# Create distribution package
dist: clean
@mkdir -p gaussian-extractor-$(shell date +%Y%m%d)
@cp -r $(SRC_DIR) $(TEST_DIR) docs scripts CMakeLists.txt README.MD .clang-format gaussian-extractor-$(shell date +%Y%m%d)/
@tar czf gaussian-extractor-$(shell date +%Y%m%d).tar.gz gaussian-extractor-$(shell date +%Y%m%d)/
@rm -rf gaussian-extractor-$(shell date +%Y%m%d)/
@echo "Distribution package created: gaussian-extractor-$(shell date +%Y%m%d).tar.gz"
# Help target
help:
@echo "ComChemKit Makefile - Available targets:"
@echo ""
@echo " all - Build the program (default)"
@echo " debug - Build with debug symbols and AddressSanitizer"
@echo " release - Build optimized release version"
@echo " cluster - Build cluster-safe version"
@echo " test-build - Build with maximum compiler warnings"
@echo " clean - Remove build artifacts"
@echo " install - Install to /usr/local/bin (requires sudo)"
@echo " install-user - Install to ~/bin"
@echo " test - Run basic functionality test"
@echo " memcheck - Run with valgrind memory checker"
@echo " dist - Create distribution package"
@echo " help - Show this help message"
@echo ""
@echo "Compiler Support:"
@echo " Auto-detects: icpx, icpc, icc, g++ (in order of preference)"
@echo " Force GCC: make CXX=g++"
@echo " Intel issues: Requires TBB library. If compilation fails with"
@echo " 'execution' or TBB errors, use: make CXX=g++"
@echo ""
@echo "Version Management:"
@echo " scripts/update_version.sh <version> - Update version across all files"
@echo " ./cck --version - Check current version"
@echo ""
@echo "Usage examples:"
@echo " make # Build with default settings"
@echo " make CXX=g++ # Force GCC compilation"
@echo " make debug # Build debug version"
@echo " make cluster # Build for cluster deployment"
@echo " make clean install-user # Clean build and install to user bin"
# Declare phony targets
.PHONY: all debug release cluster clean install install-user test-build test memcheck dist help