Skip to content

Commit

Permalink
make objects go to build folder, compile in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 21, 2024
1 parent 9f36f56 commit e37bd3c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions fortran/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ BLUE=\033[0;34m
NC=\033[0m # No Color
FC?=flang-new
COV?=false
BUILD_DIR=build
SRC_DIR=src
SRC_FILES=$(wildcard $(SRC_DIR)/*.f90)
OBJ_FILES=$(patsubst $(SRC_DIR)/%.f90, $(BUILD_DIR)/%.o, $(SRC_FILES))


ifeq ($(FC),ifort)
opt_args= -Wall -Werror -march=native -qwholeprogram
else ifeq ($(FC),lfortran)
opt_args=
else ifeq ($(FC),nvfortran)
opt_args= -Wall -Werror -march=native
else ifneq (,$(findstring flang,$(FC)))
opt_args= -Werror -march=native -flto
else
opt_args= -Wall -Werror -march=native -flto
endif

ifneq ($(COV),false)
cov_args= -fprofile-arcs -ftest-coverage -O0
else ifeq ($(FC),lfortran)
cov_args=
else
cov_args= -O2
endif
Expand All @@ -23,15 +34,19 @@ help:
@echo " $(BLUE)test_auto$(NC) Run through all Fortran tests (parallel execution not implemented)."
@echo " $(BLUE)clean$(NC) Clean up any stray files."

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.f90
@mkdir -p $(BUILD_DIR)
@$(FC) $(opt_args) $(cov_args) -c $< -o $@ -J$(BUILD_DIR)

.PHONY: test
test: ../LICENSE
@$(FC) $(opt_args) $(cov_args) -c src/*.f90
@$(FC) $(opt_args) $(cov_args) *.o test.f90 -o test_runner
@$(MAKE) $(OBJ_FILES) $(MFLAGS) -j --no-print-directory
@$(FC) $(opt_args) $(cov_args) -J$(BUILD_DIR) build/*.o test.f90 -o test_runner
@./test_runner

test_%:
@$(MAKE) test $(MFLAGS)

.PHONY: clean
clean:
@rm *.o *.mod test_runner
@rm -rf $(BUILD_DIR) test_runner

0 comments on commit e37bd3c

Please sign in to comment.