The following page contains the same procedures we use when building a redistributable package containing all the libraries necessary for MOOSE Application development. We are making these available in an attempt to allow anyone to more easily build their own custom redistributable... for what ever the reason. We of course can not guarantee the finished product, but we would still love to hear from your success story or not!

We will break this down into two parts. One, will be to build everything from source that is going to go into your package, and two, the actual creation of the package bundle.  

Creating the package bundle using our scripts does come with one large requirement: Your operating system, what ever it may be, must support either RedHat Package Management (RPM), Debian Packages (DEB), or Macintosh Packages (PKG).  


----------


**Pre-Reqs**  

* An internet connection during the building phase  
* Have the following binaries/libraries installed before hand:

```bash
gcc  
gfortran  
flex  
make  
curl  
git  
bison  
tcl-devel  
tk-devel  
python-devel  
libblas-devel  
liblapack-devel  
freeglut3-devel  
libXt-devel  
ncurses-devel  
libedit-devel  
zlib-devel  
```

Note: Install the 'devel' arch type for all of the above where labeled as 'devel'

Hopefully, thats everything your machine requires, but in practice there's always something. If that 'something' comes up, the script will fail, and report what 'configure/make' reported to it. Usually that will be enough to understand what additional dependency is needed to continue. And once you do satisfy that dependency, re-running the script will pick up where it left off.  

----------

Clone the repository where ever you wish and enter the build_from_source directory:

```bash
git clone https://github.com/idaholab/package_builder.git  
cd package_builder/build_from_source
```

Create and chown the target directory:

```bash
sudo mkdir -p /some/path  
sudo chown -R <your user id> /some/path  
```
`/some/path` should be something standard. Example, on both Linux and Macintosh machines, it is standard to have external packages installed in the /opt/ directory. In our case, we use `/opt/moose`.    

`sudo chown`; We do this, so that the script we're about to execute does not require root privileges. Running scripts you find on the internet as 'root' is a bad idea.  

Engage!  

```bash
./make_all.py --prefix /some/path --max-jobs <int> --cpu-count <int>  
```

A word about those options:  
 --max-jobs basically builds this many modules at the same time  
 --cpu-count is how many processors to throw at anything requiring a `make -j`  

When/If a problem arises, it will normally be an additional dependency required (libperl-devel, libz-devel, etc). What ever the fix may be, once solved, simply re-execute the same make_all.py script with the same set of arguments and the script will pick up where it left off.  

If you ever need to start over, you will need to delete the `progress` file located in the `package_builder/build_from_source` directory. It is this file which allows make_all.py to continue where it left off. Items in this file with the same name as the bash scripts located in `build_from_source/packages` will be skipped. Just to give you a quick idea how that works.

After several hours hopefully everything completes! Once it does, you can source your new compiler stack by:  

 `source /some/path/environments/moose_profile`  

... and then verify the stack actually works by continuing to Step 2 on the [Getting Started][1]
 pages.  

Now that you have scrutinized your work thoroughly enough to warrant this build as 'redistributable for the masses worthy'... Continue on to creating the package.


----------
**Creating the Package**  

Depending on the type of operating system you have running, you will need to install the necessary binaries for package creation on that machine.   

RPM based machines; `rpmbuild`  
Debian based machines; `dpkg`  
Macintosh; `PackageMaker`  

Note: Obtaining PackageMaker requires that you have an Apple Developers account. As well as knowing which version of the Auxiliary Tools to download. I'll save you the search. You are going to want the version of auxiliary tools that was released on July 24th 2012. Download that DMG, and simply drag 'n drop PackageMaker to your /Applications folder. Apple has been moving towards distributing all packages via the AppStore aggressively, and thus, removed PackageMaker from their current Auxiliary Tools DMG.  

With the above out of the way, you simply need to run the `create.py` python script:  

```bash
cd create_redistributable/  
./create.py -p /some/path
```

`/some/path` being the same path you used during the `make_all.py --prefix /some/path` stage.  

By running that script, a couple of things happen. First, we copy everything necessary that constitutes a package into a temporary directory, and then we increment your build version by 1. This is important to note, because if you wish to maintain your own version control, you can easily do so by `forking` the package_builder repository and pushing this new version change to your fork every time you create a new version of this package. Simple.  


Building the package can take a very long time. Especially DEBs and RPMs. Please be patient. I have rarely seen this step fail. But if it fails for you, I would love to hear how, in the form of a pull request =D

The script will inform you when and where your newly built redistributable is sitting (the current directory where `create.py` resides). Enjoy your new redistributable!


  [1]: http://mooseframework.org/getting-started/