Generating IDE Projects and Makefiles

MakeMe can generate generate complete project files for building using: make, nmake, Visual Studio, Xcode or plain shell scripts. The generated Makefiles or projects are clean, regular and easy to understand or modify.

This document describes how to generate Makefiles and IDE projects using MakeMe. If you wish to learn how to use MakeMe generated Makefiles, read the Using Generated Makefiles guide.

Targets

When MakeMe generates a Makefile or IDE project, it translates the each MakeMe target onto a project or target in the Makefile or IDE. In Make, MakeMe targets become Make targets. In Visual Studio, MakeMe targets become projects. The result is a completely native Makefile or IDE project that executes at optimal speed while faithfully representing the project.

Makefiles

The Makefiles generated by MakeMe are flat, meaning that no recursion is used. The entire project is expressed as one Makefile. This is desirable because the Makefiles are much simpler to read, understand and modify, and they run fast.

The Makefiles include definitions at the top that can be overridden by specifying Makefile variables on the make command line. There are variables for the compiler, linker, compiler flags, output directory and installation prefixes, Here is a sample of the Makefile variables:

CC      ?= /usr/bin/gcc
LD      ?= /usr/bin/ld
CONFIG  ?= $(OS)-$(ARCH)-$(PROFILE)

To override, set the relevant Makefile variable in the environment. Note: this must be supplied each time Make is invoked.

CC=/usr/bin/ccache/gcc make

On Linux (Unix), these may also be provided on the make command line. But for Windows, they must be provided via the environment.

The definitions are made available to source files during compilation via the generated me.h header file. Make variables provided via the environment are converted into preprocessor definitions and override the default values in me.h. The me.h header is constructed in such a way to allow overriding by command line preprocessor definitions. For example:

ME_EXT_SSL=0 make

This will override the me.h definition and will disable the use of SSL.

Windows Makefiles

The Windows Makefiles that MakeMe generates are similar to Unix Makefiles, except they are designed to work with Windows Nmake. The generated code will run natively without requiring a Unix emulator like cygwin.

Visual Studio Projects

For Visual Studio, MakeMe creates a Visual Studio sub-projects are created for each MakeMe executable, library, script or file target. This may seem like a lot of projects, but the organization is simple and maps MakeMe dependencies well onto Visual Studio project dependencies.

MakeMe generates a solution file which includes all the generated projects. MakeMe creates Visual Studio project property files for the product, debug and release builds and for X86 and X64 architectures. This enables changed property file settings to be easily inherited by all projects.

Xcode Projects

For Xcode, MakeMe creates an Xcode project with targets for each MakeMe executable, library, script or file target. The MakeMe dependencies are mapped onto Xcode target dependencies.

Shell Projects

A shell project is just a simple straight line set of commands to build the product.

Generating

MakeMe uses the --gen command line option to specify the projects to build.

me --platform macosx-x64-debug -configure . -gen xcode,make

This will generate an Xcode project and a Makefile for MAC OSX. Arguments to -gen are: make, nmake, shell, vs, xcode, for: Make, Windows Nmake, Shell script, Visual Studio project and Xcode project.

MakeMe is capable of cross-generating projects for non-native platforms. For example: you can generate an Xcode project for Mac OS X on a Windows system, or generate Windows Visual Studio Projects on a Mac.

When generating for a non-local platform, you must select the -configure . option. If generating for the local platform, you do not need to reconfigure.

You should choose a unique profile name ("debug" in the example above). The platform output products directory will contain this name and if you are building via MakeMe, Makefile and/or IDE, it is important to keep the various output products directories separate. This is because some IDEs will add incompatible compiler options that will not interoperate with builds by Make or MakeMe.

Generating Targets

MakeMe can automatically create equivalent Makefile and IDE project commands for compiling objects, exporting headers, building libraries, executables and copy file targets. You do not need to specify any additional information, MakeMe will translate the current MakeMe targets appropriately for each generated project. But for custom actions, MakeMe needs some guidance.

Generating from Custom Actions

MakeMe provides a suite of generate properties that are useful to explicitly provide the code to emit into the generated Makefile or project file. For example:

stest: {
    build:            "print('Script to run at build time')",
    'generate-sh':    "echo Script to run in shell script projects",
    'generate-make':  "echo Script to run in Makefiles",
    'generate-nmake': "echo Script to run in Windows Nmake files",
    'generate-vs':    "echo Script to run in Visual Studio ",
    'generate-xcode': "echo Script to run in Xcode",
    'generate-linux': "echo Script to run on Linux",
    'generate':       "echo Script to run anywhere else",
}

When generating, MakeMe examines each target for the presence of generate properties. It tests for these properties in the order below (from the most specific to the least specific):

  1. generate-PROJECT-EXACT-TYPE
  2. generate-PROJECT-COMPATIBLE-TYPE
  3. generate-OS
  4. generate

The EXACT-TYPE means that the exact project type will have highest priority. For example: if generating Xcode, if a generate-xcode property exists, it will take precedence. The COMPATIBLE-TYPE means that if the exact type match is not present, a compatible generation property may be used. The compatible options are: for Xcode, a generate-sh will be acceptable. Similarly, if generating a Visual Studio project, a generate-nmake will be acceptable.

If the exact and compatible generate properties are not present, MakeMe checks if a platform specific property is present. For example: generate-linux can be used to provide a script for Linux Makefiles.

If none of these options are present, MakeMe checks for a generic generate property.

Generating Conditional Makefiles

MakeMe can generate conditional Makefiles where the list of targets to build may be modified at run-time depending on Make environment variables. These variables override default values defined in the platform makefile and/or the product me.h configuration header. For example:

$ ME_EXT_EST=0 make

This will disable use of the EST (Embedded Security Transport SSL).

The ifdef target property is used to specify what components are required by a target before it will be built.

rocket: {
    type: 'exe'
    sources: '*.c',
    ifdef: [ 'ssl' ],
},

Only if the ssl component is enabled, will the generated Makefile build the rocket target.

Learn More

To learn more, read some actual MakeMe Samples.

© Embedthis Software, 2003-2015. All rights reserved.