Artistic Style - Installation

# Artistic Style Install Information

### Contents

Artistic Style Versions

Linux Version

CMake Linux

GCC Makefile

Clang Makefile

Intel Makefile

CodeBlocks Linux

MacOS Version

CMake MacOS

MacOS Makefile

Xcode

Windows Version

Precompiled Executable

CMake Windows

CodeBlocks Windows

Visual Studio

Other Makefile Targets

Other Development Environments

Compiler Options

Python PIP

### Artistic Style Versions

astyle_x.x_linux.tar.gz is the Linux version of Artistic Style. It contains the source code, documentation, and makefiles. The Linux Version compile instructions below give information for compiling the source code.

astyle_x.x_macos.tar.gz is the Mac OS version of Artistic Style. It contains the source code, documentation, Xcode project files, and a makefile. The Mac OS Version compile instructions below give information for compiling the source code.

astyle_x.x_windows.zip is the Windows version of Artistic Style. It contains the source code, documentation, and an executable. The Windows Version compile instructions below give information for compiling the source code.

astyle_x.x_windows_x64.zip is the Windows 64 bitversion of Artistic Style. It contains the source code, documentation, and an executable. The Windows Version compile instructions below give information for compiling the source code.

Only one platform is supported in each distribution package. If you use Artistic Style on more than one platform you will need to download packages for each platform. The main difference in platforms is the build directories and the line endings. Most compilers and development packages will accept any type of line ending. The source code and documentation are the same for all distributions.

### Linux Version

#### CMake Linux

Artistic Style has CMake support for GCC, Clang, and Intel compilers. Other compilers will probably work if the necessary options are set. Refer to the section on Compiler Options for more information.

Since the different builds use the same source files an "out of source" build should be used. The default build is a release version. A debug version must be specifically requested. The following options are available for building the various configurations.

- The default builds the Artistic Style command line executable (astyle).
- BUILD_SHARED_LIBS=ON builds the Artistic Style program as a shared object (libastyle.so).
- BUILD_JAVA_LIBS=ON builds the Artistic Style program as a shared object (libastylej.so) that can be called from a Java program. The Java Development Kit (JDK) must be installed for the project to compile. CMake will look for the JDK in the Java default folder or in a system path. If the files cannot be found, use the variable JAVA_HOME=<Java Directory> with the path into the top level Java folder.
- BUILD_STATIC_LIBS=ON builds the Artistic Style program as a Static Library (libastyle.a) that can be statically linked to a user program.

##### EXAMPLES

The following examples are assumed to be run from the astyle directory that contains CMakeLists.txt. They show out of source builds that generate makefiles.

To build the console release version:

    mkdir  as-gcc-exe
    cd  as-gcc-exe
    cmake  ../
    make

To build the shared debug version:

    mkdir  --parents  as-gcc-so
    cd  as-gcc-so
    cmake  -DBUILD_SHARED_LIBS=ON  -DCMAKE_BUILD_TYPE=Debug  ../
    make

To build the Java release version using the Clang compiler and the JAVA_HOME variable:

    mkdir  as-clang-java
    cd  as-clang-java
    CXX=clang++  cmake  -DBUILD_JAVA_LIBS=ON  -DJAVA_HOME="C:/Programs/Java"  ../
    make

##### INSTALL

The makefile install option installs the astyle executable and documentation files. The option installs from the generated makefile, not CMake. You must have the appropriate permissions to use install.

To install astyle:

    make install

The default install directory is /usr/local/bin for the executable and /usr/local/share/doc/astyle for the documentation. To change the default install directory from /usr/local the CMake must be run with the option CMAKE_INSTALL_PREFIX.

To run CMake and change the install directory:

    cmake  -DCMAKE_INSTALL_PREFIX=/usr  ../
    make install

##### UNINSTALL

There is no uninstall. The easiest way to uninstall is to use the install_manifest.txt file, for example "xargs rm < install_manifest.txt".

#### GCC Makefile

To compile using the GCC compiler you must have GCC (3.1 or better) installed.

The build has no autoconf dependency. To build the Artistic Style configurations, use the makefile located in the astyle/build/gcc directory. The executables will be in the astyle/build/gcc/bin directory. To build the command line configuration, enter the following:

    cd astyle/build/gcc
    make

To build the other astyle configurations, you can enter the file name or a symbolic name. Entering "make astyle" or "make release" will build the command line configuration. Following are the symbolic names and file names (in parens) of the various configurations:

- release or astyle builds the Artistic Style command line program. This is the default option.
- shared or libastyle.so builds the Artistic Style program as a shared library.
- static or libastyle.a builds the Artistic Style program as a static library.
- debug or astyled builds the Artistic Style command line program with debugging information
- shareddebug or libastyled.so builds the Artistic Style program as a shared library with debugging information.
- staticdebug or libastyled.a builds the Artistic Style program as a static library with debugging information.
- all builds all the above configurations.

  The following Java shared library builds are separate from the above. They include a Java Native Interface (JNI) and require that the Java Development Kit (JDK) be installed. The environment variable JAVA_HOME should be defined. It defines the install directory for the JDK. If the compile cannot find the file jni.h, either set the JAVA_HOME variable or change the value in the makefile.

- java builds the Artistic Style program as a shared library which includes the JNI (libastylej.so).
- javadebug builds the Artistic Style program as a shared library which includes the JNI and debugging information (libastylejd.so).
- javaall builds all the above java configurations.

More than one configuration can be built at the same time. For example, to build all the release configurations enter:

    cd astyle/build/gcc
    make release shared static

The Other Makefile Targets section contains additional target options.

#### Clang Makefile

Clang has a static analyzer that finds potential bugs in C/C++ and Objective-C programs. It can be run as a standalone tool from the command-line and runs in tandem with a build. There is a script file, analyze.sh, that will run the analysis on Artistic Style.

The build has no autoconf dependency. To build the Artistic Style configurations use the makefile located in the astyle/build/clang directory. The executables will be in the astyle/build/clang/bin directory. To build the command line configuration, enter the following:

    cd astyle/build/clang
    make

To build the other astyle configurations, you can enter the file name or a symbolic name. The configurations for Clang are the same as for the GCC Makefile. More than one configuration can be built at the same time. For example, to build all the release configurations enter:

    cd astyle/build/clang
    make release shared static

The Other Makefile Targets section contains additional target options.

#### Intel Makefile

These procedures and the makefile are for recent versions of the compiler. They may not work for earlier versions. Instructions for your compiler are in the compiler documentation file "get_started_lc.htm".

To compile with Intel there are environment variables that must be set by running the compiler environment script compilervars.sh (or compilervars.csh) with an argument that specifies the target architecture. This should be done before running the make. If it is not done, "make" will display an error message stating that the compiler environment variables are not set.

The build has no autoconf dependency. To build the Artistic Style configurations use the makefile located in the astyle/build/intel directory. The output executables will be in the astyle/build/intel/bin directory. To build the command line configuration, enter the following:

    cd astyle/build/intel
    make

To build the other astyle configurations, you can enter the file name or a symbolic name. The configuration names for Intel are the same as for the GCC Makefile. More than one configuration can be built at the same time. For example, to build the entire debug configurations enter:

    cd astyle/build/intel
    make debug shareddebug staticdebug

The Other Makefile Targets section contains additional target options.

#### CodeBlocks Linux

There are build folders for the following compilers. All compiler folders are in the "build" directory.

- cb-clang contains the workspace and project files for the Linux Clang Compiler.
- cb-gcc contains the workspace and project files for the Linux GCC Compiler.
- cb-intel contains the workspace and project files for the Linux Intel Compiler.

There are workspace and project files for each folder. All projects have at least Debug and Release configurations. All output will be in the "bin" directory.

The workspace contains the following projects.

- AStyle builds the Artistic Style command line program (astyle).
- AStyle So builds the Artistic Style program as a shared object (libastyle.so).
- AStyle Java builds the Artistic Style program as a shared object (libastylej.so) that can be called from a Java program. The Java Development Kit (JDK) is required for the project to compile. The Project Properties must have an include path to the JDK include directories.
- AStyle A builds the Artistic Style program as a Static Library (libastyle.a). This can be statically linked to a user program.

For other Linux development environments, follow the instructions in Other Development Environments.

### MacOS Version

#### CMake MacOS

Artistic Style has CMake support for MacOS. It is used the same as CMake Linux except the supported compilers are only GCC and Clang. The macOS default installs will be to /usr/local instead of /usr.

#### MacOS Makefile

The Artistic Style makefile compile uses the Mac OS "Command Line Tools". If you have Xcode 4.3 or newer the command line tools, such as "make", are NOT installed by default. They must be downloaded and installed separately. Once everything is successfully installed, you should see "make" and other command line developer tools in /usr/bin.

The build has no autoconf dependency. To build the Artistic Style configurations use the makefile located in the astyle/build/mac directory. The executables will be in the astyle/build/mac/bin directory. To build the command line configuration, enter the following:

    cd astyle/build/mac
    make

To build the other astyle configurations, you can enter the file name or a symbolic name. The configurations for Mac are the same as for the GCC Makefile. More than one configuration can be built at the same time. For example, to build all the release configurations enter:

    cd astyle/build/mac
    make release shared static

The Other Makefile Targets section contains additional target options. The macOS default installs will be to /usr/local instead of /usr.

#### Xcode

Artistic Style workspace and project files for the Xcode development environment are available in the "build/xcode" directory. A workspace can be used to build a single project or all the projects. The project files have Debug and Release configurations. The following projects are available.

- AStyle builds the Artistic Style command line program (astyle).
- AStyleA builds the Artistic Style program as a Static Library (libastyle.a). This can be statically linked with an executable.
- AStyleDylib builds the Artistic Style program as a Dynamic Library (libastyle.dylib). It can be used with C/C++, Objective-C, C#, and Python programs.
- AStyleJava builds the Artistic Style program as a Dynamic Library (libastylej.dylib) that can be called from a Java program. The Java Development (JDK) is required for the project to compile. The Project Properties must have an include path to the JDK include directory. The output dylib can also be called from a C++ or C# program.

##### INSTALL

Only the astyle executable is installed. The library project installs are sent to UninstalledProjects in the Build directory. The following instructions are for the astyle executable and documentation files. The default install directory is /usr/local/bin for the executable and /usr/local/share/doc/astyle for the documentation. You must have the appropriate permissions to use install. If sudo is not used for the install, an error will occur during the build.

To install the astyle executable in the default directory:

    cd astyle/build/xcode
    sudo xcodebuild install -project AStyle.xcodeproj

A script is used to install the documentation from the same directory.

    sudo bash install.sh

##### UNINSTALL

Uninstalls the executable and documentation. You must have the appropriate permissions to use uninstall.

A script is used to uninstall astyle and the documentation:

    sudo bash uninstall.sh

NOTE: The uninstall option will NOT remove the .astylerc files from the users' home directories. The files must be removed individually for each user.

### Windows Version

#### Precompiled Executable

In addition to the source files, the Windows distribution package contains an Artistic Style Win32 executable (AStyle.exe). If you prefer to compile the executable yourself, use the following instructions.

#### CMake Windows

Artistic Style has CMake support for Borland, and MinGW compilers. Other compilers will probably work if the necessary options are set. Refer to the section on Compiler Options for more information.

The console executable will run for both of the supported compilers. The DLL builds may not. CMake does not fully support all Windows compilers. To build the DLLs it would be best to generate an IDE project file and compile the DLLs with the IDE. The "build" folder contains project files for CodeBlocks and Visual Studio.

Since the different builds use the same source files an "out of source" build should be used. The default build for MinGW is a release version. A debug version must be specifically requested. For Borland, a release build may need to be specifically requested, depending on the CMake release used. Borland has been tested with the bcc32c free compiler. It may or may not work with other Borland compilers. The following options are available for building the various configurations.

- The default builds the Artistic Style command line executable (AStyle.exe).
- BUILD_SHARED_LIBS=ON builds the Artistic Style program as a DLL (AStylexx.dll, where xx is the astyle release number).
- BUILD_JAVA_LIBS=ON builds the Artistic Style program as a DLL (AStylexxj.dll, where xx is the astyle release number) that can be called from a Java program. The Java Development Kit (JDK) must be installed for the project to compile. CMake will look for the JDK in the Java default folder or in a system path. If the files cannot be found, use the variable JAVA_HOME=<Java Directory> with the path into the top level Java folder.
- BUILD_STATIC_LIBS=ON builds the Artistic Style program as a Static Library (AStyleLib.lib) that can be statically linked to a user program.

##### EXAMPLES

The following examples are assumed to be run from the astyle directory that contains CMakeLists.txt. They show out of source builds that generate makefiles.

A path to the compiler executable may need to be declared before compiling. And the Borland free compiler will need the compiler name. To set the variables before compiling (replace the path names with the paths on your computer):

    set PATH=C:\Program Files\CMake\bin;%PATH%
    set PATH=C:\Program Files (x86)\Embarcadero\BCC101\bin;%PATH%
    set CXX=bcc32c

To build the Borland console release version (the release build may need to be specified):

    md  as-bcc32c-exe
    cd  as-bcc32c-exe
    cmake  -G "Borland Makefiles"  -DCMAKE_BUILD_TYPE=Release  ../
    make

To build the MinGW Java release version using the JAVA_HOME variable:

    md  as-mingw-exe
    cd  as-mingw-exe
    cmake  -G "MinGW Makefiles"  -DBUILD_JAVA_LIBS=ON  -DJAVA_HOME="C:/Programs/Java"  ../
    mingw32-make

As stated previously, the DLL builds may not work with the CMake generated makefiles.

##### INSTALL

The makefile install option installs the astyle executable and documentation files. The default is "C:\Program Files\AStyle" for the executable and "C:\Program Files\AStyle\doc" for the documentation. You may need to run as an administrator to install.

##### UNINSTALL

There is no uninstall. The uninstall must be done manually. Just remove the AStyle folder indicated in the Install.

#### CodeBlocks Windows

There are build folders for the following compilers. All compiler folders are in the "build" directory.

- cb-bcc32c contains the workspace and project files for the Embarcadero BCC32C Compiler.
- cb-mingw contains the workspace and project files for the MinGw or TDM_GCC Compilers.

There are workspace and project files for each folder. All projects have at least Debug and Release configurations. All output will be in the "bin" directory.

The workspace contains the following projects.

- AStyle builds the Artistic Style command line program (AStyle.exe).
- AStyle Dll builds the Artistic Style program as a shared object (AStyle.dll).
- AStyle Java builds the Artistic Style program as a shared object AStylej.dll) that can be called from a Java program. The Java Development Kit (JDK) is required for the project to compile. The Project Properties must have an include path to the JDK include directories.
- AStyle Lib builds the Artistic Style program as a Static Library (astyle.lib). This can be statically linked to a calling program.

For other Windows development environments, follow the instructions in Other Development Environments.

#### Visual Studio

There are solution and project files for several versions of Microsoft Visual Studio. Open an Artistic Style solution file in the appropriate "build" directory. All projects have Debug, Release and Static configurations. Debug file output will be in the "debug" directory. Release file output will be in the "bin" directory. Static file output will be in the "binstatic" directory. The following solution files are available.

- All AStyle builds the release and the debug configurations for all the following.
- AStyle builds the Artistic Style command line program (AStyle.exe). This project has an extra "Static"" option. It is the same as the "Release" build except that it is linked with a static runtime library. This is needed if the executable is to be run on a system without Visual Studio installed. The builds for this configuration are placed in a separate "binstatic" directory.
- AStyle Dll builds the Artistic Style program as a Dynamic Link Library (AStyle.dll). This will also build an export library and a static library for linking the dll.
- AStyle Java builds the Artistic Style program as a Dynamic Link Library (AStylej.dll) that can be called from a Java program. The Java Development (JDK) is required for the project to compile. The Project Properties must have an include path to the JDK include and include/win32 directories. This is set in "Project > Properties > C/C++ > General > Additional Include Directories". The default setting is for the JDK to be installed in the default directory, but it may not be the most current release. The output DLL can also be called from a C++ or C# program.
- AStyle Lib builds the Artistic Style program as a Static Library (libAStyle.lib). This can be statically linked to a calling program.

For other Windows development environments, follow the instructions in Other Development Environments.

### Other Makefile Targets

The following makefile targets are available for GCC, Clang, Intel, and Mac.

##### CLEAN

Removes the object and executable files for all configurations.

To remove the files for all configurations:

    make clean

##### CLEANOBJ

Removes the object files for all configurations. The executables will not be removed.

To remove only the object files for all configurations:

    make cleanobj

##### INSTALL

Installs the astyle executable and documentation files. The default is /usr/bin for the executable and /usr/share/doc/astyle for the documentation. You must have the appropriate permissions to use install.

To install the astyle to the default directories:

    sudo make install

To install astyle to a different bin directory set a value for the macro $(prefix). For example, to install the executable to a user's home directory (/home/user/bin):

    sudo make prefix=$HOME install

##### UNINSTALL

Uninstalls the executable and documentation. You must have the appropriate permissions to use uninstall.

To uninstall astyle from the default directories:

    sudo make uninstall

To uninstall the files from a different directory set a value for the macro $(prefix). For example, to uninstall the files from a user's home directory (/home/user):

     sudo make prefix=$HOME uninstall

NOTE: The uninstall option will NOT remove the .astylerc files from the users' home directories. The files must be removed individually for each user.

### Other Development Environments

To use other development environments project files usually must be built. CMake can be used if the development environment is supported. Otherwise, use the development environment to create files.

- Create a project using the development environment.
- Add to the project all the .cpp and .h files in the "src" directory.
- The Compiler Options section discusses the compiler options to use.
- Compile.

### Compiler Options

No macro definitions are required to compile the executable. To compile as a static or shared (dynamic) library define the macro ASTYLE_LIB. To compile a Java shared (dynamic) library define the macro ASTYLE_JNI. The option ASTYLE_NO_EXPORTS is sometimes needed for static libraries to prevent compiler error and warning messages. Use the appropriate compiler and linker options to compile the static or shared library. Add debug options to compile the debug versions.

Artistic Style is a small program and it is best to optimize for speed. The debug configurations are not usually optimized. To optimize for speed in the release configurations, use the macro NDEBUG to remove asserts. If necessary, use an option to activate the C++11 standards (-std=c++11 or -std=c++0x on most compilers). Use an option that allows inline function expansion. Runtime Type Information (RTTI) is NOT needed and exceptions are NOT used. Use whole program optimization if your compiler supports it. There may be other options you can use depending on the compiler.

### Python PIP

There are two projects which enable astyle installation using PIP: astyle-wheel and astyle_py (using WASM).
These are useful to be included in git pre-commit hooks.