Building with Make or Nmake

This document describes the process to build the software from source using Make or Nmake on Windows. First make sure you have read the Building Overview to prepare your build environment.

Platform Makefiles

MakeMe can create a suite of generated, pre-configured Makefiles for common platforms. These are simple makefiles that build a default configuration for a specific operating system. These makefiles are typically provided under the ./projects directory.

A top level Makefile is also provided that detects your operating system and CPU architecture and then invokes the appropriate project Makefile for your system. For example:

$ make
make --no-print-directory -f projects/ all

Windows Nmake

On Windows, a make.bat file is provided to to invoke nmake. The make.bat file first invokes projects/windows.bat to setup the necessary Visual Studio environment variables for compiling. If you have already setup your Visual Studio environment by running vcvarsall.bat, the windows.bat will simply invoke the namefile without modifying your environment.

To build on Windows with nmake, type:

$ make
nmake -f projects\NAME-windows.nmake

Modifying the Makefile Defaults

You do not use a configure program when building via Make, that is used only for building with MakeMe. Rather, you supply configuration options directly to Make. These options override default values defined by the projects/ makefile and by the projects/NAME-OS-debug-me.h file. For example, to disable use of SQLite:

$ make ME_COM_SQLITE=0 

Configurable components are enabled by setting their corresponding ME_COM_NAME option to 1. Disable by setting to zero. Some components requires a path to locate libraries and headers. Use ME_COM_NAME_PATH to define the path to the component.

By defining make variables such as CC and CFLAGS, you can modify the compiler options. This is the also the technique used when cross-compiling.

To see the list of configurable options, run make help:

$ make help
usage: make [clean, compile, install, run, uninstall]
The default configuration can be modified by setting make variables
Set to 0 to disable and 1 to enable:
  PROFILE          # Select default or static for static linking
  ME_EJS_DB        # Enable database support, ejs.db
  ME_EJS_MAIL      # Enable mail support, ejs.mail
  ME_EJS_MAPPER    # Enable database mapper support, ejs.mapper
  ME_EJS_TAR       # Enable tar support, ejs.tar
  ME_EJS_TEMPLATE  # Enable template support, ejs.template
  ME_EJS_WEB       # Enable web support, ejs.web
  ME_EJS_ZLIB      # Enable zlib support, ejs.zlib
  ME_ESP_MDB       # Enable ESP MDB database support
  ME_ESP_SDB       # Enable ESP SQLite database support
  ME_MPR_LOGGING   # Enable application logging
  ME_MPR_TRACING   # Enable debug tracing
  ME_COM_CGI       # Enable the CGI handler
  ME_COM_DIR       # Enable the directory listing handler
  ME_COM_EJSCRIPT  # Enable the Ejscript handler
  ME_COM_ESP       # Enable the ESP web framework
  ME_COM_EST       # Enable the EST SSL stack
  ME_COM_OPENSSL   # Enable the OpenSSL SSL stack
  ME_COM_PHP       # Enable the PHP framework
  ME_COM_SQLITE    # Enable the SQLite database
  ME_ROM           # Build for ROM without a file system

For example, to disable CGI:
  ME_COM_CGI=0 make

Other make variables:
  ARCH               # CPU architecture (x86, x64, ppc, ...)
  OS                 # Operating system (linux, macosx, windows, vxworks)
  CC                 # Compiler to use
  LD                 # Linker to use
  DEBUG              # Set to debug or release for debug or optimized builds
  CONFIG             # Output directory for built items.
  CFLAGS             # Add compiler options. For example: -Wall
  DFLAGS             # Add compiler defines. For example: -DCOLOR=blue
  IFLAGS             # Add compiler include directories.
  LDFLAGS            # Add linker options
  LIBPATHS           # Add linker library search directories.
  LIBS               # Add linker libraries. For example: -lpthreads
  PROFILE            # Build profile, used in output products directory name

On windows, set the variables in your environment rather than passing on the command line.

Installing with Make

You can install the newly built software via:

sudo make install

You can remove by:

sudo make uninstall
Must Use Exact Same Options

It is essential when invoking make install, that you provide the same make flags and options as you did when compiling. This is because the Makefile will conditionally install only the selected components for those options.

For example, to build and install PHP, use the same options for the compile and install commands:

$ make ME_COM_PHP=1 ME_COM_PHP_PATH=/usr/src/php compile
$ sudo make ME_COM_PHP=1 ME_COM_PHP_PATH=/usr/src/php install


If you need to deploy to a different system or capture the build products, you can install to a specific directory via:

make deploy

This will install to the deploy directory under the output platform directory.

Cross Compiling with Make

Building a product for platform different to that of the local system is called cross compiling. Sometimes this compiling is just for a different instruction set (say x64 instead of x86). Other times, it is for a completely different operating system and/or CPU architecture. In such cases, a cross-compiler is typically required to build for the target platform.

To cross compile, you invoke the relevant project makefile and pass the required CPU architecture as a make variable. For example, to cross compile for VxWorks on ARM:

make -f projects/ ARCH=arm PROFILE=debug

When make runs, it places the output products (executables, libraries and objects) in a platform-specific output directory. This is named using the form: OS-ARCH-PROFILE. For example: vxworks-arm-debug. In this manner, make can be invoked multiple times, once for each target platform and the results will be captured in separate platform output directories. Some of the supported architectures for the ARCH field are: arm, mips, ppc, x64 and x86. The PROFILE is a descriptive name chosen by you for your configuration.

If there is not a makefile for your target operating system, copy the closest makefile and edit to suit your target platform.

Specifying the CPU

The build will use the generic CPU type within the specified architecture. To override the default choice and specify a CPU type within an architecture, use the CPU variable. For example:

make OS=vxworks ARCH=arm CPU=arm7tdmi

Specifying a Tool Chain

You may need to specify where Make can locate your cross-compiler and other tools. You can supply these via the make variables: CC, CFLAGS, DFLAGS, IFLAGS, LD and LDFLAGS.

For example:

make CC=/opt/bin/ccarm.exe LD=/opt/bin/ccarm.exe ARCH=arm PROFILE=release
    -f projects/

Supporting OpenSSL

If OpenSSL is required to provide SSL support, you must specify the path to the OpenSSL source directory. For example:

make ME_COM_OPENSSL=1 ME_COM_OPENSSL_PATH=/path/to/openssl compile

If you are using a binary OpenSSL distribution, provide the path where the OpenSSL libraries are located (typically /usr/lib).

make ME_COM_OPENSSL=1 ME_COM_OPENSSL_PATH=/usr/lib compile

Static Building

If you require a static build without the ability to dynamically load modules, use the static makefile profile. For example:

make PROFILE=static

Some web frameworks such as ESP and Ejscript may have reduced functionality in static builds.

Building for VxWorks

Before building for VxWorks, you must define the WIND_* environment variables via the script provided with VxWorks. This defines the WIND_BASE, WIND_HOST_TYPE and other required environment variables.

The command below runs and defines the WIND variables in the current shell's environment.

eval `/WindRiver/ -p vxworks-6.8 -o print_env -f sh`

Once defined, you can invoke make.

make OS=vxworks

If you require a static build, set the profile to "static".

make OS=vxworks PROFILE=static

© Embedthis Software. All rights reserved.