[CIG-SEISMO] [SPECFEM3D_GLOBE] [PATCH] Out-of-source builds

Elliott Sales de Andrade esalesde at physics.utoronto.ca
Wed Apr 18 15:30:42 PDT 2012


Hi SPECFEM3D_GLOBE developers,

The following patch enables out-of-source builds. What this means is
that you can do something like,
--
$ tar zxvf SPECFEM3D_GLOBE-${VERSION}.tar.gz
$ mkdir test_directory; cd test_directory
$ ../SPECFEM3D_GLOBE-${VERSION}/configure <options>
$ vim setup/*.h Par_file CMTSOLUTION STATIONS
...change settings...
$ make
--
and then SPECFEM3D_GLOBE will be built in `test_directory` instead of
the source directory. You can do this multiple times using the same
source but different config.h/constants.h/Par_file or different compile
flags for debug/release purposes.

Thankfully, with the (relatively) recent changes to the Makefiles to add
directory variables such as $O, $SETUP, etc., this has been a fairly
easy task. There are basically three changes:
     1. Change all the `Makefile.in` so that `configure` sets the
        directory variables to the correct paths, instead of the
        hardcoded `../..`.
     2. Ensure that all paths are referenced using one of those
        directory variables.
     3. Tell `configure` to copy `DATA/{CMTSOLUTION,Par_file,STATIONS}`
        to the build directory. (I assume they will remain without the
        `.in` suffix, so I instructed `configure` not to use it.)
        Additionally, `configure` is told to link all the subdirectories
        in `DATA` from build to source so that you can actually run
        stuff. Note, I have only included the changes to `configure.ac`,
        since the diff to `configure` would contain superfluous changes
        and should not be in SVN anyway.

Note, I have attached the patch as well as reproduced it below, just in
case the mailing list formats it strangely.

=====
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -101,7 +101,39 @@
 # Checks for library functions.
 
 
-AC_CONFIG_FILES([Makefile src/auxiliaries/Makefile src/meshfem3D/Makefile src/specfem3D/Makefile src/create_header_file/Makefile setup/constants.h setup/precision.h DATA/Par_file DATA/CMTSOLUTION DATA/STATIONS])
+AC_CONFIG_FILES([
+    Makefile
+    src/auxiliaries/Makefile
+    src/meshfem3D/Makefile
+    src/specfem3D/Makefile
+    src/create_header_file/Makefile
+    setup/constants.h
+    setup/precision.h
+])
+AC_CONFIG_FILES([
+    DATA/Par_file:DATA/Par_file
+    DATA/CMTSOLUTION:DATA/CMTSOLUTION
+    DATA/STATIONS:DATA/STATIONS
+])
+AC_CONFIG_LINKS([
+    DATA/crust2.0:DATA/crust2.0
+    DATA/crustmap:DATA/crustmap
+    DATA/epcrust:DATA/epcrust
+    DATA/eucrust-07:DATA/eucrust-07
+    DATA/heterogen:DATA/heterogen
+    DATA/Lebedev_sea99:DATA/Lebedev_sea99
+    DATA/Montagner_model:DATA/Montagner_model
+    DATA/old:DATA/old
+    DATA/PPM:DATA/PPM
+    DATA/QRFSI12:DATA/QRFSI12
+    DATA/s20rts:DATA/s20rts
+    DATA/s362ani:DATA/s362ani
+    DATA/s40rts:DATA/s40rts
+    DATA/Simons_model:DATA/Simons_model
+    DATA/topo_bathy:DATA/topo_bathy
+    DATA/Zhao_JP_model:DATA/Zhao_JP_model
+])
+
 AC_OUTPUT
 
 
diff --git a/src/auxiliaries/Makefile.in b/src/auxiliaries/Makefile.in
--- a/src/auxiliaries/Makefile.in
+++ b/src/auxiliaries/Makefile.in
@@ -33,7 +33,7 @@
 MPILIBS = @MPILIBS@
 FLAGS_CHECK = @FLAGS_CHECK@
 FLAGS_NO_CHECK = @FLAGS_NO_CHECK@
-FCFLAGS_f90 = @FCFLAGS_f90@ -I../../setup -I../..
+FCFLAGS_f90 = @FCFLAGS_f90@ -I${SETUP} -I${B}
 
 FCCOMPILE_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_CHECK)
 FCCOMPILE_NO_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_NO_CHECK)
@@ -42,7 +42,7 @@
 
 CC = @CC@
 CFLAGS = @CFLAGS@
-CPPFLAGS = -I../../setup @CPPFLAGS@
+CPPFLAGS = -I${SETUP} @CPPFLAGS@
 
 #AR = ar
 #ARFLAGS = cru
@@ -52,20 +52,22 @@
 RANLIB = @RANLIB@
 
 ## compilation directories
+# B : build directory
+B = @top_builddir@
 # E : executables directory
-E = ../../bin
+E = ${B}/bin
 # O : objects directory
-O = ../../obj
-# SHARED : shared directoy
-SHARED = ../shared
+O = ${B}/obj
 # S : source file directory
-S = .
-# root directory
-S_TOP = ../..
+S = @srcdir@
+# S_TOP : source file root directory
+S_TOP = @top_srcdir@
+# SHARED : shared directory
+SHARED = ${S_TOP}/src/shared
 ## setup file directory
-SETUP = ../../setup
+SETUP = ${B}/setup
 ## output file directory
-OUTPUT = ../../OUTPUT_FILES
+OUTPUT = ${B}/OUTPUT_FILES
 
 #######################################
 
@@ -281,8 +283,8 @@
 ##
 ## object from solver
 ##
-$O/get_cmt.o: ${SETUP}/constants.h ../specfem3D/get_cmt.f90
-	${FCCOMPILE_CHECK} -c -o $O/get_cmt.o ${FCFLAGS_f90} ../specfem3D/get_cmt.f90
+$O/get_cmt.o: ${SETUP}/constants.h $S/../specfem3D/get_cmt.f90
+	${FCCOMPILE_CHECK} -c -o $O/get_cmt.o ${FCFLAGS_f90} $S/../specfem3D/get_cmt.f90
 
 
 ##
@@ -327,5 +329,5 @@
 ### rule for the header file
 ###
 ${OUTPUT}/values_from_mesher.h: reqheader
-	(mkdir -p ${OUTPUT}; cd ${S_TOP}/; ./bin/xcreate_header_file)
+	(mkdir -p ${OUTPUT}; cd ${B}/; ./bin/xcreate_header_file)
 
diff --git a/src/create_header_file/Makefile.in b/src/create_header_file/Makefile.in
--- a/src/create_header_file/Makefile.in
+++ b/src/create_header_file/Makefile.in
@@ -33,7 +33,7 @@
 MPILIBS = @MPILIBS@
 FLAGS_CHECK = @FLAGS_CHECK@
 FLAGS_NO_CHECK = @FLAGS_NO_CHECK@
-FCFLAGS_f90 = @FCFLAGS_f90@ -I../../setup
+FCFLAGS_f90 = @FCFLAGS_f90@ -I${SETUP}
 
 FCCOMPILE_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_CHECK)
 FCCOMPILE_NO_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_NO_CHECK)
@@ -42,7 +42,7 @@
 
 CC = @CC@
 CFLAGS = @CFLAGS@
-CPPFLAGS = -I../../setup @CPPFLAGS@
+CPPFLAGS = -I${SETUP} @CPPFLAGS@
 
 #AR = ar
 #ARFLAGS = cru
@@ -52,20 +52,22 @@
 RANLIB = @RANLIB@
 
 ## compilation directories
+# B : build directory
+B = @top_builddir@
 # E : executables directory
-E = ../../bin
+E = ${B}/bin
 # O : objects directory
-O = ../../obj
-# SHARED : shared directoy
-SHARED = ../shared
+O = ${B}/obj
 # S : source file directory
-S = .
-# root directory
-S_TOP = ../..
+S = @srcdir@
+# S_TOP : source file root directory
+S_TOP = @top_srcdir@
+# SHARED : shared directory
+SHARED = ${S_TOP}/src/shared
 ## setup file directory
-SETUP = ../../setup
+SETUP = ${B}/setup
 ## output file directory
-OUTPUT = ../../OUTPUT_FILES
+OUTPUT = ${B}/OUTPUT_FILES
 
 #######################################
 
diff --git a/src/meshfem3D/Makefile.in b/src/meshfem3D/Makefile.in
--- a/src/meshfem3D/Makefile.in
+++ b/src/meshfem3D/Makefile.in
@@ -33,7 +33,7 @@
 MPILIBS = @MPILIBS@
 FLAGS_CHECK = @FLAGS_CHECK@
 FLAGS_NO_CHECK = @FLAGS_NO_CHECK@
-FCFLAGS_f90 = @FCFLAGS_f90@ -I../../setup
+FCFLAGS_f90 = @FCFLAGS_f90@ -I${SETUP}
 
 FCCOMPILE_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_CHECK)
 FCCOMPILE_NO_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_NO_CHECK)
@@ -42,7 +42,7 @@
 
 CC = @CC@
 CFLAGS = @CFLAGS@
-CPPFLAGS = -I../../setup @CPPFLAGS@
+CPPFLAGS = -I${SETUP} @CPPFLAGS@
 
 #AR = ar
 #ARFLAGS = cru
@@ -52,20 +52,22 @@
 RANLIB = @RANLIB@
 
 ## compilation directories
+# B : build directory
+B = @top_builddir@
 # E : executables directory
-E = ../../bin
+E = ${B}/bin
 # O : objects directory
-O = ../../obj
-# SHARED : shared directoy
-SHARED = ../shared
+O = ${B}/obj
 # S : source file directory
-S = .
-# root directory
-S_TOP = ../..
+S = @srcdir@
+# S_TOP : source file root directory
+S_TOP = @top_srcdir@
+# SHARED : shared directory
+SHARED = ${S_TOP}/src/shared
 ## setup file directory
-SETUP = ../../setup
+SETUP = ${B}/setup
 ## output file directory
-OUTPUT = ../../OUTPUT_FILES
+OUTPUT = ${B}/OUTPUT_FILES
 
 #######################################
 
diff --git a/src/specfem3D/Makefile.in b/src/specfem3D/Makefile.in
--- a/src/specfem3D/Makefile.in
+++ b/src/specfem3D/Makefile.in
@@ -33,7 +33,7 @@
 MPILIBS = @MPILIBS@
 FLAGS_CHECK = @FLAGS_CHECK@
 FLAGS_NO_CHECK = @FLAGS_NO_CHECK@
-FCFLAGS_f90 = @FCFLAGS_f90@ -I../../setup -I../..
+FCFLAGS_f90 = @FCFLAGS_f90@ -I${SETUP} -I${B}
 
 FCCOMPILE_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_CHECK)
 FCCOMPILE_NO_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_NO_CHECK)
@@ -42,7 +42,7 @@
 
 CC = @CC@
 CFLAGS = @CFLAGS@
-CPPFLAGS = -I../../setup @CPPFLAGS@
+CPPFLAGS = -I${SETUP} @CPPFLAGS@
 
 #AR = ar
 #ARFLAGS = cru
@@ -52,20 +52,22 @@
 RANLIB = @RANLIB@
 
 ## compilation directories
+# B : build directory
+B = @top_builddir@
 # E : executables directory
-E = ../../bin
+E = ${B}/bin
 # O : objects directory
-O = ../../obj
-# SHARED : shared directoy
-SHARED = ../shared
+O = ${B}/obj
 # S : source file directory
-S = .
-# root directory
-S_TOP = ../..
+S = @srcdir@
+# S_TOP : source file root directory
+S_TOP = @top_srcdir@
+# SHARED : shared directory
+SHARED = ${S_TOP}/src/shared
 ## setup file directory
-SETUP = ../../setup
+SETUP = ${B}/setup
 ## output file directory
-OUTPUT = ../../OUTPUT_FILES
+OUTPUT = ${B}/OUTPUT_FILES
 
 #######################################
 
@@ -502,5 +504,5 @@
 ### rule for the header file
 ###
 ${OUTPUT}/values_from_mesher.h: reqheader
-	(mkdir -p ${OUTPUT}; cd ${S_TOP}/; ./bin/xcreate_header_file)
+	(mkdir -p ${OUTPUT}; cd ${B}/; ./bin/xcreate_header_file)
 
=====

-- 
Elliott Sales de Andrade <esalesde at physics.utoronto.ca>
University of Toronto (Physics)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SPECFEM3D_GLOBE-out-of-source-builds.diff
Type: text/x-patch
Size: 7171 bytes
Desc: not available
Url : http://geodynamics.org/pipermail/cig-seismo/attachments/20120418/4f66ade1/attachment.bin 


More information about the CIG-SEISMO mailing list