From 2109f3ade9d6a202c413ed9ad3e3475caa944ae3 Mon Sep 17 00:00:00 2001 From: Charles BIENVENUE Date: Wed, 5 Nov 2025 22:47:07 +0000 Subject: Parallel Build, OpenMP Support with Fortran 90, and Improved Module Dependencies --- Donjon/src/Makefile | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'Donjon/src') diff --git a/Donjon/src/Makefile b/Donjon/src/Makefile index f236c5e..b68f26a 100644 --- a/Donjon/src/Makefile +++ b/Donjon/src/Makefile @@ -1,7 +1,7 @@ #--------------------------------------------------------------------------- # # Makefile for building the Donjon library and load module -# Author : A. Hebert (2018-5-10) +# Author : A. Hebert (2018-5-10) and C. Bienvenue (2025-11-04) # #--------------------------------------------------------------------------- # @@ -20,6 +20,8 @@ DIRNAME = $(shell uname -sm | sed 's/[ ]/_/') OS = $(shell uname -s | cut -d"_" -f1) opt = -O -g PREPRO = cpp +DEFAULT_GOAL_PLACEHOLDER := +.DEFAULT_GOAL := all ifeq ($(openmp),1) COMP = -fopenmp PREPRO = cpp -D_OPENMP @@ -46,12 +48,11 @@ else endif ifeq ($(OS),AIX) - python_version_major := 2 + PY := python else - python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1))) - python_version_major := $(word 1,${python_version_full}) - ifneq ($(python_version_major),2) - python_version_major := 3 + PY := $(shell command -v python3 2>/dev/null) + ifeq ($(PY),) + PY := $(shell command -v python 2>/dev/null) endif endif @@ -161,7 +162,9 @@ else lib_module = ../lib/$(DIRNAME)_llvm/modules INCLUDE = -I../../Ganlib/lib/$(DIRNAME)_llvm/modules/ -I../../Utilib/lib/$(DIRNAME)_llvm/modules/ FFLAGS += -mmlir -fdynamic-heap-array - LFLAGS += -lclang_rt.osx + ifeq ($(OS),Darwin) + LFLAGS += -lclang_rt.osx + endif else lib = ../lib/$(DIRNAME) libUtl = ../../Utilib/lib/$(DIRNAME) @@ -181,18 +184,32 @@ ifeq ($(hdf5),1) LFLAGS += -L${HDF5_API} -lhdf5 endif -SRCC = $(shell ls *.c) -SRC77 = $(shell ls *.f) -SRCF77 = $(shell ls *.F) -ifeq ($(python_version_major),2) - SRC90 = $(shell python ../../script/make_depend.py *.f90) +SRCC = $(shell ls *.c 2>/dev/null) +SRC77 = $(shell ls *.f 2>/dev/null) +SRCF77 = $(shell ls *.F 2>/dev/null) +ifeq ($(PY),) + $(warning No Python interpreter found; Fortran dependency ordering may be suboptimal) + SRC90 = $(shell ls *.f90 2>/dev/null) else - SRC90 = $(shell python3 ../../script/make_depend_py3.py *.f90) + SRC90 = $(shell $(PY) ../../script/make_depend.py *.f90 *.F90) + endif OBJC = $(SRCC:.c=.o) -OBJ90 = $(SRC90:.f90=.o) +OBJ90 = $(patsubst %.f90,%.o,$(patsubst %.F90,%.o,$(SRC90))) OBJ77 = $(SRC77:.f=.o) OBJF77 = $(SRCF77:.F=.o) + +# Auto-generated dependency file capturing Fortran module and include deps +DEPS_MK := .donjon_deps.mk +-include $(DEPS_MK) +$(DEPS_MK): $(SRC90) $(SRC77) $(SRCF77) +ifeq ($(PY),) + @echo "# Dependencies not generated: no Python available" > $(DEPS_MK) +else + @echo "# Generating Fortran dependencies into $(DEPS_MK)"; \ + $(PY) ../../script/make_depend.py --make-deps $(SRC90) $(SRC77) $(SRCF77) > $(DEPS_MK) || { rm -f $(DEPS_MK); exit 1; } +endif + all : sub-make Donjon ifeq ($(openmp),1) @echo 'Donjon: openmp is defined' @@ -227,7 +244,7 @@ $(lib_module)/: $(lib)/: $(lib_module)/ mkdir -p $(lib)/ libDonjon.a: $(OBJC) $(OBJ90) $(OBJ77) $(OBJF77) $(lib)/ - ar r $@ $(OBJC) $(OBJ90) $(OBJ77) $(OBJF77) + ar rcs $@ $(OBJC) $(OBJ90) $(OBJ77) $(OBJF77) cp $@ $(lib)/$@ cp *.mod $(lib_module) $(bin)/: @@ -238,4 +255,4 @@ Donjon: libDonjon.a DONJON.o $(bin)/ sub-make cp $@ $(bin)/$@ clean: $(MAKE) -C ../../Dragon/src clean - /bin/rm -f *.o *.mod *.a sub-make temp.* Donjon + /bin/rm -f *.o *.mod *.a sub-make temp.* Donjon $(DEPS_MK) -- cgit v1.2.3