Skip to content

Commit

Permalink
Remove all sub makefiles for Fortran code.
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanSkocic committed Nov 21, 2024
1 parent 5d5b428 commit d77da70
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 72 deletions.
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ else
btype=release
endif

PY=python
GEN_F=./scripts/gen_fortran.py
GEN_STDLIB=./scripts/gen_stdlib.py

AST_SRC=$(wildcard ./data/*.toml)
F_SRC=$(patsubst ./data/%.toml, ./src/%.f90, $(AST_SRC))
SRC_FYPP=$(wildcard ./src/*.fypp)
SRC_FYPP_F90=$(patsubst ./src/%.fypp, ./src/%.f90, $(SRC_FYPP))
STDLIB=./stdlib/stdlib_codata.f90
# ---------------------------------------------------------------------


Expand All @@ -28,15 +36,22 @@ $(LIBNAME): sources build copy_a shared

# ---------------------------------------------------------------------
# SOURCES
sources:
make -C src
make -C stdlib
sources: $(SRC_FYPP_F90) $(F_SRC) $(STDLIB)

./src/%.f90: ./data/%.toml
$(PY) $(GEN_F) $< $@

./src/%.f90: ./src/%.fypp
fypp -I ./include $< $@

./stdlib/stdlib_codata.f90: ./src/codata_constants_2022.f90
$(PY) $(GEN_STDLIB) $< $@
# ---------------------------------------------------------------------


# ---------------------------------------------------------------------
# COMPILATION
build:
build: sources
fpm build --profile=$(btype)

test: build
Expand Down Expand Up @@ -112,8 +127,7 @@ logo:
make -C media

clean:
make -C src clean
make -C stdlib clean
rm -rf $(F_SRC) $(SRC_FYPP_F90) $(STDLIB)
fpm clean --all
rm -rf API-doc/*
# ---------------------------------------------------------------------
16 changes: 16 additions & 0 deletions scripts/gen_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ def run(fpath_ast: str, fpath_code: str)->None:
fast.close()
fcode.close()

def write_version()->None:

version = None
with open("VERSION", "r") as f:
version = f.read().strip()

fobj = open('./src/codata_version.f90', "w")
fobj.write("module codata__version" + newline)
fobj.write(" !! Version" + newline)
fobj.write("implicit none" + newline)
fobj.write("private" + newline)
fobj.write(f"character(len=*), parameter :: version = \"{version:s}\"" + newline)
fobj.write("end module codata__version")
fobj.close


if __name__ == "__main__":
parser = argparse.ArgumentParser(prog='genfortran', description='Generate source code.')
Expand All @@ -80,3 +95,4 @@ def run(fpath_ast: str, fpath_code: str)->None:
args = parser.parse_args()

run(args.ast, args.code)
write_version()
26 changes: 0 additions & 26 deletions src/Makefile

This file was deleted.

24 changes: 1 addition & 23 deletions src/codata_version.f90
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
module codata__version
!! Version
use iso_fortran_env
implicit none
private

character(len=*), parameter :: version = "2.0.0"
character(len=:), allocatable, target :: version_f

public :: get_version

contains

function get_version()result(fptr)
!! Get the version.
implicit none
character(len=:), pointer :: fptr
!! Fortran pointer to a string indicating the version.

if(allocated(version_f))then
deallocate(version_f)
endif
allocate(character(len=len(version)) :: version_f)
version_f = version
fptr => version_f
end function

end module codata__version
end module codata__version
17 changes: 0 additions & 17 deletions stdlib/Makefile

This file was deleted.

0 comments on commit d77da70

Please sign in to comment.