主要內(nèi)容
本章我們來(lái)分析SDK中的Makefile,同時(shí)學(xué)習(xí)如何創(chuàng)建自己的源碼文件夾。
預(yù)備知識(shí)
一份代碼工程編譯成二進(jìn)制可執(zhí)行文件催蝗,需要經(jīng)過(guò)四個(gè)步驟:預(yù)處理、編譯育特、匯編和鏈接丙号。
進(jìn)行編譯需要有編譯器,Linux環(huán)境下使用的是gcc缰冤,而對(duì)應(yīng)的犬缨,ESP8266使用的編譯器是xtensa-lx106-elf-gcc。在后面分析Makefile中棉浸,我們就會(huì)看到該編譯器怀薛。
下面是其他一些工具的含義:
- ar:用于建立或修改備存文件,或是從備存文件中抽取文件
- nm:用來(lái)列出目標(biāo)文件的符號(hào)清單
- objcopy:將目標(biāo)文件的一部分或者全部?jī)?nèi)容拷貝到另外一個(gè)目標(biāo)文件中迷郑,或者實(shí)現(xiàn)目標(biāo)文件的格式轉(zhuǎn)換
- objdump:查看目標(biāo)文件或者可執(zhí)行的目標(biāo)文件的構(gòu)成
Makefile分析
首先我們來(lái)看看ESP8266 SDK的目錄結(jié)構(gòu)以及Makefile:
│ License
│ Makefile # 主目錄下的Makefile
├─app/
│ Makefile
├─ driver
└─ user
└─ Makefile
├─bin
├─documents
├─driver_lib
├─examples
├─lib
├─include
├─ld
└─tools
由此可見(jiàn)枝恋,我們至少要分析三個(gè)Makefile:
- 主目錄下的Makefile
- app目錄下的Makefile
-
app/user/
的Makefile
主目錄下的Makefile
下面我們來(lái)hack一下主目錄下的Makefile,詳細(xì)解釋請(qǐng)看注釋:
# copyright (c) 2010 Espressif System
#
ifndef PDIR
endif
############################################
# 編譯工具配置
# ESP8266 主要使用的編譯器是 xtensa-lx106-elf-gcc
ifeq ($(COMPILE), gcc)
AR = xtensa-lx106-elf-ar
CC = xtensa-lx106-elf-gcc
NM = xtensa-lx106-elf-nm
CPP = xtensa-lx106-elf-cpp
OBJCOPY = xtensa-lx106-elf-objcopy
OBJDUMP = xtensa-lx106-elf-objdump
else
AR = xt-ar
CC = xt-xcc
NM = xt-nm
CPP = xt-cpp
OBJCOPY = xt-objcopy
OBJDUMP = xt-objdump
endif
############################################
# 參數(shù)默認(rèn)配置
# =none - 不使用boot
# =old - 使用老版本的boot_v1.1+
# =new - 使用新版本的boot_v1.2+
BOOT?=none
# =0 - 不使用遠(yuǎn)程升級(jí)FOTA
# =1 - 使用FOTA嗡害,生成user1.<flash_map>.<BOOT>.bin
# =2 - 使用FOTA焚碌,生成user2.<flash_map>.<BOOT>.bin
APP?=0
# SPI速率和模式,一般不用改動(dòng)
SPI_SPEED?=40
SPI_MODE?=QIO
# SPI_SIZE_MAP flash映射方式
# 4MB Flash使用 SPI_SIZE_MAP?=4
SPI_SIZE_MAP?=4
############################################
ifeq ($(BOOT), new)
boot = new
else
ifeq ($(BOOT), old)
boot = old
else
boot = none
endif
endif
ifeq ($(APP), 1)
app = 1
else
ifeq ($(APP), 2)
app = 2
else
app = 0
endif
endif
ifeq ($(SPI_SPEED), 26.7)
freqdiv = 1
else
ifeq ($(SPI_SPEED), 20)
freqdiv = 2
else
ifeq ($(SPI_SPEED), 80)
freqdiv = 15
else
freqdiv = 0
endif
endif
endif
ifeq ($(SPI_MODE), QOUT)
mode = 1
else
ifeq ($(SPI_MODE), DIO)
mode = 2
else
ifeq ($(SPI_MODE), DOUT)
mode = 3
else
mode = 0
endif
endif
endif
addr = 0x01000
ifeq ($(SPI_SIZE_MAP), 1)
size_map = 1
flash = 256
else
ifeq ($(SPI_SIZE_MAP), 2)
size_map = 2
flash = 1024
ifeq ($(app), 2)
addr = 0x81000
endif
else
ifeq ($(SPI_SIZE_MAP), 3)
size_map = 3
flash = 2048
ifeq ($(app), 2)
addr = 0x81000
endif
else
ifeq ($(SPI_SIZE_MAP), 4)
size_map = 4
flash = 4096
ifeq ($(app), 2)
addr = 0x81000
endif
else
ifeq ($(SPI_SIZE_MAP), 5)
size_map = 5
flash = 2048
ifeq ($(app), 2)
addr = 0x101000
endif
else
ifeq ($(SPI_SIZE_MAP), 6)
size_map = 6
flash = 4096
ifeq ($(app), 2)
addr = 0x101000
endif
else
size_map = 0
flash = 512
ifeq ($(app), 2)
addr = 0x41000
endif
endif
endif
endif
endif
endif
endif
############################################
# 選擇鏈接工具
# 這里選擇了主目錄下的 ld/eagle.app.v6.ld
LD_FILE = $(LDDIR)/eagle.app.v6.ld
# 如果boot!=none霸妹,才進(jìn)入這里
ifneq ($(boot), none)
ifneq ($(app),0)
ifeq ($(size_map), 6)
LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).2048.ld
else
ifeq ($(size_map), 5)
LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).2048.ld
else
ifeq ($(size_map), 4)
LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).1024.app$(app).ld
else
ifeq ($(size_map), 3)
LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).1024.app$(app).ld
else
ifeq ($(size_map), 2)
LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).1024.app$(app).ld
else
ifeq ($(size_map), 0)
LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).512.app$(app).ld
endif
endif
endif
endif
endif
endif
BIN_NAME = user$(app).$(flash).$(boot).$(size_map)
endif
else
app = 0
endif
############################################
CSRCS ?= $(wildcard *.c)
ASRCs ?= $(wildcard *.s)
ASRCS ?= $(wildcard *.S)
SUBDIRS ?= $(patsubst %/,%,$(dir $(wildcard */Makefile)))
ODIR := .output
OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj
# 設(shè)置 OBJS 變量
OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \
$(ASRCs:%.s=$(OBJODIR)/%.o) \
$(ASRCS:%.S=$(OBJODIR)/%.o)
# 設(shè)置 DEPS 變量
DEPS := $(CSRCS:%.c=$(OBJODIR)/%.d) \
$(ASRCs:%.s=$(OBJODIR)/%.d) \
$(ASRCS:%.S=$(OBJODIR)/%.d)
# 設(shè)置 LIBODIR 庫(kù)文件夾
LIBODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/lib
OLIBS := $(GEN_LIBS:%=$(LIBODIR)/%)
IMAGEODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/image
OIMAGES := $(GEN_IMAGES:%=$(IMAGEODIR)/%)
# 設(shè)置 BINODIR 二進(jìn)制文件夾
BINODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/bin
OBINS := $(GEN_BINS:%=$(BINODIR)/%)
#############################################################
CCFLAGS += \
-g \
-Wpointer-arith \
-Wundef \
-Werror \
-Wl,-EL \
-fno-inline-functions \
-nostdlib \
-mlongcalls \
-mtext-section-literals \
-ffunction-sections \
-fdata-sections \
-fno-builtin-printf
# -Wall
CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(INCLUDES)
DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(INCLUDES)
#############################################################
# Functions
#
define ShortcutRule
$(1): .subdirs $(2)/$(1)
endef
define MakeLibrary
DEP_LIBS_$(1) = $$(foreach lib,$$(filter %.a,$$(COMPONENTS_$(1))),$$(dir $$(lib))$$(LIBODIR)/$$(notdir $$(lib)))
DEP_OBJS_$(1) = $$(foreach obj,$$(filter %.o,$$(COMPONENTS_$(1))),$$(dir $$(obj))$$(OBJODIR)/$$(notdir $$(obj)))
$$(LIBODIR)/$(1).a: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_$(1))
@mkdir -p $$(LIBODIR)
$$(if $$(filter %.a,$$?),mkdir -p $$(EXTRACT_DIR)_$(1))
$$(if $$(filter %.a,$$?),cd $$(EXTRACT_DIR)_$(1); $$(foreach lib,$$(filter %.a,$$?),$$(AR) xo $$(UP_EXTRACT_DIR)/$$(lib);))
$$(AR) ru $$@ $$(filter %.o,$$?) $$(if $$(filter %.a,$$?),$$(EXTRACT_DIR)_$(1)/*.o)
$$(if $$(filter %.a,$$?),$$(RM) -r $$(EXTRACT_DIR)_$(1))
endef
define MakeImage
DEP_LIBS_$(1) = $$(foreach lib,$$(filter %.a,$$(COMPONENTS_$(1))),$$(dir $$(lib))$$(LIBODIR)/$$(notdir $$(lib)))
DEP_OBJS_$(1) = $$(foreach obj,$$(filter %.o,$$(COMPONENTS_$(1))),$$(dir $$(obj))$$(OBJODIR)/$$(notdir $$(obj)))
$$(IMAGEODIR)/$(1).out: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_$(1))
@mkdir -p $$(IMAGEODIR)
$$(CC) $$(LDFLAGS) $$(if $$(LINKFLAGS_$(1)),$$(LINKFLAGS_$(1)),$$(LINKFLAGS_DEFAULT) $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1))) -o $$@
endef
$(BINODIR)/%.bin: $(IMAGEODIR)/%.out
@mkdir -p $(BINODIR)
ifeq ($(APP), 0)
@$(RM) -r ../bin/eagle.S ../bin/eagle.dump
@$(OBJDUMP) -x -s $< > ../bin/eagle.dump
@$(OBJDUMP) -S $< > ../bin/eagle.S
else
mkdir -p ../bin/upgrade
@$(RM) -r ../bin/upgrade/$(BIN_NAME).S ../bin/upgrade/$(BIN_NAME).dump
@$(OBJDUMP) -x -s $< > ../bin/upgrade/$(BIN_NAME).dump
@$(OBJDUMP) -S $< > ../bin/upgrade/$(BIN_NAME).S
endif
@$(OBJCOPY) --only-section .text -O binary $< eagle.app.v6.text.bin
@$(OBJCOPY) --only-section .data -O binary $< eagle.app.v6.data.bin
@$(OBJCOPY) --only-section .rodata -O binary $< eagle.app.v6.rodata.bin
@$(OBJCOPY) --only-section .irom0.text -O binary $< eagle.app.v6.irom0text.bin
@echo ""
@echo "!!!"
# 默認(rèn)是 app==0
# 下面是輸出打印信息
ifeq ($(app), 0)
@python ../tools/gen_appbin.py $< 0 $(mode) $(freqdiv) $(size_map) $(app)
@mv eagle.app.flash.bin ../bin/eagle.flash.bin
@mv eagle.app.v6.irom0text.bin ../bin/eagle.irom0text.bin
@rm eagle.app.v6.*
@echo "No boot needed."
@echo "Generate eagle.flash.bin and eagle.irom0text.bin successully in folder bin."
@echo "eagle.flash.bin-------->0x00000"
@echo "eagle.irom0text.bin---->0x10000"
else
ifneq ($(boot), new)
@python ../tools/gen_appbin.py $< 1 $(mode) $(freqdiv) $(size_map) $(app)
@echo "Support boot_v1.1 and +"
else
@python ../tools/gen_appbin.py $< 2 $(mode) $(freqdiv) $(size_map) $(app)
ifeq ($(size_map), 6)
@echo "Support boot_v1.4 and +"
else
ifeq ($(size_map), 5)
@echo "Support boot_v1.4 and +"
else
@echo "Support boot_v1.2 and +"
endif
endif
endif
@mv eagle.app.flash.bin ../bin/upgrade/$(BIN_NAME).bin
@rm eagle.app.v6.*
@echo "Generate $(BIN_NAME).bin successully in folder bin/upgrade."
@echo "boot.bin------------>0x00000"
@echo "$(BIN_NAME).bin--->$(addr)"
endif
@echo "!!!"
#############################################################
# Rules base
# Should be done in top-level makefile only
#
############################################
# make all執(zhí)行的方法
all: .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)
############################################
# make clean執(zhí)行的方法
clean:
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;)
$(RM) -r $(ODIR)/$(TARGET)/$(FLAVOR)
clobber: $(SPECIAL_CLOBBER)
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clobber;)
$(RM) -r $(ODIR)
.subdirs:
@set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);)
#.subdirs:
# $(foreach d, $(SUBDIRS), $(MAKE) -C $(d))
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),clobber)
ifdef DEPS
sinclude $(DEPS)
endif
endif
endif
# “$<”表示所有的依賴目標(biāo)集(所有.c后綴文件)十电,“$@”表示目標(biāo)集(所有.o后綴文件)
$(OBJODIR)/%.o: %.c
@mkdir -p $(OBJODIR);
$(CC) $(if $(findstring $<,$(DSRCS)),$(DFLAGS),$(CFLAGS)) $(COPTS_$(*F)) -o $@ -c $<
$(OBJODIR)/%.d: %.c
@mkdir -p $(OBJODIR);
@echo DEPEND: $(CC) -M $(CFLAGS) $<
@set -e; rm -f $@; \
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
$(OBJODIR)/%.o: %.s
@mkdir -p $(OBJODIR);
$(CC) $(CFLAGS) -o $@ -c $<
$(OBJODIR)/%.d: %.s
@mkdir -p $(OBJODIR); \
set -e; rm -f $@; \
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
$(OBJODIR)/%.o: %.S
@mkdir -p $(OBJODIR);
$(CC) $(CFLAGS) -D__ASSEMBLER__ -o $@ -c $<
$(OBJODIR)/%.d: %.S
@mkdir -p $(OBJODIR); \
set -e; rm -f $@; \
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
$(foreach lib,$(GEN_LIBS),$(eval $(call ShortcutRule,$(lib),$(LIBODIR))))
$(foreach image,$(GEN_IMAGES),$(eval $(call ShortcutRule,$(image),$(IMAGEODIR))))
$(foreach bin,$(GEN_BINS),$(eval $(call ShortcutRule,$(bin),$(BINODIR))))
$(foreach lib,$(GEN_LIBS),$(eval $(call MakeLibrary,$(basename $(lib)))))
$(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image)))))
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
############################################
# 設(shè)置頭文件路徑
# 把主目錄下的 include頭文件包含進(jìn)來(lái)
INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/$(TARGET) -I $(PDIR)driver_lib/include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
app下的Makefile
下面我們就來(lái)hack一下app/Makefile
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of object file images to be generated ()
# GEN_BINS - list of binaries to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
#############################################################
TARGET = eagle
#############################################################
# 選擇debug工程還是release
#FLAVOR = release
FLAVOR = debug
#EXTRA_CCFLAGS += -u
ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin
SPECIAL_MKTARGETS=$(APP_MKTARGETS)
#############################################################
# 子目錄,如果你在app里新建了一個(gè)源文件目錄叹螟,需要添加到這里
# 否則不會(huì)編譯未添加的目錄的源文件鹃骂!
SUBDIRS= \
user \
driver
# 比如添加了一個(gè) network 文件夾,則:
#SUBDIRS= \
# user \
# driver \
# network
endif # } PDIR
APPDIR = .
LDDIR = ../ld
CCFLAGS += -Os
TARGET_LDFLAGS = \
-nostdlib \
-Wl,-EL \
--longcalls \
--text-section-literals
#############################################################
# 根據(jù) FLAVOR 變量選擇優(yōu)化等級(jí)
# -O0不優(yōu)化罢绽,-O2中級(jí)優(yōu)化
ifeq ($(FLAVOR),debug)
TARGET_LDFLAGS += -g -O2
endif
ifeq ($(FLAVOR),release)
TARGET_LDFLAGS += -g -O0
endif
#############################################################
# 添加靜態(tài)鏈接庫(kù)畏线,對(duì)應(yīng)前面 SUBDIRS 變量設(shè)置的目錄
# 每一個(gè)文件夾里的源代碼先編譯成對(duì)應(yīng)的靜態(tài)庫(kù),然后在進(jìn)行鏈接
# 所以如果添加新的源碼文件夾良价,也需要在這里添加對(duì)應(yīng)的靜態(tài)庫(kù)寝殴!
COMPONENTS_eagle.app.v6 = \
user/libuser.a \
driver/libdriver.a
# 比如添加network:
#COMPONENTS_eagle.app.v6 = \
# user/libuser.a \
# driver/libdriver.a \
# network/libnetwork.a
#############################################################
# 鏈接參數(shù)
# 參考lib文件夾里的靜態(tài)鏈接庫(kù)
# 比如蒿叠,如果需要使用smartconfig接口
# 只需要添加 -lsmartconfig 即可。
LINKFLAGS_eagle.app.v6 = \
-L../lib \
-nostdlib \
-T$(LD_FILE) \
-Wl,--no-check-sections \
-Wl,--gc-sections \
-u call_user_start \
-Wl,-static \
-Wl,--start-group \
-lc \
-lgcc \
-lhal \
-lphy \
-lpp \
-lnet80211 \
-llwip \ # lwip靜態(tài)庫(kù)杯矩,可見(jiàn)ESP8266使用的是lwip協(xié)議棧
-lwpa \
-lcrypto \
-lmain \ # main靜態(tài)庫(kù)
-ljson \ # JSON靜態(tài)庫(kù)
-lupgrade \ # OTP在線升級(jí)相關(guān)庫(kù)
-lssl \ # 安全鏈接SSL靜態(tài)庫(kù)
-lpwm \ # 有關(guān)PWM的靜態(tài)庫(kù)
-lsmartconfig \ # 快速連接smartconfig
$(DEP_LIBS_eagle.app.v6)\
-Wl,--end-group
DEPENDS_eagle.app.v6 = \
$(LD_FILE) \
$(LDDIR)/eagle.rom.addr.v6.ld
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#UNIVERSAL_TARGET_DEFINES = \
# Other potential configuration flags include:
# -DTXRX_TXBUF_DEBUG
# -DTXRX_RXBUF_DEBUG
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -DICACHE_FLASH
DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
DDEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
#############################################################
# 把當(dāng)前目錄下的 include 文件夾包含進(jìn)來(lái)
INCLUDES := $(INCLUDES) -I $(PDIR)include
# 把子目錄包含進(jìn)來(lái)
PDIR := ../$(PDIR)
# 把子目錄下的Makefile加進(jìn)來(lái)
# sinclude:以忽略錯(cuò)誤的方式執(zhí)行
sinclude $(PDIR)Makefile
.PHONY: FORCE
FORCE:
app/user/
下的Makefile
由app/Makefile
可知栈虚,Makefile最后會(huì)把子目錄下的Makefile加進(jìn)來(lái)袖外,而且好像還添加了user/libuser.a
和driver/libdriver.a
史隆,但是這些.a
文件怎么生成我們還不知道。
所以我們來(lái)看下app/user/
下的Makefile做了一些什么事情曼验。
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
# 仔細(xì)閱讀上面英文即可知道是什么意思了
# 下面語(yǔ)句即是生成 libuser.a
ifndef PDIR
GEN_LIBS = libuser.a
endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
# 查找頭文件時(shí)泌射,進(jìn)入當(dāng)前文件夾的 include 文件夾進(jìn)行查找(如果有)
INCLUDES := $(INCLUDES) -I $(PDIR)include
# 在當(dāng)前文件夾的進(jìn)行查找
INCLUDES += -I ./
# 在主目錄下的 include/ets/ 文件夾進(jìn)行查找
# (實(shí)際上本人都沒(méi)有找到 include/ets/ 文件夾)
INCLUDES += -I ../../include/ets
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
如何新添源碼文件夾
- 在
app/
目錄下新建一個(gè)文件夾,比如叫network
鬓照; - 然后把
app/user/Makefile
文件拷貝過(guò)去熔酷,修改下面語(yǔ)句:
改為:ifndef PDIR GEN_LIBS = libuser.a endif
ifndef PDIR GEN_LIBS = libnetwork.a endif
- 然后打開(kāi)
app/Makefile
,給SUBDIRS
變量和COMPONENTS_eagle.app.v6
添加對(duì)應(yīng)的文件即可(app/Makefile
代碼分析小節(jié)已經(jīng)有說(shuō)明)豺裆; - 最后編譯的時(shí)候拒秘,
network
文件夾下的源碼即會(huì)被編譯進(jìn)來(lái)了。
參考資料
打廣告時(shí)間~下面是本人做ESP8266項(xiàng)目收集的各種示例工程臭猜,已經(jīng)放在Github:https://github.com/AngelLiang/ESP8266-Demos