Getting Started with GridLAB-D
Copyright (C) 2009 Battelle Memorial Institute

Building GridLAB-D with the Auto-Toolset Under Linux and Other Unix Variants
You must have autoconf, automake, libtool, and xerces-c installed to build 
GridLAB-D in this way. With newer versions of the mac os, you will also need 
gnu sed and have it symlinked to sed.  To install the necessary tools, we 
recommend using XCode and homebrew.

Install XCode

In the XCode menu, select Preferences.  Select the Downloads tab.  Select 
Command Line Tools and install.

Install homebrew
      % sudo ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
      % sudo brew doctor

Install autoconf, automake, and libtool
      % sudo brew install autoconf
      % sudo brew install automake
      % sudo brew install libtool

The above commands should create symlinks in /usr/local/bin to each of these
tools.  On some combinations of XCode version and Mac OSX version, the
symlinks don't get created.  If this is the case, create them with
      % sudo brew ln --force autoconf
      % sudo brew ln --force automake
      % sudo brew ln --force libtool

Install gnu sed
      % sudo brew install gnu-sed

Symlink gsed to sed
      % sudo ln -s /usr/local/bin/gsed /usr/local/bin/sed

Make sure symlinked sed is the first instance of sed in the path
      % which sed

If /usr/local/bin/sed is not the response, put /usr/local/bin first in the path
you can do this temporarily using:
      % export PATH=/usr/local/bin:$PATH
or permanently by editing the file /etc/paths

If you are building from a source distribution you must first run:

      % cd gridlab-d/trunk
      % autoreconf -isf

You will most likely need to build and install XercesC:

      % cd third_party
      % . install_xercesc

If you are using the powerflow module, you will need to build SuperLU:

      % cd third_party
      % gunzip SuperLU*.gz
      % tar xvf SuperLU*.tar
      % cd SuperLU_3.1

Generally you simply follow the build instructions in the README file. In
addition you need to edit superLU's make.inc file as follows:
  -- Change SuperLUroot to point to your unzipped SuperLU_3.1 directory.
  -- (optional) To use the MacOSX optimized BLAS library (for highest 
      performance), replace the existing BLASLIB line with:
        BLASDEF = -DUSE_VENDOR_BLAS
        BLASLIB = -framework Accelerate
Once everything is setup actually build SuperLU using:
      % make 

You may get an error at the end regarding ldconfig--ignore it.  

Finally change back to the main code directory, configure and build

      % cd ../..
      % ./configure
      % make 

Note: If you encounter "can't create output" errors, you may have permissions
problems in one of the many include or library directors (some hidden). If this
happens you may have to change the folders back to being owned by your user
account using:
      % sudo chown -R YOUR_USER_NAME *
Run this from your main code directory to include all subfolders. The sloppier
alternative is to use sudo when running make.


This builds GridLAB-D from the makefiles provided in the distribution, and will
create targets in the same directory as the input source.  Libraries are
created using libtool which outputs libraries in a directory named '.libs' in
the input's source directory.  Use 'make install' to install GridLAB-D on the
system.  You must be superuser (or use sudo) to install to the system. If you
want to install GridLAB-D to a different location, use:

      % make install prefix=<install-path>.  

where <install-path> is the full path to the installation directory.

Whenever changes have been made to configure.ac or any of the makefile.am
files, the following build steps must be executed from the source-path folder:  
	1. Use 'autoreconf -isf' to update the configure script.
	2. Use './configure' to create the makefiles.
	3. Repeat the above command to make the project as usual.

Make should detect changes to configure.ac and makefile.am files and
automatically rerun steps 1 and 2 as needed.  If files are added to a module,
add the filename to makefile.am in that module's directory and remake. If make
does not automatically perform the required steps, rerun autoreconf -isf and
./configure manually.

To distribute the source code, it is best to check out a clean copy of the
source code and then package the resulting source tree using the
utilities/release-src command from the <source-path> directory.

On Apple OS-X, the GNU libtools are prefixed with a 'g' to differentiate them
from the NeXTStep libtool.  Before performing the steps above, tell the
autotoolset where to find libtool and libtoolize by setting the LIBTOOL and
LIBTOOLIZE environment variables.  The following lines are an example:

    % export LIBTOOL=/usr/bin/glibtool
    % export LIBTOOLIZE=/usr/bin/glibtoolize
    % autoreconf -isf
 
For information on the sample models, see samples/README.

On some platforms you may run into a problem with rpl_malloc being undefined
during the build.  If so, set the following environment before running
./configure

    % export ac_cv_func_malloc_0_nonnull=yes 


