Skip to content

Commit

Permalink
libamrex: add lib/pkgconfig/amrex.pc
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Apr 10, 2019
1 parent 317c978 commit 6f7257c
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 51 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ all: $(amrexlib)
distclean: realclean
$(SILENT) $(RM) GNUmakefile

install: install_lib install_headers install_fortran_modules
install: install_lib install_headers install_fortran_modules install_pkg_config

uninstall:
@echo Uninstalling...
Expand Down
2 changes: 2 additions & 0 deletions Tools/GNUMake/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ MKDEP = perl $(AMREX_HOME)/Tools/C_scripts/mkdep
MODDEP = $(AMREX_HOME)/Tools/F_scripts/dep.py
CHECKFORT = $(AMREX_HOME)/Tools/typechecker/typechecker.py
MKCONFIG = $(AMREX_HOME)/Tools/libamrex/mkconfig.py
MKPKGCONFIG = $(AMREX_HOME)/Tools/libamrex/mkpkgconfig.py

RANLIB = ranlib

Expand Down Expand Up @@ -655,6 +656,7 @@ amrexLibDir = $(AMREX_INSTALL_DIR)/lib
amrexIncludeDir = $(AMREX_INSTALL_DIR)/include
# Do different compilers have different name convention for mod files?
amrexFortModules = $(wildcard $(objEXETempDir)/*.mod)
amrexPkgconfigDir = $(AMREX_INSTALL_DIR)/lib/pkgconfig

#
# For source code manipulation
Expand Down
62 changes: 39 additions & 23 deletions Tools/GNUMake/Make.rules
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif

ifndef LINKFLAGS
ifeq ($(LINK_WITH_FORTRAN_COMPILER),TRUE)
LINKFLAGS = $(F90FLAGS)
LINKFLAGS = $(F90FLAGS) $(FMODULES)
else
LINKFLAGS = $(CXXFLAGS)
endif
Expand Down Expand Up @@ -110,13 +110,28 @@ install_fortran_modules:
install -c -m 644 "$$m" $(amrexIncludeDir); \
done

$(objEXETempDir)/amrex.pc: FORCE
@echo Generating amrex.pc ...
@ $(MKPKGCONFIG) --prefix="$(abspath $(AMREX_INSTALL_DIR))" \
--version="$(AMREX_GIT_VERSION)" \
--cflags="$(CXXFLAGS)" \
--libs="$(filter-out -L.,$(LDFLAGS)) $(libraries)" \
--libpriv="" \
--fflags="$(F90FLAGS)" \
> $@

install_pkg_config: $(objEXETempDir)/amrex.pc
@echo Installing amrex.pc ...
@if [ ! -d $(amrexPkgconfigDir) ]; then mkdir -p $(amrexPkgconfigDir); fi
$(SILENT) install -c -m 644 $< $(amrexPkgconfigDir)

$(amrexIncludeDir)/AMReX_Config.H: FORCE
@echo Generating AMReX_config.H ...
@if [ ! -d $(amrexIncludeDir) ]; then mkdir -p $(amrexIncludeDir); fi
@ $(MKCONFIG) --defines "$(CPPFLAGS)" --undefine "BL_LANG_FORT" \
--comp "$(lowercase_comp)" \
--allow-different-compiler "$(ALLOW_DIFFERENT_COMP)" \
--use-omp "$(USE_OMP)" \
@ $(MKCONFIG) --defines="$(CPPFLAGS)" --undefine="BL_LANG_FORT" \
--comp="$(lowercase_comp)" \
--allow-different-compiler="$(ALLOW_DIFFERENT_COMP)" \
--use-omp="$(USE_OMP)" \
> $@

clean::
Expand Down Expand Up @@ -158,7 +173,7 @@ clang-tidy: $(CEXE_sources)

FORCE:

.PHONY: all clean realclean file_locations tags TAGS clang-analyze clang-tidy install_lib install_headers install_fortran_modules
.PHONY: all clean realclean file_locations tags TAGS clang-analyze clang-tidy install_lib install_headers install_fortran_modules install_pkg_config

#
# Rules for objects.
Expand Down Expand Up @@ -188,9 +203,9 @@ ifeq ($(USE_GPU_PRAGMA),TRUE)
@if [ ! -d $(srcTempDir) ]; then mkdir -p $(srcTempDir); fi
@$(SHELL) -ec 'cp $< $(srcTempDir)'
$(AMREX_HOME)/Tools/F_scripts/gpu_fortran.py --fortran "$(srcTempDir)/$(<F)"
$(SILENT) $(F90CACHE) $(FC) $(FFLAGS) $(fincludes) -c $(srcTempDir)/$(<F) $(FORT_EXE_OUTPUT_OPTION)
$(SILENT) $(F90CACHE) $(FC) $(FFLAGS) $(FMODULES) $(fincludes) -c $(srcTempDir)/$(<F) $(FORT_EXE_OUTPUT_OPTION)
else
$(SILENT) $(F90CACHE) $(FC) $(FFLAGS) $(fincludes) -c $< $(FORT_EXE_OUTPUT_OPTION)
$(SILENT) $(F90CACHE) $(FC) $(FFLAGS) $(FMODULES) $(fincludes) -c $< $(FORT_EXE_OUTPUT_OPTION)
endif

$(objEXETempDir)/%.o: %.F
Expand All @@ -202,10 +217,10 @@ ifeq ($(USE_GPU_PRAGMA),TRUE)
@$(SHELL) -ec 'cp $< $(srcTempDir)'
$(AMREX_HOME)/Tools/F_scripts/gpu_fortran.py --fortran "$(srcTempDir)/$(<F)"
$(SILENT) $(FORT_CPP) -DBL_LANG_FORT -DAMREX_LANG_FORT $(CPPFLAGS) $(fincludes) $(srcTempdir)/$(<F) | $(FORTPREP) > $(srcTempDir)/$*.f
$(SILENT) $(F90CACHE) $(FC) $(FFLAGS) $(fincludes) -c $(srcTempDir)/$*.f $(FORT_EXE_OUTPUT_OPTION)
$(SILENT) $(F90CACHE) $(FC) $(FFLAGS) $(FMODULES) $(fincludes) -c $(srcTempDir)/$*.f $(FORT_EXE_OUTPUT_OPTION)
else
$(SILENT) $(FORT_CPP) -DBL_LANG_FORT -DAMREX_LANG_FORT $(CPPFLAGS) $(fincludes) $< | $(FORTPREP) > $(f77EXETempDir)/$*.f
$(SILENT) $(F90CACHE) $(FC) $(FFLAGS) $(fincludes) -c $(f77EXETempDir)/$*.f $(FORT_EXE_OUTPUT_OPTION)
$(SILENT) $(F90CACHE) $(FC) $(FFLAGS) $(FMODULES) $(fincludes) -c $(f77EXETempDir)/$*.f $(FORT_EXE_OUTPUT_OPTION)
endif

$(objEXETempDir)/%.o: %.f90
Expand All @@ -215,9 +230,9 @@ ifeq ($(USE_GPU_PRAGMA),TRUE)
@if [ ! -d $(srcTempDir) ]; then mkdir -p $(srcTempDir); fi
@$(SHELL) -ec 'cp $< $(srcTempDir)'
$(AMREX_HOME)/Tools/F_scripts/gpu_fortran.py --fortran "$(srcTempDir)/$(<F)"
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) $(fincludes) -c $(srcTempDir)/$(<F) $(FORT_EXE_OUTPUT_OPTION)
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) $(FMODULES) $(fincludes) -c $(srcTempDir)/$(<F) $(FORT_EXE_OUTPUT_OPTION)
else
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) $(fincludes) -c $< $(FORT_EXE_OUTPUT_OPTION)
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) $(FMODULES) $(fincludes) -c $< $(FORT_EXE_OUTPUT_OPTION)
endif

$(objEXETempDir)/%.o: %.F90
Expand All @@ -227,9 +242,9 @@ ifeq ($(USE_GPU_PRAGMA),TRUE)
@if [ ! -d $(srcTempDir) ]; then mkdir -p $(srcTempDir); fi
@$(SHELL) -ec 'cp $< $(srcTempDir)'
$(AMREX_HOME)/Tools/F_scripts/gpu_fortran.py --fortran "$(srcTempDir)/$(<F)"
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -c $(srcTempDir)/$(<F) $(FORT_EXE_OUTPUT_OPTION)
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) $(FMODULES) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -c $(srcTempDir)/$(<F) $(FORT_EXE_OUTPUT_OPTION)
else
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -c $< $(FORT_EXE_OUTPUT_OPTION)
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) $(FMODULES) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -c $< $(FORT_EXE_OUTPUT_OPTION)
endif

# Handle the special case of amrex_filccn for CUDA -- we need to reduce the register count.
Expand All @@ -256,9 +271,9 @@ $(objEXETempDir)/AMReX_filcc_mod.o: AMReX_filcc_mod.F90
@$(SHELL) -ec 'cp $< $(srcTempDir)'
$(AMREX_HOME)/Tools/F_scripts/gpu_fortran.py --fortran "$(srcTempDir)/$(<F)"
ifeq ($(cap_registers),1)
$(SILENT) $(F90CACHE) $(F90) $(patsubst $(cap_register_flag)$(CUDA_MAXREGCOUNT), $(cap_register_flag)128, $(F90FLAGS)) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -c $(srcTempDir)/$(<F) -o $(objEXETempDir)/AMReX_filcc_mod.o
$(SILENT) $(F90CACHE) $(F90) $(patsubst $(cap_register_flag)$(CUDA_MAXREGCOUNT), $(cap_register_flag)128, $(F90FLAGS) $(FMODULES)) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -c $(srcTempDir)/$(<F) -o $(objEXETempDir)/AMReX_filcc_mod.o
else
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -c $(srcTempDir)/$(<F) -o $(objEXETempDir)/AMReX_filcc_mod.o
$(SILENT) $(F90CACHE) $(F90) $(F90FLAGS) $(FMODULES) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -c $(srcTempDir)/$(<F) -o $(objEXETempDir)/AMReX_filcc_mod.o
endif

endif
Expand Down Expand Up @@ -375,19 +390,19 @@ $(fortran_ir_sources): $(objForTypeCheck)
# gfortran only
$(tmpEXETempDir)/%.f90.orig: %.f90
@if [ ! -d $(tmpEXETempDir) ]; then mkdir -p $(tmpEXETempDir); fi
$(SILENT) $(F90) $(F90FLAGS) $(fincludes) -fsyntax-only -fdump-fortran-original $< > $@
$(SILENT) $(F90) $(F90FLAGS) $(FMODULES) $(fincludes) -fsyntax-only -fdump-fortran-original $< > $@

$(tmpEXETempDir)/%.F90.orig: %.F90
@if [ ! -d $(tmpEXETempDir) ]; then mkdir -p $(tmpEXETempDir); fi
$(SILENT) $(F90) $(F90FLAGS) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -fsyntax-only -fdump-fortran-original $< > $@
$(SILENT) $(F90) $(F90FLAGS) $(FMODULES) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -fsyntax-only -fdump-fortran-original $< > $@

$(tmpEXETempDir)/%.f.orig: %.f
@if [ ! -d $(tmpEXETempDir) ]; then mkdir -p $(tmpEXETempDir); fi
$(SILENT) $(F90) $(FFLAGS) $(fincludes) -fsyntax-only -fdump-fortran-original $< > $@
$(SILENT) $(F90) $(FFLAGS) $(FMODULES) $(fincludes) -fsyntax-only -fdump-fortran-original $< > $@

$(tmpEXETempDir)/%.F.orig: %.F
@if [ ! -d $(tmpEXETempDir) ]; then mkdir -p $(tmpEXETempDir); fi
$(SILENT) $(F90) $(FFLAGS) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -fsyntax-only -fdump-fortran-original $< > $@
$(SILENT) $(F90) $(FFLAGS) $(FMODULES) -DBL_LANG_FORT -DAMREX_LANG_FORT $(FCPPFLAGS) $(fincludes) -fsyntax-only -fdump-fortran-original $< > $@

# fix amrex::Real and amrex_real
# & --> *
Expand Down Expand Up @@ -471,9 +486,9 @@ help:
@echo ""
@echo "The rule for compiling foo.cpp is: \$$(CXX) \$$(CXXFLAGS) \$$(CPPFLAGS) \$$(includes) -c foo.o foo.cpp"
@echo "The rule for compiling foo.c is: \$$(CC) \$$(CFLAGS) \$$(CPPFLAGS) \$$(includes) -c foo.o foo.c"
@echo "The rule for compiling foo.f90 is: \$$(F90) \$$(F90FLAGS) \$$(fincludes) -c foo.o foo.f90"
@echo "The rule for compiling foo.F90 is: \$$(F90) \$$(F90FLAGS) \$$(FCPPFLAGS) \$$(fincludes) -c foo.o foo.F90"
@echo "The rule for compiling foo.[fF] is: \$$(FC) \$$(FFLAGS) \$$(fincludes) -c foo.o foo.f"
@echo "The rule for compiling foo.f90 is: \$$(F90) \$$(F90FLAGS) \$$(FMODULES) \$$(fincludes) -c foo.o foo.f90"
@echo "The rule for compiling foo.F90 is: \$$(F90) \$$(F90FLAGS) \$$(FMODULES) \$$(FCPPFLAGS) \$$(fincludes) -c foo.o foo.F90"
@echo "The rule for compiling foo.[fF] is: \$$(FC) \$$(FFLAGS) \$$(FMODULES) \$$(fincludes) -c foo.o foo.f"
@echo " Note that .F files are preprocessed with cpp into .f files before being compiled."
ifeq ($(LINK_WITH_FORTRAN_COMPILER),TRUE)
@echo "The rule for linking is: \$$(F90) \$$(LINKFLAGS) \$$(FCPPFLAGS) \$$(fincludes) \$$(LDFLAGS) -o \$$(executable) *.o \$$(libraries)"
Expand All @@ -494,6 +509,7 @@ endif
@echo " includes = $(includes)"
@echo " FFLAGS = $(FFLAGS)"
@echo " F90FLAGS = $(F90FLAGS)"
@echo " FMODULES = $(FMODULES)"
@echo " fincludes = $(fincludes)"
@echo " LDFLAGS = $(LDFLAGS)"
@echo " libraries = $(libraries)"
Expand Down
6 changes: 4 additions & 2 deletions Tools/GNUMake/comps/cray.mak
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ endif
CXXFLAGS += -h std=c++11
CFLAGS += -h c99

F90FLAGS += -N 255 -I $(fmoddir) -J $(fmoddir) -em
FFLAGS += -N 255 -I $(fmoddir) -J $(fmoddir) -em
F90FLAGS += -N 255 -em
FFLAGS += -N 255 -em

FMODULES = -I $(fmoddir) -J $(fmoddir)

########################################################################

Expand Down
6 changes: 4 additions & 2 deletions Tools/GNUMake/comps/gnu.mak
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ endif

########################################################################

FFLAGS += -ffixed-line-length-none -fno-range-check -fno-second-underscore -J$(fmoddir) -I $(fmoddir)
F90FLAGS += -ffree-line-length-none -fno-range-check -fno-second-underscore -J$(fmoddir) -I $(fmoddir) -fimplicit-none
FFLAGS += -ffixed-line-length-none -fno-range-check -fno-second-underscore
F90FLAGS += -ffree-line-length-none -fno-range-check -fno-second-underscore -fimplicit-none

FMODULES = -J$(fmoddir) -I $(fmoddir)

########################################################################

Expand Down
3 changes: 1 addition & 2 deletions Tools/GNUMake/comps/ibm.mak
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ F90FLAGS += -WF,-C!

FFLAGS += -qfixed=72

F90FLAGS += -qmoddir=$(fmoddir) -I $(fmoddir)
FFLAGS += -qmoddir=$(fmoddir) -I $(fmoddir)
FMODULES = -qmoddir=$(fmoddir) -I $(fmoddir)

FFLAGS += $(GENERIC_IBM_FLAGS)
F90FLAGS += $(GENERIC_IBM_FLAGS)
Expand Down
5 changes: 3 additions & 2 deletions Tools/GNUMake/comps/intel.mak
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ else
endif
CFLAGS += -std=c99

F90FLAGS += -module $(fmoddir) -I$(fmoddir) -implicitnone
FFLAGS += -module $(fmoddir) -I$(fmoddir)
F90FLAGS += -implicitnone

FMODULES = -module $(fmoddir) -I$(fmoddir)

########################################################################

Expand Down
3 changes: 1 addition & 2 deletions Tools/GNUMake/comps/llvm-flang.mak
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ endif
CXXFLAGS += -std=c++11
CFLAGS += -std=c99

FFLAGS += -J$(fmoddir) -I $(fmoddir)
F90FLAGS += -J$(fmoddir) -I $(fmoddir)
FMODULES = -J$(fmoddir) -I $(fmoddir)

########################################################################

Expand Down
6 changes: 4 additions & 2 deletions Tools/GNUMake/comps/llvm.mak
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ endif
CXXFLAGS += -std=c++14
CFLAGS += -std=c99

FFLAGS += -ffixed-line-length-none -fno-range-check -fno-second-underscore -J$(fmoddir) -I $(fmoddir)
F90FLAGS += -ffree-line-length-none -fno-range-check -fno-second-underscore -J$(fmoddir) -I $(fmoddir) -fimplicit-none
FFLAGS += -ffixed-line-length-none -fno-range-check -fno-second-underscore
F90FLAGS += -ffree-line-length-none -fno-range-check -fno-second-underscore -fimplicit-none

FMODULES = -J$(fmoddir) -I $(fmoddir)

########################################################################

Expand Down
6 changes: 4 additions & 2 deletions Tools/GNUMake/comps/nag.mak
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ else ifeq ($(gcc_major_version),5)
endif
CFLAGS += -std=gnu99

FFLAGS += -mismatch -mdir $(fmoddir) -I $(fmoddir)
F90FLAGS += -mismatch -mdir $(fmoddir) -I $(fmoddir) -u
FFLAGS += -mismatch
F90FLAGS += -mismatch -u

FMODULES = -mdir $(fmoddir) -I $(fmoddir)

########################################################################

Expand Down
5 changes: 2 additions & 3 deletions Tools/GNUMake/comps/nec.mak
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ endif

########################################################################

F90FLAGS += -module $(fmoddir) -I$(fmoddir)
FFLAGS += -module $(fmoddir) -I$(fmoddir)
FMODULES += -module $(fmoddir) -I$(fmoddir)

########################################################################

Expand All @@ -47,7 +46,7 @@ CXXFLAGS += $(GENERIC_COMP_FLAGS)
CFLAGS += $(GENERIC_COMP_FLAGS)
FFLAGS += $(GENERIC_COMP_FLAGS)
F90FLAGS += $(GENERIC_COMP_FLAGS)
LDFLAGS = -cxxlib
LDFLAGS += -cxxlib

########################################################################

6 changes: 4 additions & 2 deletions Tools/GNUMake/comps/pgi.mak
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ endif

########################################################################

F90FLAGS += -module $(fmoddir) -I$(fmoddir) -Mdclchk
FFLAGS += -module $(fmoddir) -I$(fmoddir) -Mextend
F90FLAGS += -Mdclchk
FFLAGS += -Mextend

FMODULES = -module $(fmoddir) -I$(fmoddir)

########################################################################

Expand Down
2 changes: 1 addition & 1 deletion Tools/libamrex/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def configure(argv):
argv[0] = "configure" # So the help message print it
parser = argparse.ArgumentParser()
parser.add_argument("--prefix",
help="Install libarmex, headers and Fortran modules in PREFIX directory [default=tmp_install_dir]",
help="Install libamrex, headers and Fortran modules in PREFIX directory [default=tmp_install_dir]",
default="tmp_install_dir")
parser.add_argument("--dim",
help="Dimension [default=3]",
Expand Down
59 changes: 59 additions & 0 deletions Tools/libamrex/mkpkgconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python

from __future__ import print_function

import sys

if sys.version_info < (2, 7):
sys.exit("ERROR: need python 2.7 or later for mkpkgconfig.py")

import argparse

def doit(prefix, version, cflags, libs, libpriv, fflags):
print("# AMReX Version: "+version)
print("")
print("prefix="+prefix)
print("exec_prefix=${prefix}")
print("libdir=${prefix}/lib")
print("includedir=${prefix}/include")
print("")
print("fflags="+fflags);
print("")
print("Name: amrex")
print("Description: Software Framework for Block Structed AMR")
print("Version:")
print("URL: https://github.com/AMReX-Codes/amrex")
print("Requires:")
print("Cflags: -I${includedir}", cflags)
print("Libs: -L${libdir} -lamrex", libs)
print("Libs.private:", libpriv)

if __name__ == "__main__":

parser = argparse.ArgumentParser()
parser.add_argument("--prefix",
help="prefix",
default="")
parser.add_argument("--version",
help="version",
default="")
parser.add_argument("--cflags",
help="cflags",
default="")
parser.add_argument("--libs",
help="libs",
default="")
parser.add_argument("--libpriv",
help="libpriv",
default="")
parser.add_argument("--fflags",
help="fflags",
default="")
args = parser.parse_args()

try:
doit(prefix=args.prefix, version=args.version, cflags=args.cflags,
libs=args.libs, libpriv=args.libpriv, fflags=args.fflags)
except:
# something went wrong
print("$(error something went wrong in mkpkgconfig.py)")
Loading

0 comments on commit 6f7257c

Please sign in to comment.