# set Compiler
CC = g++
#-fpic acts on the compile phase, telling the compiler to generate location-independent code
The #-D macro definition, equivalent to the global # define in C, can be used to control the compilation of the source program through macro definitions, for example:
# #ifdef _fileline
# printf ("Hello Yu Qiang, How is you?\n");
# #else
# printf ("Sorry to Lost. \ n ");
# #endif
# program Final call output is: Hello Yu Qiang, how is it?
Cflag =-g-fpic-d_fileline
# MySQL header file
Mysqlinc =/usr/include/mysql
INC =-i-iinclude-i$ (mysqlinc)
# MySQL Library directory
Mysqllib =-l/usr/lib64/mysql-l MYSQLCLIENT-LZ-LM
# Server Destination
SERVEROBJS = src/file1.o src/file2.o src/file3.o
# client Target
CLIENTOBJS = SRC/F1.O SRC/F2.O
# Bin Directory
BINDIR = Bin
# Checkbin Check if the bin directory exists
# Generate Server and Client in bin directory
All:checkbin $ (BINDIR)/server $ (BINDIR)/client
# Build Server
# $^ all. o Files
# [email protected] all. C Files
$ (BINDIR)/server: $ (SERVEROBJS)
$ (CC)-G $ (myslqlib) $^-o [email protected]
# Generate Client
$ (BINDIR)/CLIETN: $ (CLIENTOBJS)
$ (CC)-G $ (mysqllib) $^-o [email protected]
# . Suffixes the connection suffix, connect the. O. cpp. C. cpp.o these files together to compile. A list of types that support file suffixes within the current makefile.
. Suffixes:. C. o CPP
. CPP.O:
$ (CC) $ (cflag) $ (INC)-o [email protected]-C $<
# . Phony pseudo target
. Phony:checkbin
Checkbin:
Test-d "${bindir}" | | mkdir $ (BINDIR)
. Phony:clean
Clean
-rm-f *.O
-rm-f $ (BINDIR)/server
Makefile Example 1