Game Development Reference
In-Depth Information
Targets have dependencies separated by a colon ( : ). Below each target is a list of commands, preceded
by a tab character.
To compile the application, type the command $ make . This will trigger the execution of the main
target all (this is a built-in name). The target is followed by a colon, then a series of dependencies—in
this case, all: $(OBJ) . Thus, when the main target kicks in, it will trigger the execution of the $(OBJ)
dependencies, which define the application object files. These object files will, in turn, start the
compilation process, defined by the target %o:%c , which essentially says, “process all .c files whenever
an .o dependency is found.” So. when a .c source file is read from the current directory, the following
will be displayed in the console:
Compiling file1.c ...
gcc -c file1.c -Ifolder1 -Ifolder2 ...
Compiling file2c ...
gcc -c file2c -Ifolder1 -Ifolder2 ...
Note the following lines in the Makefile:
@echo Compiling $<...
gcc -c $< $(INC)
The instruction @echo tells GNU make to display a message to the console, and the value $< is a built-
in variable that tells make to use the second argument from the target %o:%c as an argument to the
command (in this case, a .c file read from the file system). Note that the % character is equivalent to the
DOS * character, thus %.c means “all .c files in the current directory,” The next line, gcc -c $< $(INC) ,
will expand to gcc -c file1.c -Ifolder1 -Ifolder2 ... .
The process will continue for all object files defined in the variable OBJ . Execution will then resume
for the all target (provided there are no errors in the compilation process) with the linking step, and
with the following line displayed on the console:
Linking...
The line gcc -o myapp $(OBJ) $(LIB) will be expanded as follows:
gcc -o myapp file1.o file2.o ... -lc -lm -Lpath1 -Lpath2
This will produce the final binary myapp , which can then be run from the console.
This works fine for a x86 PC system. However, it will not work in an Android device for several
reasons. One is that the GCC produces binary files for an x86 architecture; desktop binaries will not run
in an ARM processor. (This could be easily fixed by replacing gcc with arm-none-linux-gnueabi-gcc .)
Another problem is that commands such as arm-none-linux-gnueabi-gcc -c file1.c -Ifolder1 -
Ifolder2 ... will compile the source code using standard header files (for the C runtime and others)
bundled with the toolchain. Depending on the version you are using, this could cause undesired side
effects, such as missing symbols at linkage time. For example, the following error is thrown when trying
to compile a file from the 3D game Doom for ARM:
arm-none-linux-gnueabi-gcc -Werror -Dstricmp=strcasecmp
-msoft-float -mcpu=arm9
 
Search WWH ::




Custom Search