
============================================================================
WARNING: the following instructions are not updated and are not maintained,
         we cannot guarantee are correct.
============================================================================


CWB installation WAT 6.0.1 on a mac using MacOs 10.10 and ROOT6 (Carlos Filipe Da Silva Costa)

I used these versions:

  - FFTW 3.3.4
  - GSL 1.9
  - ROOT 6.02.05
  - cfitsio 3.20
  - Healpix 3.00
  - libframe-8.21

By default MacOs use a Bash shell.

First, for ROOT we have to install:

  FFTW 3.3.4
  --------------------------------------------------------------------------- 
    // These flags are required for the root installation. 
    // The shared is required by root also but during the load.
    ./configure CFLAGS=-m64 --with-pic  --enable-shared 
    make
    make install

	
  GSL 1.9 
  --------------------------------------------------------------------------- 
    ./configure CFLAGS=-m64 <- This flag is asked by the root installation
    make 
    make install

    If one chose to not install both libs in the system repository, 
    but in a local repository (=no make install) 
    Add this to the ~/.profile

      GSL=/path_to_gsl_libs/gsl-1.19
      FFTW3=/path_to_fftw3_libs/fftw-3.3.4

      export GSL
      export FFTW3
	
  ROOT6
  --------------------------------------------------------------------------- 
    If we use ROOT5 with the new clang of MacOs, we get the errors below: 

      Error: class,struct,union or type __signed not defined /usr/include/sys/_types/_int8_t.h:30:
      Error: class,struct,union or type int8_t not defined /usr/include/stdint.h:29:
      Error: class,struct,union or type int8_t not defined /usr/include/stdint.h:40:
      Warning: Error occurred during reading source files
      Warning: Error occurred during dictionary source generation
      !!!Removing wave_dict.cc wave_dict.h !!!
      Error: /Files/CWB_osx_clang/ROOT/root-5.34/bin/rootcint: error loading 
          
    ROOT6 is the official solution for this future incompatibility (source rootTalk).	

    Compiling ROOT6
      ./configure --with-gsl-incdir=" /usr/local/include/gsl" 
      --with-gsl-libdir=" /usr/local/lib"  
      --with-fftw3-libdir=" /usr/local/lib" 
      --with-fftw3-incdir=" /usr/local/include"
    The options above are used to be sure that root will compile with these 
    two libraries FFTw and GSL. In principle if they are in system repository, root will found them.

    make
    source bin/thisroot.sh 

  CFITSIO	
  --------------------------------------------------------------------------- 
    Remarque! One has to change this: 
    The Cfistio Makefile uses gcc -dynamiclib -arch i386 -arch x86_64, 
    but the two architectures generate a conflict when linking  Healpix 
    and Cfistion libs during the root loading.
		
    They are two options: 
    1) after generating Makefile whith the ./configure, change these lines:
       CC =		gcc
       CFLAGS =	-O -arch x86_64 -fPIC -fno-common -std=c++11
       SHLIB_LD =	gcc -dynamiclib -arch x86_64  -install_name... 
    2) or change directly the configure file
       change this flag:  C_UNIV_SWITCH="-arch x86_64"
       I didn't found where to add c++11. 

    ./configure
    make shared
    
    
  HEALPIX 3.00
  --------------------------------------------------------------------------- 
    Edit the file: Healpix_3.00/src/cxx/config/ config.osx
    comment: 
      #LS_OMPFLAGS:= -fopenmp  (clang is not compatible with this option, it will stop the compilation)
    and replace ARCREATE=:
      libtool -static -o
    with
      gcc -fno-common -dynamiclib -std=c++11 -undefined dynamic_lookup -o 

    in the following files: 

      ./c_utils/planck.make
      ./cxxsupport/planck.make
      ./Healpix_cxx/planck.make
      ./libcfitsio/planck.make
      ./libpsht/planck.make
      ./libsharp/planck.make
 
    - LIB_$(PKG):=$(LIBDIR)/libpsht.a
    + LIB_$(PKG):=$(LIBDIR)/libpsht.dylib (instead of so)

    This will generate the correct names for the libs 

    Then return in Healpix_3.00/

    ./configure -L

    follow the options of the configure

      (4): configure Healpix C++ package, and edit Makefile
			
        Enter location of cfitsio library (/usr/local/lib):  write the paths to the cfitsion
        enter location of cfitsio header fitsio.h (/Files/CWB_osx_clang/CFITSIO/cfitsio-3.20): enter if the same!

      (4): osx

      It will add this to the .profile

        # configuration for Healpix 3.00
        HEALPIX=/Files/CWB_osx_clang/HEALPix/Healpix_3.00 ; export HEALPIX 
        HPX_CONF_DIR=/Users/Filipe/.healpix/3_00_Darwin
        if [ -r ${HPX_CONF_DIR}/idl.sh ] ; then . ${HPX_CONF_DIR}/idl.sh ; fi
        if [ -r ${HPX_CONF_DIR}/f90.sh ] ; then . ${HPX_CONF_DIR}/f90.sh ; fi
        if [ -r ${HPX_CONF_DIR}/cpp.sh ] ; then . ${HPX_CONF_DIR}/cpp.sh ; fi
        if [ -r ${HPX_CONF_DIR}/c.sh ] ;   then . ${HPX_CONF_DIR}/c.sh ;   fi

      (0): exit

    make cpp-all
		
    Now the libs are directly dylib, but the rootlogon looks for .so files, 
    so one should do the dynamic links ln -ls:
                	
    libc_utils.dylib     libcxxsupport.dylib  libfftpack.dylib     libhealpix_cxx.dylib libpsht.dylib (original)
    libc_utils.so        libcxxsupport.so     libfftpack.so        libhealpix_cxx.so    libpsht.so (ln -s)
		
    Also, ln-ls osx shared, again this is necessary for the rootlogon.c
                
  libframe-8.21
  --------------------------------------------------------------------------- 
    mgr/makeMacOS:
    First change in libframe-8.21/mgr/makeMacOS
      - ${MYCC} -dynamiclib -o libFrame.dynlib *.o
      + ${MYCC} -dynamiclib -o libFrame.dylib *.o
		
    root/bulid_MacOs:
      The build in libframe-8.21/root/
      was replaced by bulid_MacOs where i changed:

      - In the future rootcint will be replaced with rootcling
      I take the opportunity to include it.

      - I added:  --std=c++11 C++11 in the following line:
        g++ -DG__REGEXP -DG__SHAREDLIB -DG__OSFDLL --std=c++11 $CXXGENFL \
            -I$ROOTSYS/include -I$ROOTSYS/include/root -I../src -c G_frameL.C
      You need to make sure that the dictionary (and the rest of your code) is build with --std=c++11 rootTalk

      - I replaced
          gcc -shared  -g -o libFrameROOT.so  *.o
        with
          gcc -fno-common -dynamiclib -undefined dynamic_lookup -o libFrameROOT.dylib  *.o 

    Now these two libs are generated: libFrame.dylib     libFrameROOT.dylib 
    As previously, make dynamic links (ln -s) to get libFrame.so     libFrameROOT.so
    They are required by the rootlogon.C.
		
	
  WAT 6.0.1
  --------------------------------------------------------------------------- 
    watenv.sh:
    Before compiling the WAT, the local_watenv.sh should be updated and sourced.
    One should add these two environmentable variables: 
      export _USE_CPP11=1 # to compile with root6
      export _USE_ROOT6=1 # To move the *.pcm dictionaries used in ROOT6 at 
                          # the location as the generated libraries

    Without the C++11, you will get the following error: 
      'atomic_TClass_ptr' add this export _USE_CPP11=1 #to compile with root6 in watenv
    If you use ROOT5 and clang, you will get an error: 
      The stdint.h of OSX 10.9/10 is too complex for CINT to process.
		
    Makefiles:
    Presently I only cancelled only one -fopenmp in the makefile of trunk/wat
      CPP_OPT = -Wno-deprecated -fPIC # -fopenmp 
    (clang is not compatible with this option, but in this makefile it passes:  
       clang: warning: argument unused during compilation: '-fopenmp'	

    Changes in the code:
		
    The following files were changed:
      tools/cwb/cwb1G.cc
        -  wavearray<double> y[nIFO];       
        +  std::vector<wavearray<double>> y;
        +  y.resize(nIFO);
		
      tools/cwb/cwb2G.cc
        -  wavearray<double> y[nIFO];       
        +  std::vector<wavearray<double>> y;
        +  y.resize(nIFO);

      tools/gwat/gnetwork.cc
        -  wavecomplex F[nIFO];
        +  std::vector<wavecomplex> F;
        +  F.resize(nIFO);

    All arrays var[parameter] were changed by vector<>.  
    A dynamic memory allocation of the arrays is considered as an error with newer compilers.
	
    In this last case, we had to recast. C++ doesn't accept any more it.
      tools/wavegraph/wavegraph.cc
        -      bool read_ok = (streamline >> node);
        +      bool read_ok = static_cast<bool> (streamline >> node);

    Remarques:
    Presently, the config.sh in /war/tools search only for .so and no .dylib but 
    this could be changed in the future as now most of the libs are directly named .dylib. 
    As mentioned above, we can try to remove the '-fopenmp' and find another option 
    (or see if clang becomes compatible with it).

    To compile:
    Return to trunk/.
    make clean  (just to be sure)
    make ALL
    make install (imperative, it will call winstall which will move all the *.pcm file 
                  into the right directory. If not root will not load these libs) 
