Makefile introduction

#print in makefile

$(error   VAR is $(VAR))
$(warning VAR is $(VAR))
$(info    VAR is $(VAR))

#make and log to a file

make 2>&1 | tee build.log

File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).

Here is one way to remember this construct (although it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named 1". & indicates that what follows and precedes is a file descriptor and not a filename. So the construct becomes: 2>&1.

Consider >& as redirect merger operator.

#set the cross compiler (CROSS_COMPILE)

make CROSS_COMPILE=arm-cortex_a8-linux-gnueabihf- 

or 

$ export CROSS_COMPILE=arm-cortex_a8-linux-gnueabihf-
$ make

note, the makefile has the CC,LD,etc. definiations of toolchain

$CC = ${CROSS_COMPILE}gcc

 

#autotools

The auto tools will automatic generate the makefile to meet different platforms, e.g. cross compiler, different gcc version, etc.

The typical commands 

$ ./configure
$ make
$ sudo make install

you can get the help by ./configure --help

Autotools is able to handle cross development as well. some shell variables are used.

CC: The C compiler command
CFLAGS: Additional C compiler flags

LDFLAGS: Additional linker flags; for example, if you have libraries in a nonstandard directory <lib dir>, you would add it to the library search path by adding -L<lib dir>

LIBS: Contains a list of additional libraries to pass to the linker; for instance, -lm for the math library
CPPFLAGS: Contains C/C++ preprocessor flags; for example, you would add -I<include dir> to search for headers in a non-standard directory <include dir>
CPP: The C preprocessor to use

An example for defining the cross compiler, CC=arm-cortex_a8-linux-gnueabihf-gcc ./configure

There are three concepts for cross compilation:

- Build is the computer that builds the package, which defaults to the current machine.
- Host is the computer the program will run on; for a native compile, this is left blank and it defaults to be the same computer as build. When you are cross compiling, set it to be the tuple of your toolchain.
- Target is the computer the program will generate code for; you would set this when building a cross compiler, for example.
So, to cross compile, you just need to override the host, as follows:
$ CC=arm-cortex_a8-linux-gnueabihf-gcc \
./configure --host=arm-cortex_a8-linux-gnueabihf

 

#condition in makefile

an example to check the PUBLISH is equal ON

ifeq (${PUBLISCH},ON)

#here when PUBLISH = 'ON'

else

endif

#below is my presentation long time ago.

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2019-01-30 11:35  荷树栋  阅读(170)  评论(0)    收藏  举报

导航