diff --git a/CMakeLists.txt b/CMakeLists.txt index 207fc79..3a46dd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,40 +4,40 @@ project(PE-Fortran VERSION 0.0.4 HOMEPAGE_URL https://github.com/han190/PE-Fortran LANGUAGES Fortran) -if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") +if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") + if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + if (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0) + message(FATAL_ERROR gfortran >= ${CMAKE_Fortran_COMPILER_VERSION}) + endif() + message(STATUS "Using gfortran ${CMAKE_Fortran_COMPILER_VERSION}.") - if (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0) - message(FATAL_ERROR gfortran >= ${CMAKE_Fortran_COMPILER_VERSION}) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + message(STATUS "Compiling in debug mode.") + set(CMAKE_Fortran_FLAGS "-g -O0 -Wall -Wextra -pedantic -fbounds-check \ + -fimplicit-none -fPIC -Wno-uninitialized -fcheck=all -fbacktrace \ + -ffree-form -fcheck=array-temps -Werror=implicit-interface \ + -std=f2018 -march=native") + elseif (CMAKE_BUILD_TYPE STREQUAL "Release") + message(STATUS "Compiling in release mode.") + set(CMAKE_Fortran_FLAGS "-O3 -march=native -std=f2018 -march=native") + endif() + elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM") + if (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 2021.11) + message(FATAL_ERROR ifx >= ${CMAKE_Fortran_COMPILER_VERSION}) + endif() + message(STATUS "Using ifx ${CMAKE_Fortran_COMPILER_VERSION}.") + + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + message(STATUS "Compiling in debug mode.") + set(CMAKE_Fortran_FLAGS "-O0 -warn all -check all,nouninit \ + -g -traceback -no-simd -stand f18 -mtune=native") + elseif (CMAKE_BUILD_TYPE STREQUAL "Release") + message(STATUS "Compiling in release mode.") + set(CMAKE_Fortran_FLAGS "-O1 -ipo -xHost -stand f18 -mtune=native") + endif() endif() - message(STATUS "Using gfortran ${CMAKE_Fortran_COMPILER_VERSION}.") - - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - message(STATUS "Compiling in debug mode.") - set(CMAKE_Fortran_FLAGS "-g -O0 -Wall -Wextra -pedantic -fbounds-check \ - -fimplicit-none -fPIC -Wno-uninitialized -fcheck=all -fbacktrace \ - -ffree-form -fcheck=array-temps -Werror=implicit-interface \ - -std=f2018 -march=native") - elseif (CMAKE_BUILD_TYPE STREQUAL "Release") - message(STATUS "Compiling in release mode.") - set(CMAKE_Fortran_FLAGS "-O3 -march=native -std=f2018 -march=native") - endif() - -elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM") - - if (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 2021.11) - message(FATAL_ERROR ifx >= ${CMAKE_Fortran_COMPILER_VERSION}) - endif() - message(STATUS "Using ifx ${CMAKE_Fortran_COMPILER_VERSION}.") - - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - message(STATUS "Compiling in debug mode.") - set(CMAKE_Fortran_FLAGS "-O0 -warn all -check all,nouninit \ - -g -traceback -no-simd -stand f18 -mtune=native") - elseif (CMAKE_BUILD_TYPE STREQUAL "Release") - message(STATUS "Compiling in release mode.") - set(CMAKE_Fortran_FLAGS "-O1 -ipo -xHost -stand f18 -mtune=native") - endif() - +else() + message(FATAL_ERROR "Unsupported OS.") endif() # Build static library diff --git a/Makefile b/Makefile deleted file mode 100644 index a73a774..0000000 --- a/Makefile +++ /dev/null @@ -1,112 +0,0 @@ -compiler?=gfortran -profile?=release -src_dir:=src -current_dir=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) -build_dir=$(current_dir)build/$(compiler)_$(profile)_makefile -data_dir=$(current_dir)data -include_dir=$(build_dir)/include -local_dir=${HOME}/.local -prefix=$(local_dir)/bin -data_prefix=$(local_dir)/share/PE-Fortran-data -args?= - -ifeq ($(compiler), gfortran) - compiler_flags=-std=f2018 -march=native - ifeq ($(profile), debug) - compiler_flags+=-g -O0 -Wall -Wextra -pedantic -fbounds-check \ - -fimplicit-none -fPIC -Wno-uninitialized -fcheck=all -fbacktrace \ - -ffree-form -fcheck=array-temps -Werror=implicit-interface - else ifeq ($(profile), release) - compiler_flags+=-O3 -march=native - endif - compile=$(compiler) $(compiler_flags) \ - -I$(include_dir) -J$(build_dir) -else ifeq ($(compiler), ifx) - compiler_flags=-stand f18 -mtune=native - ifeq ($(profile), debug) - compiler_flags+=-O0 -warn all -check all,nouninit -g -traceback -no-simd - else ifeq ($(profile), release) - compiler_flags+=-O1 -ipo -xHost - endif - compile=$(compiler) $(compiler_flags) \ - -I$(include_dir) -module $(build_dir) - AR=xiar -endif - -# Preprocess objects -preproc_filename=module_file module_preprocessor preprocess -preproc_dir=$(src_dir)/preprocess -preproc_obj=$(addprefix $(build_dir)/, \ - $(addsuffix .o, $(preproc_filename))) - -# Toolkit objects -toolkit_filename=module_utility module_quicksort module_prime \ - module_permutation module_multiprecision module_list module_toolkit -toolkit_dir=$(src_dir)/toolkit -toolkit_obj=$(addprefix $(build_dir)/, \ - $(addsuffix .o, $(toolkit_filename))) - -# Problems objects -problems_dir=$(src_dir)/problems -problems_src=$(wildcard $(problems_dir)/*.f90) -problems_obj=$(subst $(problems_dir), $(build_dir), \ - $(patsubst %.f90, %.o, $(problems_src))) - -# PE objects -pe_filename=module_problem module_driver project_euler -pe_obj=$(addprefix $(build_dir)/, $(addsuffix .o, $(pe_filename))) - -.PHONY: clean build preprocess install test -all: $(build_dir)/PE-Preprocess preprocess \ - $(build_dir)/libpetk.a $(build_dir)/PE-Fortran - -test: - $(build_dir)/PE-Fortran -d $(data_dir) $(args) - -install: - mkdir -p $(data_prefix) - mkdir -p $(prefix) - cp $(data_dir)/* $(data_prefix) - cp $(build_dir)/PE-Preprocess $(prefix) - cp $(build_dir)/PE-Fortran $(prefix) - @echo Executables installed to $(prefix) - @echo Data copied to $(data_prefix) - @echo PE-Fortran is installed successfully. - -$(build_dir)/PE-Fortran: $(pe_obj) $(problems_obj) - $(compile) -o $@ $(pe_obj) $(problems_obj) -L$(build_dir) -lpetk - @echo PE-Fortran is built successfully. - -$(build_dir)/%.o: $(src_dir)/%.f90 - $(compile) -c $< -o $@ - -$(build_dir)/%.o: $(problems_dir)/%.f90 - $(compile) -c $< -o $@ - -libs: $(build_dir)/libpetk.a -$(build_dir)/libpetk.a: $(toolkit_obj) - $(AR) rcs $@ $(toolkit_obj) - -$(build_dir)/%.o: $(toolkit_dir)/%.f90 - $(compile) -c $< -o $@ - -preprocess: - $(build_dir)/PE-Preprocess -d $(data_prefix) -i $(include_dir) - -$(build_dir)/PE-Preprocess: $(preproc_obj) - $(compile) -o $@ $(preproc_obj) - -$(build_dir)/%.o: $(preproc_dir)/%.f90 build - $(compile) -c $< -o $@ - -build: - mkdir -p $(build_dir) $(include_dir) - -clean: - $(RM) -r $(build_dir) - @echo Build files cleaned. - -uninstall: - $(RM) $(prefix)/PE-Fortran $(prefix)/PE-Preprocess - $(RM) -r $(data_prefix) - @echo PE-Fortran uninstalled. diff --git a/src/module_driver.f90 b/src/module_driver.f90 index 376db8d..442aa92 100644 --- a/src/module_driver.f90 +++ b/src/module_driver.f90 @@ -94,9 +94,10 @@ end function problem_found !> Get arugment subroutine get_arguments() - character(len=:), allocatable :: answer_sheet, data_directory, output_format - character(len=:), allocatable :: arguments(:), keywords(:) - character(len=:), allocatable :: argument, next_argument, messages(:) + character(len=:), allocatable :: answer_directory, data_directory + character(len=:), allocatable :: keywords(:), messages(:) + character(len=:), allocatable :: arguments(:), argument, next_argument + character(len=:), allocatable :: output_format integer(int64) :: num_trails, selected integer :: argument_counts, i type(problem_type), allocatable :: problems(:) @@ -112,8 +113,8 @@ subroutine get_arguments() !> Default values data_directory = default_data_directory - allocate (character(len=500) :: answer_sheet) - answer_sheet = "answer.log" + allocate (character(len=500) :: answer_directory) + answer_directory = "." num_trails = 2 selected = 0 list_solved = .false. @@ -146,9 +147,9 @@ subroutine get_arguments() output_format = "('Data directory:', 1x, a)" write (output_unit, output_format) trim(data_directory) case ("-a", "--answer") - answer_sheet = next_argument - output_format = "('Answer sheet:', 1x, a)" - write (output_unit, output_format) trim(answer_sheet) + answer_directory = next_argument + output_format = "('Answer directory:', 1x, a)" + write (output_unit, output_format) trim(answer_directory) case ("-l", "--list") list_solved = .true. case ("-v", "--version") @@ -177,7 +178,8 @@ subroutine get_arguments() return end if call solve_problems(problems, num_trails, selected) - if (selected == 0) call print_answers(problems, trim(answer_sheet)) + if (selected == 0) call print_answers( & + & problems, trim(answer_directory)//"/answer.log") end subroutine get_arguments end module module_driver