基于以上的学习,下面编写一个基于Hi3520D开发板的程序
工程目录结构如下
.
├── Components
│ ├──Common
│ │ ├── xx_inc.h
│ │ ├── xx_type.h
│ ├──HAL
│ │ ├── Common
│ │ │ ├── xx_inc_hal.h
│ │ ├── Include
│ │ │ ├── xx_alarm_in.h
│ │ │ ├── xx_alarm_out.h
│ │ │ ├── xx_tm7705.h
│ │ ├── Source
│ │ │ ├── xx_alarm_in.c
│ │ │ ├── xx_alarm_out.c
│ │ │ ├── xx_tm7705.c
│ │ └── Makefile
│ ├──MCU
│ │ ├── Common
│ │ │ ├── xx_inc_mcu.h
│ │ ├── Include
│ │ │ ├── hi35xx_gpio.h
│ │ │ ├── xx_uart.h
│ │ ├── Source
│ │ │ ├── hi35xx_gpio.c
│ │ │ ├── xx_uart.c
│ │ └── Makefile
│ ├──Protocal
│ │ ├── Common
│ │ │ ├── xx_inc_ip.h
│ │ ├── Include
│ │ │ ├── gk_protocal.h
│ │ │ ├── xx_crc.h
│ │ │ ├── xx_protocal.h
│ │ ├── Source
│ │ │ ├── gk_protocal.c
│ │ │ ├── xx_crc.c
│ │ │ ├── xx_protocal.c
│ │ └── Makefile
│ ├──Services
│ │ ├── Common
│ │ │ ├── xx_inc_ip.h
│ │ ├── Include
│ │ │ ├── xx_dbug.h
│ │ │ ├── xx_inifile.h
│ │ │ ├── xx_pthread_mutex.h
│ │ │ ├── xx_socket.h
│ │ │ ├── xx_waiter.h
│ │ ├── Source
│ │ │ ├── xx_dbug.c
│ │ │ ├── xx_inifile.c
│ │ │ ├── xx_pthread_mutex.c
│ │ │ ├── xx_socket.c
│ │ │ ├── xx_waiter.c
│ │ └── Makefile
├── Project
│ ├── main.h
│ ├── main.c
│ ├── Makefile(主)
│ ├──Iot_hornet
│ │ ├── iot_intfc.h
│ │ ├── iot_main.h
│ │ ├── iot_intfc.c
│ │ ├── iot_main.c
│ │ └──Makefile
│ ├──wlan_select
│ │ ├── wlan_main.h
│ │ ├── wlan_main.c
│ │ └── Makefile
├── Object(存放所有目标文件(.o文件)的文件夹)
相对来说,子makefiled都是相同,
所做的工作就是把子makefile同目录下的所有文件下的.c源文件全部便宜为相应的.o目标文件,然后把所有的.o文件cp到Object目录下;
#$(shell ls -d */) 命令打印当前目录下的所有文件夹
DIRS := $(shell ls -d*/) ./
FILES := $(foreachdirs, $(DIRS), $(wildcard $(dirs)*.c))
OBJS := $(patsubst%.c, %.o, $(FILES))
all:$(OBJS)$(OBJSDIR)
#$(OBJS):%.o:%.c
# $(CC) -c $< -o $@ $(CFLAGS)
#依赖一个伪目标,这样每次编译时因为ALWAYSMAKE不存在,都会执行命令
$(OBJSDIR):ALWAYSMAKE
cp $(OBJS) $(OBJSDIR)
.PHONY:clean
clean:
$(RM) $(OBJS)
.PHONY:ALWAYSMAKE
ALWAYSMAKE:
export WORKDIR :=$(shell pwd)/..
export OBJSDIR :=$(WORKDIR)/Object
export LIBS :=-lpthread -lmpi -ltde -laec -ljpeg -lanr -lresampler -lVoiceEngine
export MPPLIBS :=-L/opt/Hi3520D_SDK_V1.0.5.0/mpp/lib
export CC :=arm-hisiv100nptl-linux-gcc
#头文件路径
export CFLAGS := \
-I$(WORKDIR)/Components/Common\
-I$(WORKDIR)/Components/HAL/Common\
-I$(WORKDIR)/Components/HAL/Include\
-I$(WORKDIR)/Components/MCU/Common\
-I$(WORKDIR)/Components/MCU/Include\
-I$(WORKDIR)/Components/Protocal/Common\
-I$(WORKDIR)/Components/Protocal/Include\
-I$(WORKDIR)/Components/Services/Common\
-I$(WORKDIR)/Components/Services/Include\
-I$(WORKDIR)/Project/Iot_hornet\
-I$(WORKDIR)/Project/wlan_select\
-I$(WORKDIR)/Project\
-I/opt/Hi3520D_SDK_V1.0.5.0/mpp/include\
-O0 -Wall -g3
RM := rm -f
OBJS := main.o
TARGET := xxproject
$(TARGET):$(OBJS)$(OBJSDIR)
$(MAKE) -C$(WORKDIR)/Components/Protocal/
$(MAKE) -C$(WORKDIR)/Components/Services/
$(MAKE) -C $(WORKDIR)/Components/HAL/
$(MAKE) -C $(WORKDIR)/Components/MCU/
$(MAKE) -C $(WORKDIR)/Project/wlan_select/
$(MAKE) -C$(WORKDIR)/Project/Iot_hornet/
$(CC) $(MPPLIBS) -o $(TARGET)$(OBJSDIR)/*.o $(CFLAGS) $(LIBS)
#$(OBJS):%.o:%.c
# $(CC) -c $< -o $(OBJSDIR)/$@ $(CFLAGS)
#依赖一个伪目标,这样每次编译时因为ALWAYSMAKE不存在,都会执行命令
$(OBJSDIR):ALWAYSMAKE
cp $(OBJS) $(OBJSDIR)
.PHONY:clean
clean:
$(MAKE) clean -C$(WORKDIR)/Components/Protocal/
$(MAKE) clean -C$(WORKDIR)/Components/Services/
$(MAKE) clean -C$(WORKDIR)/Components/HAL/
$(MAKE) clean -C$(WORKDIR)/Components/MCU/
$(MAKE) clean -C $(WORKDIR)/Project/wlan_select/
$(MAKE) clean -C$(WORKDIR)/Project/Iot_hornet/
$(RM) $(OBJS) $(TARGET)
$(RM) $(OBJSDIR)/*.o
.PHONY:ALWAYSMAKE
ALWAYSMAKE: