diff options
| author | Charles BIENVENUE <charles.bienvenue@polymtl.ca> | 2025-11-05 22:47:07 +0000 |
|---|---|---|
| committer | Charles BIENVENUE <charles.bienvenue@polymtl.ca> | 2025-11-05 22:47:07 +0000 |
| commit | 2109f3ade9d6a202c413ed9ad3e3475caa944ae3 (patch) | |
| tree | 7e9ad87417236520023804b629e15e572bcb7c9d /Utilib/src/Makefile | |
| parent | 8e8dd16f67ed325e2bf7fca0a9d878a18e6911ae (diff) | |
Parallel Build, OpenMP Support with Fortran 90, and Improved Module Dependencies
Diffstat (limited to 'Utilib/src/Makefile')
| -rw-r--r-- | Utilib/src/Makefile | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/Utilib/src/Makefile b/Utilib/src/Makefile index 2bb6d73..e56d213 100644 --- a/Utilib/src/Makefile +++ b/Utilib/src/Makefile @@ -1,7 +1,7 @@ #--------------------------------------------------------------------------- # # Makefile for building the Utilib library -# Author : A. Hebert (2018-5-10) +# Author : A. Hebert (2018-5-10) and C. Bienvenue (2025-11-04) # #--------------------------------------------------------------------------- # @@ -19,6 +19,7 @@ endif DIRNAME = $(shell uname -sm | sed 's/[ ]/_/') OS = $(shell uname -s | cut -d"_" -f1) opt = -O -g +.DEFAULT_GOAL := all ifeq ($(openmp),1) COMP = -fopenmp else @@ -44,12 +45,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 @@ -128,7 +128,9 @@ else lib = ../lib/$(DIRNAME)_llvm lib_module = ../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) lib_module = ../lib/$(DIRNAME)/modules @@ -136,16 +138,29 @@ else endif endif -SRCC = $(shell ls *.c) -SRC77 = $(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) +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) + + # Auto-generated dependency file capturing Fortran module and include deps +DEPS_MK := .utilib_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 : libUtilib.a @echo 'Utilib: fflags=' $(FFLAGS) ifeq ($(openmp),1) @@ -158,9 +173,9 @@ ifeq ($(nvidia),1) @echo 'Utilib: nvidia is defined' endif ifeq ($(llvm),1) -] @echo 'Utilib: llvm is defined' + @echo 'Utilib: llvm is defined' endif - @echo "Utilib: python version=" ${python_version_major} + @echo "Utilib: python=" $(PY) %.o : %.c $(C) $(CFLAGS) $(opt) $(COMP) -c $< -o $@ %.o : %.f90 @@ -173,8 +188,8 @@ $(lib_module)/: $(lib)/: $(lib_module)/ mkdir -p $(lib)/ libUtilib.a: $(OBJC) $(OBJ90) $(OBJ77) $(lib)/ - ar r $@ $(OBJC) $(OBJ90) $(OBJ77) + ar rcs $@ $(OBJC) $(OBJ90) $(OBJ77) cp $@ $(lib)/$@ cp *.mod $(lib_module) clean: - /bin/rm -f *.o *.mod *.a + /bin/rm -f *.o *.mod *.a $(DEPS_MK) |
