Embedthis Appweb 3.4.0
Home >Source Code> Make Scheme

Quick Nav

See Also

Embedthis Make Scheme

Embedthis Make Scheme uses the GNU make tools and provides a set of make rules and targets to facilitate cross-platform and cross-target building.

The goals of the make scheme are:

Overview

The scheme uses recursive compilation and building where each directory contains a Makefile. Each Makefile includes a single dependency file called ".makedep". The ".makedep" file contains target dependencies and includes the necessary rules and configuration files.

Components

The make scheme uses the following components.

Quick Tour

The make scheme operates similarly to many open source projects and supports the following targets. These operate recursively applying the same target to relevant subdirectories. The directories recursed are specified in the PRE_DIRS and POST_DIRS variables.

Target Description
clean Remove intermediate and generated targets
compile Compile source files
depend Create the .makedep dependency file
install Install the software
package Create an installable distribution package
test Run unit tests
uninstall Uninstall the software

A Makefile looks similar to this example:

include    .makedep
 
compileExtra: myProg$(BLD_EXE)
 
myProg$(BLD_EXE): $(FILES)
    @bld --exe myProg$(BLD_EXE) $(OBJECTS)

Note: the BLD_EXE variable which allow the Makefile to be cross-platform. On Windows, BLD_EXE is set to ".exe" whereas on Unix systems BLD_EXE is set to "". This cross-platform variable and others are defined for you by the "build/config/config.*" files.

Targets

The scheme defines internal targets for clean, compile, depend, install, package, test and uninstall. If you require custom behavior for any of these targets, define a target with an "Extra" suffix. For example, to add extra processing to the clean target, define a "cleanExtra" target in your Makefile.

Make Variables

The following table describes the some of the make variables that are defined for you by the configure program.

Variable Typical Value Description
BLD_ARCH .a Platform specific extension for static libraries.
BLD_LIB .so Platform specific extension for default libraries (shared or static).
BLD_OBJ .o Platform specific extension for libraries.
BLD_SHLIB .so Platform specific extension for shared libraries.

The following table describes the some of the supported make variables that you can define in your Makefile.

Variable Typical Value Description
BUILD_CROSS 0 Cross-compile the directory. Set to 1 to enable and 0 to disable.
BUILD_NATIVE 1 Build the directory natively (for the development system). Set to 1 to enable and 0 to disable.
MAKE_CFLAGS Any local compiler flags.
COMPILE *.c List of files to be compiled. Can contain wild cards.
EXPORT_OBJECTS yes Export objects into a common object directory, typically BLD_TOP/obj.
MAKE_IFLAGS Any local include flags.
MAKE_LDFLAGS Any local link flags.
PRE_DIRS List of directories to be recursed before making the current directory.
POST_DIRS List of directories to be recursed after making the current directory.

Cross Compiling

If you are cross-compiling, the make scheme will automatically run twice: once for building for the development system and once for the target (host).

To control if a given directory should be built natively (for the development system) or cross (for the target host), use the BUILD_NATIVE and BUILD_CROSS make variables. Setting BUILD_CROSS to zero will disable cross compilation. Setting to one will enable. Setting BUILD_NATIVE to zero will disable native building, whereas setting to one will enable.

Dynamic Dependencies

The .makedep file is generated by invoking "make depend" which will run the genDepend program to parse the source files and generate the file dependency lists. For first time builds, the command build/bin/makedep will generate stub ".makedep" files. A typical ".makedep" file looks like the following:

all: compile
 
BLD_TOP := ../..
 
#
#   Read the build configuration settings and make variable definitions.
#
include $(BLD_TOP)/build/buildConfig.make
 
OBJECTS = $(BLD_OBJ_DIR)/mprSample$(BLD_OBJ)
 
$(BLD_OBJ_DIR)/mprSample$(BLD_OBJ):  \
    ../../mpr/mpr.h \
    ./mprSample.h
 
include $(BLD_TOP)/build/make/make.rules
include $(BLD_TOP)/build/make/make.$(BLD_BUILD_OS)

The BLD_TOP variable defines the top of the source tree and the OBJECTS variable lists all objects that will be made.

Rule and Configuration Files

Two files are included. The first, "buildConfig.make", is generated by the configure program and contains the configuration settings for this build. The "make.rules" file contains the make rules for this operating system. You should not hand edit the ".makedep" files. All changes should go into the Makefile.

Configure Variables

The configure program will create the "buildConfig.make" file. This file will contain the following variables. To ensure the entire source tree is relocatable, all paths are always paths relative to the top of the source tree.

Variable Typical Value (Linux) Description
BLD_ARCH .a File extension for static libraries.
BLD_BIN_DIR ${BLD_TOP}/bin Directory to hold executables.
BLD_CFLAGS "" The value of the CFLAGS environment variable when configure was run.
BLD_EXE (.exe on Windows) File extension for executables.
BLD_IFLAGS "" The value of the IFLAGS environment variable when configure was run.
BLD_INC_DIR ${BLD_TOP}/src/include Include headers directory.
BLD_LDFLAGS "" The value of the LDFLAGS environment variable when configure was run.
BLD_LIB .so File extension for the default library type (shared or static)
BLD_LIB_DIR ${BLD_TOP}/bin Directory to hold libraries.
BLD_MOD_DIR ${BLD_TOP}/lib/modules Directory to hold modules.
BLD_OBJ .o File extension for objects.
BLD_OBJ_DIR ${BLD_TOP}/obj Directory to hold objects. May be "." in some Makefiles if EXPORT_OBJECTS is not defined.
BLD_PIOBJ .lo File extension for position independent objects.
BLD_SHLIB (.lib on windows) Shared library extension when shared objects and shared libraries are separate files.
BLD_SHOBJ .so File extension for shared objects.
BLD_TOOLS_DIR ${BLD_TOP}/build/bin Directory to hold build tools.

The bld Program

The bld program is used to create executables and libraries. It provides a cross-platform interface that requires minimal typing in makefiles and is controlled by the per-O/S make.rules make include file. The bld program is not run as a stand-alone command and must be invoked from within a Makefile.

These make variables are defined in the make.rules file and are passed to the bld program.

Variable Description
_CFLAGS Compiler control flags. Does not include pre-processor defines.
_DFLAGS Compiler pre-processor define flags.
_IFLAGS compiler include directories.
_LDFLAGS Linker flags.
_LDPATH Path to directory containing libraries.
_LIBS System libraries to link with.

Bld Program Switches

In addition to the environment variables defined in the buildConfig.sh file, the bld program takes the following command line switches:

Switch Description
--c++ Program includes C++ components
--debug Not implemented
--dry-run Trace commands but do not execute
--entry NAME Shared library entry point
--exe NAME Name of executable to build
--graphical Create a windowed program instead of a console program (Windows only)
--help Print usage information
--library NAME Name of library to link
--libs "LIBRARIES ..." Extra libraries to link with
--objects "OBJECTS ..." String containing list of objects to link
--quiet Run quietly without tracing actions to stdout
--resources FILE Resource file (menus and icons for Windows)
--rpath PATH Specify the executable run-time library search path (Unix only)
--shared Only make a shared library
--soname Create a versioned shared library with a SONAME
--static Only make a static library
--syslibs "LIBRARIES ..." Extra system libraries ot link with
--version Print the bld version number.
--versionSoname Create a versioned shared library with soname
--verbose Verbose operation. Traces internal searching strategies.

The bld program also uses the following environment variables:

Variable Description
BLD_TOP Top of the source tree. This is automatically set by the genDepend program in the .makedep files.
BLD_FEATURE_STATIC Build static libraries where relevant. This is defined by the configure --static switch.

© Embedthis Software LLC, 2003-2012. All rights reserved. Embedthis, Ejscript and Appweb are trademarks of Embedthis Software LLC.