Using Generated Makefiles
This document describes how to work with MakeMe generated Makefiles and how to tailor them to to suit your needs.
MakeMe can be used to generate complete Makefiles and projects for building via: make, nmake, Visual Studio or Xcode projects. Developers can then include these projects to building their code on specific platforms.
Building with the Makefile
To build with make, simply type:
$ make [Run] make --no-print-directory -f projects/appweb-macosx-default.mk all [Info] Use make SHOW=1 to trace executed commands. [File] macosx-x64-default/inc/mpr.h [Compile] src/deps/mpr/mprLib.c [Link] libmpr
Note the output is simplified so that build errors and compiler warnings are more obvious. If you wish to see the full compiler, linker and other build commands, include the SHOW=1 option:
$ make SHOW=1 [Run] make --no-print-directory -f projects/appweb-macosx-default.mk all [Info] Use make SHOW=1 to trace executed commands. [Compile] src/deps/mpr/mprLib.c /usr/bin/clang -c -o macosx-x64-default/obj/mprLib.o -w -g -DME_DEBUG \ -Imacosx-x64-default/inc src/deps/mpr/mprLib.c [Link] libmpr /usr/bin/clang -dynamiclib -o macosx-x64-default/bin/libmpr.dylib \ '-Wl,-rpath,@executable_path/' '-Wl,-rpath,@loader_path/' -g \ -compatibility_version 4.3.0 -current_version 4.3.0 \ -Lmacosx-x64-default/bin -install_name @rpath/libmpr.dylib \ macosx-x64-default/obj/mprLib.o -lpthread -lm -ldl
MakeMe eschews creating Makefiles that will work on all the possible platforms, rather it generates dedicated, simple, fast, non-recursive Makefiles that run quickly and simply for the dominant platforms: Linux, Mac OSX, Windows, and BSD. There is one Makefile for each platform. Developers can then easily extend for other platforms if required.
Developers typically deliver these per-platform Makefiles and IDE projects under the a projects directory and provide a top-level Makefile that detects your operating system and CPU architecture and then invokes the relevant per-platform Makefile for your system. For example:
$ make make -f projects/appweb-macosx-default.mk all
Selecting a Platform Makefile
Invoking the top-level Makefile will automatically invoke the appropriate platform makefile for the current system architecture. Some products provide optional static build makefiles. These are named: PRODUCT-OS-static.mk. If provided, you can select a static build via:
$ make PROFILE=static
MakeMe can generate a Makefile for Nmake which is the Windows variant of Make. This has a .nmake extension.
To build on Windows with nmake, you need to define the Visual Studio environment variables (via the Visual Studio vsvarsall.bat and then type:
$ make nmake -f projects\appweb-windows.nmake
Modifying Makefile Defaults
Generated Makefiles to not require the use of a configure program and provide a limited means of tailoring the build by suppling configuration options directly to make. These options override default values defined in the platform makefile. For example:
$ ME_EXT_EST=0 make
On linux and unix, you can supply the overrides as environment variables or on the make command line. On Windows, you must supply the overrides as environment variables only.
Configurable components are enabled by setting their corresponing ME_EXT_NAME option to 1. Disable by setting to zero. Some components require a path to locate their libraries and headers. Use ME_EXT_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.
If using make to install the product after compiling, use make install. However, 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 OpenSSL:
$ ME_EXT_OPENSSL=1 ME_EXT_OPENSSL_PATH=/usr/src/openssl make compile $ sudo ME_EXT_OPENSSL=1 ME_EXT_OPENSSL_PATH=/usr/src/openssl make install
Cross Compiling with Make
Building a product for a 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.
Appweb supplies makefiles for Linux, Windows, FreeBSD, MAC OSX and VxWorks. 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/appweb-vxworks-default.mk ARCH=x86 PROFILE=debug
When make runs, it places the output products (executables, libraries and objects) in a platform-specific output directory. This directory is named using the form: OS-ARCH-PROFILE. For example: vxworks-x86-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, you may be able to copy the closest makefile and edit to suit your target platform.
Specifying the CPU
Make will use a 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.
CC=/opt/bin/ccarm.exe \ LD=/opt/bin/ccarm.exe \ ARCH=arm \ CPU=arm7tdmi \ PROFILE=release \ make -f projects/appweb-vxworks-default.mk
To learn more, read about Cross Compiling with MakeMe.