From 1504bca61c7b0dad30031b65edb45c916a146181 Mon Sep 17 00:00:00 2001 From: Paul Gierz Date: Thu, 29 Dec 2022 10:02:15 -0800 Subject: [PATCH] Adds makefile and small readme --- .gitignore | 35 +++++++++++++++++++++++++++ Makefile | 23 ++++++++++++++++++ README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a710d05 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# Directories for build and binary +build/ +bin/ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..34c068b --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +FC = gfortran +FFLAGS = -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single + +all: esm_dummy_model.o libesm_dummy_model.a app_main.f90.o + mkdir bin + $(FC) $(FFLAGS) build/$(FC)/esm_dummy_model/app_main.f90.o build/gfortran/esm_dummy_model/libesm_dummy_model.a -o bin/esm_dummy_model + +prepare: + mkdir -p build/dependencies + mkdir -p build/$(FC) + mkdir -p build/$(FC)/esm_dummy_model/ + +esm_dummy_model.o: prepare + $(FC) -c ././src/esm_dummy_model.f90 $(FFLAGS) -J build/$(FC) -Ibuild/$(FC) -o build/$(FC)/esm_dummy_model/src_esm_dummy_model.f90.o + +libesm_dummy_model.a: esm_dummy_model.o + ar -rs build/$(FC)/esm_dummy_model/libesm_dummy_model.a build/$(FC)/esm_dummy_model/src_esm_dummy_model.f90.o + +app_main.f90.o: + $(FC) -c app/main.f90 $(FFLAGS) -J build/$(FC) -Ibuild/$(FC) -o build/$(FC)/esm_dummy_model/app_main.f90.o + +clean: + rm -rf build bin diff --git a/README.md b/README.md index b2f498e..4ec7fa3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,67 @@ -# esm_dummy_model -My cool new project! +# `esm_dummy_model`: A Minimal Fortran "Model" for Testing + +This is a minimal `FORTRAN` program, made with +[`fpm`](https://fpm.fortran-lang.org/en/index.html). It counts to 5 while +sleeping. + +# Install + +First, you can download the code via git: +```console +$ git clone https://github.com/esm-tools/esm_dummy_model.git +$ cd esm_dummy_model +``` + +If you have [`fpm` installed (see link for +instructions)](https://fpm.fortran-lang.org/en/install/index.html#install) +you can build and then run it with simple `fpm` commands: + +```console +$ fpm build # <-- will build the binary + + mkdir -p build/gfortran_2A42023B310FA28D + + mkdir -p build/gfortran_2A42023B310FA28D/esm_dummy_model/ + + gfortran -c ././src/esm_dummy_model.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D -Ibuild/gfortran_2A42023B310FA28D -o build/gfortran_2A42023B310FA28D/esm_dummy_model/src_esm_dummy_model.f90.o + + ar -rs build/gfortran_2A42023B310FA28D/esm_dummy_model/libesm_dummy_model.a build/gfortran_2A42023B310FA28D/esm_dummy_model/src_esm_dummy_model.f90.o +ar: creating archive build/gfortran_2A42023B310FA28D/esm_dummy_model/libesm_dummy_model.a + + gfortran -c app/main.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D -Ibuild/gfortran_2A42023B310FA28D -o build/gfortran_2A42023B310FA28D/esm_dummy_model/app_main.f90.o + + mkdir -p build/gfortran_2A42023B310FA28D/app/ + + gfortran -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single build/gfortran_2A42023B310FA28D/esm_dummy_model/app_main.f90.o build/gfortran_2A42023B310FA28D/esm_dummy_model/libesm_dummy_model.a -o build/gfortran_2A42023B310FA28D/app/esm_dummy_model +$ fpm run # <-- will build if needed, and immediately run the program + Hello, esm_dummy_model! + Sleeping... 1 + Sleeping... 2 + Sleeping... 3 + Sleeping... 4 + Sleeping... 5 + Goodbye, esm_dummy_model! +$ fpm install # <-- will put the binary into ${HOME}/.local/bin +# Update: build/gfortran_2A42023B310FA28D/app/esm_dummy_model -> /Users/pgierz/.local/bin +``` + +For testing use with the ESM Tools, we also have a small Makefile: + +```console +$ make clean +rm -rf build bin +$ make +mkdir -p build/dependencies +mkdir -p build/gfortran +mkdir -p build/gfortran/esm_dummy_model/ +gfortran -c ././src/esm_dummy_model.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran -Ibuild/gfortran -o build/gfortran/esm_dummy_model/src_esm_dummy_model.f90.o +ar -rs build/gfortran/esm_dummy_model/libesm_dummy_model.a build/gfortran/esm_dummy_model/src_esm_dummy_model.f90.o +ar: creating archive build/gfortran/esm_dummy_model/libesm_dummy_model.a +gfortran -c app/main.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran -Ibuild/gfortran -o build/gfortran/esm_dummy_model/app_main.f90.o +mkdir bin +gfortran -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single build/gfortran/esm_dummy_model/app_main.f90.o build/gfortran/esm_dummy_model/libesm_dummy_model.a -o bin/esm_dummy_model +``` +You can now run the program (found in `bin/`): +```console +$ ./bin/esm_dummy_model + Hello, esm_dummy_model! + Sleeping... 1 + Sleeping... 2 + Sleeping... 3 + Sleeping... 4 + Sleeping... 5 + Goodbye, esm_dummy_model! +```