2013/3/21

1.通过在根目录输入make clean all可以看见其整个的make过程:(这里截取的是bacnet-stack-0.7.1版本的主要过程)

截取bacnet-stack-0.7.1\bacnet-stack-0.7.1\demo\server为例,生成bacserv的主要过程为:

a)首先编译各种库文件,可以看见包含了-I../ports/linux -I../demo/object -I../demo/handler -I../include这4个源代码文件,以及编译宏-DPRINT_ENABLED=1 -DBACAPP_ALL -DBACFILE -DINTRINSIC_REPORTING -DBACDL_BIP=1 -DBBMD_ENABLED=1 -DWEAK_FUNC

MARK: gcc编译器中-I表示包含的文件 -D表示预定义功能 -C应该表示遍历子目录 --s  沉默模式, 在执行前不输出相应的命令行信息

make -C lib all
make[1]: Entering directory `/mnt/hgfs/share_Fedora10/Graduation/bacnet-stack-0.7.1/bacnet-stack-0.7.1/lib'
cc -c -Wall -Wmissing-prototypes  -Os  -I../ports/linux -I../demo/object -I../demo/handler -I../include -DPRINT_ENABLED=1 -DBACAPP_ALL -DBACFILE -DINTRINSIC_REPORTING -DBACDL_BIP=1 -DBBMD_ENABLED=1 -DWEAK_FUNC=  ../src/apdu.c -o ../src/apdu.o
cc -c -Wall -Wmissing-prototypes  -Os  -I../ports/linux -I../demo/object -I../demo/handler -I../include -DPRINT_ENABLED=1 -DBACAPP_ALL -DBACFILE -DINTRINSIC_REPORTING -DBACDL_BIP=1 -DBBMD_ENABLED=1 -DWEAK_FUNC=  ../src/npdu.c -o ../src/npdu.o
cc -c -Wall -Wmissing-prototypes  -Os  -I../ports/linux -I../demo/object -I../demo/handler -I../include -DPRINT_ENABLED=1 -DBACAPP_ALL -DBACFILE -DINTRINSIC_REPORTING -DBACDL_BIP=1 -DBBMD_ENABLED=1 -DWEAK_FUNC=  ../src/bacdcode.c -o ../src/bacdcode.o
cc -c -Wall -Wmissing-prototypes  -Os  -I../ports/linux -I../demo/object -I../demo/handler -I../include -DPRINT_ENABLED=1 -DBACAPP_ALL -DBACFILE -DINTRINSIC_REPORTING -DBACDL_BIP=1 -DBBMD_ENABLED=1 -DWEAK_FUNC=  ../src/bacint.c -o ../src/bacint.o
cc -c -Wall -Wmissing-prototypes  -Os  -I../ports/linux -I../demo/object -I../demo/handler -I../include -DPRINT_ENABLED=1 -DBACAPP_ALL -DBACFILE -DINTRINSIC_REPORTING -DBACDL_BIP=1 -DBBMD_ENABLED=1 -DWEAK_FUNC=  ../src/bacreal.c -o ../src/bacreal.o

b)将这些编译好的.o文件打包为lib库

ar rcs libbacnet.a ../src/apdu.o ../src/npdu.o ../src/bacdcode.o ../src/bacint.o ../src/bacreal.o ../src/bacstr.o ../src/bacapp.o ../src/bacprop.o ../src/bactext.o ../src/datetime.o ../src/indtext.o ../src/key.o ../src/keylist.o ../src/proplist.o ../src/debug.o ../src/bigend.o ../src/arf.o ../src/awf.o ../src/cov.o ../src/dcc.o ../src/iam.o ../src/ihave.o ../src/rd.o ../src/rp.o ../src/rpm.o ../src/timesync.o ../src/whohas.o ../src/whois.o ../src/wp.o ../src/wpm.o ../src/abort.o ../src/reject.o ../src/bacerror.o ../src/ptransfer.o ../src/memcopy.o ../src/filename.o ../src/tsm.o ../src/bacaddr.o ../src/address.o ../src/bacdevobjpropref.o ../src/bacpropstates.o ../src/alarm_ack.o ../src/event.o ../src/getevent.o ../src/get_alarm_sum.o ../src/readrange.o ../src/timestamp.o ../src/version.o ../ports/linux/bip-init.o ../src/bvlc.o ../src/bip.o ../demo/handler/dlenv.o ../demo/handler/txbuf.o ../demo/handler/noserv.o ../demo/handler/h_npdu.o ../demo/handler/h_whois.o ../demo/handler/h_iam.o ../demo/handler/h_rp.o ../demo/handler/h_rp_a.o ../demo/handler/h_rpm.o ../demo/handler/h_rpm_a.o ../demo/handler/h_rr.o ../demo/handler/h_wp.o ../demo/handler/h_wpm.o ../demo/handler/h_alarm_ack.o ../demo/handler/h_arf.o ../demo/handler/h_arf_a.o ../demo/handler/h_awf.o ../demo/handler/h_rd.o ../demo/handler/h_dcc.o ../demo/handler/h_ts.o ../demo/handler/h_whohas.o ../demo/handler/h_ihave.o ../demo/handler/h_cov.o ../demo/handler/h_ccov.o ../demo/handler/h_ucov.o ../demo/handler/h_getevent.o ../demo/handler/h_get_alarm_sum.o ../demo/handler/h_pt.o ../demo/handler/h_pt_a.o ../demo/handler/h_upt.o ../demo/handler/s_arfs.o ../demo/handler/s_awfs.o ../demo/handler/s_dcc.o ../demo/handler/s_ihave.o ../demo/handler/s_iam.o ../demo/handler/s_cov.o ../demo/handler/s_ptransfer.o ../demo/handler/s_rd.o ../demo/handler/s_router.o ../demo/handler/s_rp.o ../demo/handler/s_rpm.o ../demo/handler/s_ts.o ../demo/handler/s_cevent.o ../demo/handler/s_uevent.o ../demo/handler/s_whohas.o ../demo/handler/s_whois.o ../demo/handler/s_upt.o ../demo/handler/s_wp.o ../demo/object/device.o ../demo/object/ai.o ../demo/object/ao.o ../demo/object/av.o ../demo/object/bi.o ../demo/object/bo.o ../demo/object/bv.o ../demo/object/csv.o ../demo/object/lc.o ../demo/object/lsp.o ../demo/object/ms-input.o ../demo/object/mso.o ../demo/object/msv.o ../demo/object/nc.o ../demo/object/trendlog.o ../demo/object/bacfile.o

c)进入demo文件夹,依次生成demo下面的各种应用程序:

make -C demo all
make[1]: Entering directory `/mnt/hgfs/share_Fedora10/Graduation/bacnet-stack-0.7.1/bacnet-stack-0.7.1/demo'

d)对应于bacserv的编译过程:

make -b -C  server all
make[2]: Entering directory `/mnt/hgfs/share_Fedora10/Graduation/bacnet-stack-0.7.1/bacnet-stack-0.7.1/demo/server'
cc -c -Wall  -Os -I../../ports/linux -I../../demo/object -I../../demo/handler -I../../include -DPRINT_ENABLED=1 -DBACAPP_ALL -DBACFILE -DINTRINSIC_REPORTING -DBACDL_BIP=1 -DBBMD_ENABLED=1 -DWEAK_FUNC=  main.c -o main.o
cc -pthread main.o -Wl,-lc,-lgcc,-lrt,-lm,-L../../lib,-lbacnet -o bacserv
size bacserv
   text	   data	    bss	    dec	    hex	filename
 135790	   8956	 602068	 746814	  b653e	bacserv
cp bacserv ../../bin
make[2]: Leaving directory `/mnt/hgfs/share_Fedora10/Graduation/bacnet-stack-0.7.1/bacnet-stack-0.7.1/demo/server'

e)这样在bacnet-stack-0.7.1\bacnet-stack-0.7.1\demo\server目录下即生成应用程序bacserv

MARK:关于makefile对文件的编译过程,及其是如何确定哪些文件是需要遍历的

f)对于以上的编译步骤,是如何和port下的文件进行联系的:

     观察bacnet-stack-0.7.1\bacnet-stack-0.7.1\ports\linux目录下文件,发现bip-init.o和rs485.o,说明rs485.c和bip-init.c这两个文件被编译,继而说明调用到这两个文件中的函数,通过函数调用关系,可以发现:

     在dlenv_init中调用了datalink_set,而后者中有如下一句:

void datalink_set(
    char *datalink_string)
{
    /* BEGIN: Added by zhengxiang, 2013/3/22   PN:study_comment */
	/* 忽略大小写比较 */
    if (strcasecmp("bip", datalink_string) == 0) {
        datalink_init = bip_init;
        datalink_send_pdu = bip_send_pdu;
        datalink_receive = bip_receive;
        datalink_cleanup = bip_cleanup;
        datalink_get_broadcast_address = bip_get_broadcast_address;
        datalink_get_my_address = bip_get_my_address;
    }

这里的bip_init即是在bacnet-stack-0.7.1\bacnet-stack-0.7.1\ports\linux此目录下

MARK:关于MAKEFILE的分析
附bacnet-stack-0.8.0\bacnet-stack-0.8.0目录下的makefile:

# Main Makefile for BACnet-stack project with GCC

# tools - only if you need them.
# Most platforms have this already defined
# CC = gcc
# AR = ar
# MAKE = make
# SIZE = size
#
# Assumes rm and cp are available

# configuration
# If BACNET_DEFINES has not already been set, configure to your needs here
MY_BACNET_DEFINES = -DPRINT_ENABLED=1
MY_BACNET_DEFINES += -DBACAPP_ALL
MY_BACNET_DEFINES += -DBACFILE
MY_BACNET_DEFINES += -DINTRINSIC_REPORTING
BACNET_DEFINES ?= $(MY_BACNET_DEFINES)

# un-comment the next line to build the routing demo application
#BACNET_DEFINES += -DBAC_ROUTING

#BACDL_DEFINE=-DBACDL_ETHERNET=1
#BACDL_DEFINE=-DBACDL_ARCNET=1
#BACDL_DEFINE=-DBACDL_MSTP=1
BACDL_DEFINE?=-DBACDL_BIP=1

# Declare your level of BBMD support
BBMD_DEFINE ?=-DBBMD_ENABLED=1
#BBMD_DEFINE ?= -DBBMD_ENABLED=0
#BBMD_DEFINE ?= -DBBMD_CLIENT_ENABLED

# Passing parameters via command line
MAKE_DEFINE ?=

# Define WEAK_FUNC for [...somebody help here; I can't find any uses of it]
DEFINES = $(BACNET_DEFINES) $(BACDL_DEFINE) $(BBMD_DEFINE) -DWEAK_FUNC=
DEFINES += $(MAKE_DEFINE)

# directories
BACNET_PORT ?= linux
BACNET_PORT_DIR = ../ports/${BACNET_PORT}

BACNET_OBJECT = ../demo/object
BACNET_HANDLER = ../demo/handler
BACNET_CORE = ../src
BACNET_INCLUDE = ../include
# compiler configuration
#STANDARDS = -std=c99
INCLUDE1 = -I$(BACNET_PORT_DIR) -I$(BACNET_OBJECT) -I$(BACNET_HANDLER)
INCLUDE2 = -I$(BACNET_INCLUDE)
INCLUDES = $(INCLUDE1) $(INCLUDE2)
OPTIMIZATION = -Os
DEBUGGING =
WARNINGS = -Wall -Wmissing-prototypes

#条件编译为deubg版本:make all BUILD=debug

ifeq (${BUILD},debug)
OPTIMIZATION = -O0
DEBUGGING = -g -DDEBUG_ENABLED=1
ifeq (${BACDL_DEFINE},-DBACDL_BIP=1)
DEFINES += -DBIP_DEBUG
endif
endif
CFLAGS  = $(WARNINGS) $(DEBUGGING) $(OPTIMIZATION) $(STANDARDS) $(INCLUDES) $(DEFINES)

# Export the variables defined here to all subprocesses
# (see http://www.gnu.org/software/automake/manual/make/Special-Targets.html)
.EXPORT_ALL_VARIABLES:

all: library demos
.PHONY : all library demos clean

library:
	$(MAKE) -s -C lib all

demos:
	$(MAKE) -s -C demo all

router:
	$(MAKE) -s -C demo router

# Add "ports" to the build, if desired
ports:	atmega168 bdk-atxx4-mstp at91sam7s
	@echo "Built the ARM7 and AVR ports"

atmega168: ports/atmega168/Makefile
	$(MAKE) -s -C ports/atmega168 clean all

at91sam7s: ports/at91sam7s/makefile
	$(MAKE) -s -C ports/at91sam7s clean all

bdk-atxx4-mstp: ports/bdk-atxx4-mstp/Makefile
	$(MAKE) -s -C ports/bdk-atxx4-mstp clean all

clean:
	$(MAKE) -s -C lib clean
	$(MAKE) -s -C demo clean
	$(MAKE) -s -C demo/router clean


 附bacnet-stack-0.8.0\bacnet-stack-0.8.0\demo\server目录下的makefile:

#Makefile to build BACnet Application for the Linux Port

# tools - only if you need them.
# Most platforms have this already defined
# CC = gcc

# Executable file name
TARGET = bacserv

TARGET_BIN = ${TARGET}$(TARGET_EXT)

SRCS = main.c

OBJS = ${SRCS:.c=.o}

all: ${BACNET_LIB_TARGET} Makefile ${TARGET_BIN}

${TARGET_BIN}: ${OBJS} Makefile ${BACNET_LIB_TARGET}
	${CC} ${PFLAGS} ${OBJS} ${LFLAGS} -o $@
	size $@
	cp $@ ../../bin

lib: ${BACNET_LIB_TARGET}

${BACNET_LIB_TARGET}:
	( cd ${BACNET_LIB_DIR} ; $(MAKE) clean ; $(MAKE) )

.c.o:
	${CC} -c ${CFLAGS} $*.c -o $@

depend:
	rm -f .depend
	${CC} -MM ${CFLAGS} *.c >> .depend

clean:
	rm -f core ${TARGET_BIN} ${OBJS} ${BACNET_LIB_TARGET} $(TARGET).map

include: .depend

makefile的参考资料:

1.关于条件编译debug版本http://www.cnblogs.com/caosiyang/archive/2012/06/13/2548051.html
 

 

Logo

更多推荐