Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
esys-escript committed Mar 10, 2024
2 parents 565dfd4 + 28f7372 commit 59695e5
Show file tree
Hide file tree
Showing 37 changed files with 3,897 additions and 0 deletions.
6 changes: 6 additions & 0 deletions trilinos_source15/commonTools/buildTools/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The scripts in this directory are for the old autotools build system for
Trilinos that are only used by a few Trilinos packages used in contexts
outside of Trilinos.

The build tools for the new Trilinos CMake system are in the base-level
directory cmake/.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/perl -w
#
# This perl script is used to setup a build directory for
# code that is external to Trilinos but uses the hard work
# of the Trilinos autconf/automake system to define how
# code is compiled, packaged into libraries and linked
# into executables.
#
#
#
# Note, this script must be maintained to be current for
# the Teuchos makefile.
#
use strict;
use Cwd;
use File::Path;
#
# Pares the command-line
#
if( !defined(@ARGV) || scalar(@ARGV) < 3 ) {
die
"Usage: external-configure.pl TRILNOS_BUILD_DIR EXTERNAL_SRC_DIR PACKAGE1 PACAKGE2 ...\n".
" TRILNOS_BUILD_DIR : The path to the base Trilinos build directory\n".
" EXTERNAL_SRC_DIR : The path to the base directory for PACKAGE1, PACAKGE2 ...\n"
;
}
my $trilinos_build_dir = make_abs_path(cwd(),shift);
my $external_src_dir = make_abs_path(cwd(),shift);
my @external_packages = @ARGV;
# ToDo: Validate that $trilinos_build_dir is an absolute path!
print " trilinos_build_dir = $trilinos_build_dir\n";
print " external_src_dir = $external_src_dir\n";
print " external_packages = [", join(",",@external_packages), "]\n";
#
# Get the source directory for Trilinos
#
my $srcdir_line = `grep \'^srcdir.*=\' $trilinos_build_dir/Makefile`;
#print "srcdir_line: $srcdir_line";
my $trilinos_src_dir = make_abs_path($trilinos_build_dir,(split(" = ",$srcdir_line))[1]);
chomp $trilinos_src_dir;
# ToDo: If above is a relative path then we must append it to
print " trilinos_src_dir = $trilinos_src_dir\n";
#
# Create a base-level Makefile that will build the other projects
#
open BASE_MAKEFILE, ">Makefile";
print BASE_MAKEFILE ":\n";
foreach(@external_packages) {
print BASE_MAKEFILE "\tcd ${_}; make\n";
}
print BASE_MAKEFILE "all :\n";
foreach(@external_packages) {
print BASE_MAKEFILE "\tcd ${_}; make all\n";
}
print BASE_MAKEFILE "clean :\n";
foreach(@external_packages) {
print BASE_MAKEFILE "\tcd ${_}; make clean\n";
}
print BASE_MAKEFILE "clean-obj :\n";
foreach(@external_packages) {
print BASE_MAKEFILE "\tcd ${_}; make clean-obj\n";
}
print BASE_MAKEFILE "clean-lib :\n";
foreach(@external_packages) {
print BASE_MAKEFILE "\tcd ${_}; make clean-lib\n";
}
print BASE_MAKEFILE "clean-exe :\n";
foreach(@external_packages) {
print BASE_MAKEFILE "\tcd ${_}; make clean-exe\n";
}
#
# Create the external subpackage directories and their makefiles
#
foreach(@external_packages) {
my $external_package = $_;
print " Setting up \"$external_package\" ...\n";
(mkpath($external_package,1,0777) || die $!) if !(-e $external_package);
run_cmnd("cp ${external_src_dir}/${external_package}/Makefile.in ${external_package}/Makefile",1);
run_cmnd("${trilinos_src_dir}/commonTools/refactoring/token-replace.pl _TRILINOS_BUILD_DIR ${trilinos_build_dir} ${external_package}/Makefile ${external_package}/Makefile",1);
run_cmnd("${trilinos_src_dir}/commonTools/refactoring/token-replace.pl _TRILINOS_SRC_DIR ${trilinos_src_dir} ${external_package}/Makefile ${external_package}/Makefile",1);
run_cmnd("${trilinos_src_dir}/commonTools/refactoring/token-replace.pl _BASE_SRC_DIR ${external_src_dir}/${external_package} ${external_package}/Makefile ${external_package}/Makefile",1);
}

sub run_cmnd {
my $cmnd = shift;
my $stop_on_fail = shift;
#print "$cmnd\n";
if(system($cmnd) != 0 && $stop_on_fail) { die; }
}

sub make_abs_path {
my $base_path = shift;
my $path_in = shift;
return "$base_path/$path_in" if( $path_in =~ /^\./ );
return $path_in;
}
134 changes: 134 additions & 0 deletions trilinos_source15/commonTools/buildTools/external/makefileSupport.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#
# Build a makefile stub that contains Trilinos autoconf-generated
# macros for compiling and building. We will grab these from
# the tools package Teuchos.
#

TRILINOS_TEUCHOS_BUILD = $(TRILINOS_BUILD_DIR)/packages/teuchos
TRILINOS_MAKE_OPTIONS_FILE = ./trilinos_make_options.mak
TRILINOS_TEUCHOS_MAKEFILE = $(TRILINOS_TEUCHOS_BUILD)/src/Makefile
TRILINOS_TEUCHOS_EXPORT_MAKEFILE = $(TRILINOS_TEUCHOS_BUILD)/Makefile.export.teuchos

# Make rule for this file
$(TRILINOS_MAKE_OPTIONS_FILE) : $(TRILINOS_TEUCHOS_MAKEFILE)
$(TRILINOS_SRC_DIR)/packages/teuchos/config/generate-makeoptions.pl $(TRILINOS_TEUCHOS_BUILD)/src/Makefile TEUCHOS > $(TRILINOS_MAKE_OPTIONS_FILE)

#
# Read in the Trilinos autoconf-generated macros from the file created above
#

include $(TRILINOS_MAKE_OPTIONS_FILE)
include $(TRILINOS_TEUCHOS_EXPORT_MAKEFILE) # Note, the order is important since TEUCHO_LIBS is redefined here!

#
# File extenstions
#

EXTERNAL_LIB_EXT = a

EXTERNAL_OBJ_EXT = o

# Set makefile buildsystem macros
#

# EXTERNAL_C compiler
EXTERNAL_C = $(TEUCHOS_CC)
EXTERNAL_C_DEP_OPT = -MM
EXTERNAL_C_COMPILE_OPT = -c
EXTERNAL_C_OUTPUT_OPT = -o \



# EXTERNAL_C++ compiler
EXTERNAL_CXX = $(TEUCHOS_CXX)
EXTERNAL_CXX_DEP_OPT = -MM
EXTERNAL_CXX_COMPILE_OPT = -c
EXTERNAL_CXX_OUTPUT_OPT = -o \

# Fortran compiler
EXTERNAL_F77 = $(TEUCHOS_F77)
EXTERNAL_F77_COMPILE_OPT = -c
EXTERNAL_F77_OUTPUT_OPT = -o \

# Library creator
EXTERNAL_AR = $(TEUCHOS_libteuchos_a_AR) \

EXTERNAL_RANLIB = $(TEUCHOS_RANLIB) \

# Linker
EXTERNAL_LD = $(TEUCHOS_CXXLD)

# Install directory (taken from Trilinos' --prefix=??? option)
ifneq ($(TEUCHOS_prefix),)
EXTERNAL_INSTALL_DIR = $(TEUCHOS_prefix)
endif

#
# Program options
#

# Preprocessor macro definitions
EXTERNAL_DEFINES += -D_MIN=min -D_MAX=max $(TEUCHOS_DEFS) $(TEUCHOS_CPPFLAGS)

# Include directories
EXTERNAL_INCLUDES += $(EXTERNAL_INCL_DIR)

#EXTERNAL_CPPFLAGS += -v

# Linker Options
EXTERNAL_LDFLAGS = $(TEUCHOS_LDFLAGS) $(TEUCHOS_LIBS)

# EXTERNAL_C, EXTERNAL_C++ and Fortan compiler options

EXTERNAL_CFLAGS = $(TEUCHOS_CFLAGS)
EXTERNAL_CXXFLAGS = $(TEUCHOS_CXXFLAGS)
EXTERNAL_F77FLAGS = $(TEUCHOS_FFLAGS)

#
# Build Rules
#

# Build object files from EXTERNAL_C source files
%.$(EXTERNAL_OBJ_EXT) : %.c $(TRILINOS_MAKE_OPTIONS_FILE)
$(EXTERNAL_C) $(EXTERNAL_C_COMPILE_OPT) $(EXTERNAL_CPPFLAGS) $(EXTERNAL_EXTRA_CPPFLAGS) \
$(EXTERNAL_DEFINES) $(EXTERNAL_INCLUDES) \
$(EXTERNAL_CFLAGS) $(EXTERNAL_EXTRA_CFLAGS) $(EXTERNAL_C_OUTPUT_OPT)$@ $<

# Build object files from EXTERNAL_C++ source files
%.$(EXTERNAL_OBJ_EXT) : %.cpp $(TRILINOS_MAKE_OPTIONS_FILE)
$(EXTERNAL_CXX) $(EXTERNAL_CXX_COMPILE_OPT) $(EXTERNAL_CPPFLAGS) $(EXTERNAL_EXTRA_CPPFLAGS) \
$(EXTERNAL_DEFINES) $(EXTERNAL_INCLUDES) \
$(EXTERNAL_CXXFLAGS) $(EXTERNAL_EXTRA_CXXFLAGS) $(EXTERNAL_CXX_OUTPUT_OPT)$@ $<

# Build object files from Fotran source files
%.$(EXTERNAL_OBJ_EXT) : %.f $(TRILINOS_MAKE_OPTIONS_FILE)
$(EXTERNAL_F77) $(EXTERNAL_F77_COMPILE_OPT) $(EXTERNAL_F77FLAGS) $(EXTERNAL_EXTRA_F77FLAGS) $(EXTERNAL_F77_OUTPUT_OPT)$@ $<
# $(EXTERNAL_F77) $(EXTERNAL_F77_COMPILE_OPT) $(EXTERNAL_CPPFLAGS) $(EXTERNAL_EXTRA_CPPFLAGS) $(EXTERNAL_F77FLAGS) $(EXTERNAL_EXTRA_F77FLAGS) $(EXTERNAL_F77_OUTPUT_OPT)$@ $<

# Build dependency files for EXTERNAL_C source files that include header dependencies
%.d: %.c $(TRILINOS_MAKE_OPTIONS_FILE)
$(EXTERNAL_C) $(EXTERNAL_C_DEP_OPT) $(EXTERNAL_CPPFLAGS) $(EXTERNAL_EXTRA_CPPFLAGS) \
$(EXTERNAL_DEFINES) $(EXTERNAL_INCLUDES) \
$< \
| sed 's/$(@:.d=\.$(EXTERNAL_OBJ_EXT))/$(@:.d=.$(EXTERNAL_OBJ_EXT)) $@/' | $(EXTERNAL_DEP_POST_PROC) > $@; [ -s $@ ] || rm -f $@
# | $(EXTERNAL_BASE_DIR)/Moocho/build/dep_post.pl $@ $(EXTERNAL_OBJ_EXT) | $(EXTERNAL_DEP_POST_PROC) > $@; [ -s $@ ] || rm -f $@

# Build dependency files for EXTERNAL_C++ source files that include header dependencies
%.d: %.cpp $(TRILINOS_MAKE_OPTIONS_FILE)
$(EXTERNAL_CXX) $(EXTERNAL_CXX_DEP_OPT) $(EXTERNAL_CPPFLAGS) $(EXTERNAL_EXTRA_CPPFLAGS) \
$(EXTERNAL_DEFINES) $(EXTERNAL_INCLUDES) \
$< \
| sed 's/$(@:.d=\.$(EXTERNAL_OBJ_EXT))/$(@:.d=.$(EXTERNAL_OBJ_EXT)) $@/' | $(EXTERNAL_DEP_POST_PROC) > $@; [ -s $@ ] || rm -f $@
# | $(EXTERNAL_BASE_DIR)/Moocho/build/dep_post.pl $@ $(EXTERNAL_OBJ_EXT) | $(EXTERNAL_DEP_POST_PROC) > $@; [ -s $@ ] || rm -f $@

#
# Universal targets
#

clean-obj :
rm *.o
clean-lib :
rm *.a
clean-exe :
rm *.exe
clean : clean-obj clean-lib clean-exe
86 changes: 86 additions & 0 deletions trilinos_source15/commonTools/buildTools/generate-makeoptions.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/perl -w
#
# This perl script graps a bunch of make macro definitions
# generated for Teuchos that can be used in other makefiles.
# This is dumped to stdout and can be redirected to build
# a makefile.
#
# Note, this script must be maintained to be current for
# the Teuchos makefile.
#
use strict;

if( !(defined(@ARGV) && scalar(@ARGV)==2) ) {
die "Error, this script takes two and only two arguments (makefile_name package_name).!\n";
}

my $makefile_name = shift;
my $package_name = shift;

#
# List the macros you want to grep and include in the output
#
my @macros =
(
"CC"
,"CXX"
,"F77"
,"CXXLD"
,"DEFS"
,"CPPFLAGS"
,"CFLAGS"
,"CXXFLAGS"
,"FFLAGS"
,"LDFLAGS"
,"FLIBS"
,"BLAS_LIBS"
,"LAPACK_LIBS"
,"prefix"
,"AR"
,"ALTERNATE_AR"
,"libteuchos_a_AR"
,"RANLIB"
);

open FILE_IN, "<$makefile_name" || die "The file $makefile_name could not be opended for input\n";
my @makefile_name_array = <FILE_IN>;
close FILE_IN;

#
# Find the above macros and append "${package_name}_" to the beginning.
#
my @new_macros;
my $add_next_line = 0;
foreach( @makefile_name_array ) {
my $line = $_;
if($add_next_line) {
push @new_macros, $line;
if( substr($line,-1,1) eq "\\" ) {
$add_next_line = 1;
}
else {
$add_next_line = 0;
}
next;
}
#print "Line = $line";
foreach( @macros ) {
my $macro_search = "^${_} ";
#print "Macro search = \'$macro_search\'\n";
if( $line=~/$macro_search/ ) {
#print "Adding Macro!\n";
my $find_str = '\(CXX\)';
my $replace_str = "(${package_name}_CXX)";
$line=~s/$find_str/$replace_str/;
push @new_macros, "${package_name}_${line}";
if( substr($line,-2,1) eq "\\" ) {
$add_next_line = 1;
}
else {
$add_next_line = 0;
}
}
}
}

print join("",@new_macros);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
# Call this script from the 'bootstrap' script of each package
_COMMON_TOOL_BASE_DIR=$1;
cp $_COMMON_TOOL_BASE_DIR/buildTools/*.pl ./config/.
cp $_COMMON_TOOL_BASE_DIR/refactoring/string-replace.pl ./config/.
Loading

0 comments on commit 59695e5

Please sign in to comment.