Skip to content

Commit 7d27e1d

Browse files
authored
Update Makefile
1 parent 8643b65 commit 7d27e1d

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

source/Makefile

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# This is the Makefile of ABACUS
2-
include Makefile.vars
2+
ABACUS_ROOT := $(dir$(firstword $(MAKEFILE_LIST)))
3+
4+
BUILD_DIR ?= build
5+
OBJ_DIR = $(BUILD_DIR)/obj
6+
BIN_DIR = $(BUILD_DIR)/bin
7+
BUILD_INFO_DIR = $(BUILD_DIR)/source_io
8+
9+
include $(ABACUS_ROOT)Makefile.vars
10+
311
#==========================
412
# Compiler information
513
#==========================
6-
7-
INCLUDES = -I. -Isource_main -Isource_main/commands -Icommands -I../ -Isource_base/module_container
14+
INCLUDES = -I$(ABACUS_ROOT) -I$(ABACUS_ROOT)source_main -I$(ABACUS_ROOT)source_main/commands -I$(ABACUS_ROOT)commands -I$(BUILD_INFO_DIR) -I$(ABACUS_ROOT)../ -I$(ABACUS_ROOT)source_base/module_container
815

916
LIBS = -lm -lpthread
1017
OPTS = -std=c++14 -pedantic -m64 ${INCLUDES}
@@ -213,8 +220,10 @@ FP_OBJS=$(patsubst %.o, ${OBJ_DIR}/%.o, ${OBJS_ABACUS})
213220
# Rule to generate the build_info.h file using the shell script.
214221
# This rule is executed whenever build_info.h.in, the script, or any of the
215222
# relevant Makefile variables change.
216-
source_io/build_info.h: source_io/build_info.h.in ../generate_build_info.sh
223+
$(BUILD_INFO_DIR)/build_info.h:$(ABACUS_ROOT)source_io/build_info.h.in $(ABACUS_ROOT)../generate_build_info.sh
217224
@echo "Generating build information header..."
225+
@# Make sure directory is available
226+
@mkdir -p $(dir$@)
218227
@# Export all necessary Makefile variables as environment for the script
219228
@export BUILD_TYPE="Release"; \
220229
if [ "$(DEBUG)" = "ON" ]; then export BUILD_TYPE="Debug"; export ENABLE_ASAN="yes"; else export ENABLE_ASAN="no"; fi; \
@@ -233,12 +242,13 @@ source_io/build_info.h: source_io/build_info.h.in ../generate_build_info.sh
233242
if [ "$(MPI)" = "ON" ]; then export ENABLE_MPI="ON"; fi; \
234243
export USE_CUDA="no"; \
235244
if [ "$(GPU)" = "CUDA" ]; then export USE_CUDA="ON"; fi; \
236-
../generate_build_info.sh
245+
$(ABACUS_ROOT)../generate_build_info.sh
237246
@echo "Build information header generated."
238247

239-
# Specific rule for parse_args.o to enforce dependency on build_info.h.
240-
# This overrides the generic %.o:%.cpp rule for this specific file.
241-
${OBJ_DIR}/parse_args.o: source_io/parse_args.cpp source_io/build_info.h
248+
# Specific rule for parse_args.o to enforce dependency on build_info.h.
249+
# This overrides the generic %.o:%.cpp rule for this specific file.
250+
${OBJ_DIR}/parse_args.o: $(ABACUS_ROOT)source_io/parse_args.cpp $(BUILD_INFO_DIR)build_info.h
251+
@mkdir -p $(dir$@)
242252
${CXX} ${OPTS} ${OPTS_MPI} -c ${HONG} $< -o $@
243253

244254
###### END of ABACUS INFO PART ######
@@ -253,26 +263,26 @@ abacus:
253263

254264
test:
255265
@ $(MAKE) abacus
256-
@ cd ../tests/integrate/;sh Autotest.sh -a ../../../bin/ABACUS.mpi -n $(TESTNP)
266+
@ cd $(ABACUS_ROOT)../tests/integrate/;sh Autotest.sh -a $(realpath $(BIN_DIR))/ABACUS.mpi -n $(TESTNP)
257267

258268
pw $(BIN_DIR)/${VERSION}-PW.x:
259269
@ if [ ! -d $(BIN_DIR) ]; then mkdir $(BIN_DIR); fi
260-
@ cd source_pw/module_pwdft; $(MAKE) CXX=${CXX} GPU=${GPU} DEBUG=$(DEBUG) FFTW_DIR=$(FFTW_DIR) OPENBLAS_LIB_DIR=$(OPENBLAS_LIB_DIR) ${PWTAG}
261-
@ cp source_pw/module_pwdft/${VERSION}-PW.x $(BIN_DIR)/${VERSION}-PW.x
270+
@ cd $(ABACUS_ROOT)source_pw/module_pwdft; $(MAKE) CXX=${CXX} GPU=${GPU} DEBUG=$(DEBUG) FFTW_DIR=$(FFTW_DIR) OPENBLAS_LIB_DIR=$(OPENBLAS_LIB_DIR) ${PWTAG}
271+
@ cp $(ABACUS_ROOT)source_pw/module_pwdft/${VERSION}-PW.x $(realpath $(BIN_DIR))/${VERSION}-PW.x
262272

263273
$(BIN_DIR)/${VERSION}.$(suffix) : ${FP_OBJS} ${PDIAG_OBJS} ${HEADERS}
274+
@mkdir -p $(dir$@)
264275
${CXX} ${OPTS} ${OPTS_MPI} $(FP_OBJS) ${PDIAG_OBJS} ${LIBS} -o $(BIN_DIR)/${VERSION}.$(suffix)
265276

266277
#==========================
267278
# rules
268279
#==========================
269280
# Note: The specific rule for parse_args.o above is more precise.
270281
# This generic rule will apply to all other .cpp files.
271-
${OBJ_DIR}/%.o:%.cpp
282+
${OBJ_DIR}/%.o:$(realpath $(BIN_DIR))%.cpp
272283
${CXX} ${OPTS} ${OPTS_MPI} -c ${HONG} $< -o $@
273284

274285
.PHONY:clean test
275286
clean:
276-
@ if [ -d $(OBJ_DIR) ]; then rm -rf $(OBJ_DIR); fi
277-
@ if [ -d $(BIN_DIR) ]; then rm -rf $(BIN_DIR); fi
278-
@ cd source_pw/module_pwdft; make clean
287+
@ echo "Cleaning build directory: $(BUILD_DIR)"
288+
@ rm -rf $(BUILD_DIR)

0 commit comments

Comments
 (0)