ESP8266 SDK學習筆記(四):Makefile分析

主要內容

本章我們來分析SDK中的Makefile,同時學習如何創建自己的源碼文件夾。

預備知識

一份代碼工程編譯成二進制可執行文件,需要經過四個步驟:預處理、編譯、彙編和鏈接。

進行編譯需要有編譯器,Linux環境下使用的是gcc,而對應的,ESP8266使用的編譯器是xtensa-lx106-elf-gcc。在後面分析Makefile中,我們就會看到該編譯器。

下面是其他一些工具的含義:

  • ar:用於建立或修改備存文件,或是從備存文件中抽取文件
  • nm:用來列出目標文件的符號清單
  • objcopy:將目標文件的一部分或者全部內容拷貝到另外一個目標文件中,或者實現目標文件的格式轉換
  • objdump:查看目標文件或者可執行的目標文件的構成

Makefile分析

首先我們來看看ESP8266 SDK的目錄結構以及Makefile:

LicenseMakefile # 主目錄下的Makefile
├─app/
│   │  Makefile
│   ├─ driver
│   └─ user
│       └─ Makefile
├─bin
├─documents
├─driver_lib  
├─examples
├─lib
├─include    
├─ld
└─tools

由此可見,我們至少要分析三個Makefile:

  • 主目錄下的Makefile
  • app目錄下的Makefile
  • app/user/的Makefile

主目錄下的Makefile

下面我們來hack一下主目錄下的Makefile,詳細解釋請看註釋:

#  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

############################################
# 參數默認配置

# =none - 不使用boot
# =old - 使用老版本的boot_v1.1+
# =new - 使用新版本的boot_v1.2+
BOOT?=none

# =0 - 不使用遠程升級FOTA
# =1 - 使用FOTA,生成user1.<flash_map>.<BOOT>.bin
# =2 - 使用FOTA,生成user2.<flash_map>.<BOOT>.bin
APP?=0

# SPI速率和模式,一般不用改動
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,才進入這裏
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

# 設置 OBJS 變量
OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \
        $(ASRCs:%.s=$(OBJODIR)/%.o) \
        $(ASRCS:%.S=$(OBJODIR)/%.o)

# 設置 DEPS 變量
DEPS := $(CSRCS:%.c=$(OBJODIR)/%.d) \
        $(ASRCs:%.s=$(OBJODIR)/%.d) \
        $(ASRCS:%.S=$(OBJODIR)/%.d)

# 設置 LIBODIR 庫文件夾
LIBODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/lib
OLIBS := $(GEN_LIBS:%=$(LIBODIR)/%)

IMAGEODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/image
OIMAGES := $(GEN_IMAGES:%=$(IMAGEODIR)/%)

# 設置 BINODIR 二進制文件夾
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 "!!!"

# 默認是 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執行的方法
all:    .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)

############################################
# make clean執行的方法
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

# “$<”表示所有的依賴目標集(所有.c後綴文件),“$@”表示目標集(所有.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
#

############################################
# 設置頭文件路徑
# 把主目錄下的 include頭文件包含進來
INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/$(TARGET) -I $(PDIR)driver_lib/include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

app下的Makefile

下面我們就來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裏新建了一個源文件目錄,需要添加到這裏
# 否則不會編譯未添加的目錄的源文件!
SUBDIRS=    \
    user    \
    driver

# 比如添加了一個 network 文件夾,則:
#SUBDIRS=    \
#   user    \
#   driver  \
#   network

endif # } PDIR

APPDIR = .
LDDIR = ../ld

CCFLAGS += -Os

TARGET_LDFLAGS =    \
    -nostdlib       \
    -Wl,-EL         \
    --longcalls     \
    --text-section-literals

#############################################################
# 根據 FLAVOR 變量選擇優化等級
# -O0不優化,-O2中級優化
ifeq ($(FLAVOR),debug)
    TARGET_LDFLAGS += -g -O2
endif

ifeq ($(FLAVOR),release)
    TARGET_LDFLAGS += -g -O0
endif

#############################################################
# 添加靜態鏈接庫,對應前面 SUBDIRS 變量設置的目錄
# 每一個文件夾裏的源代碼先編譯成對應的靜態庫,然後在進行鏈接
# 所以如果添加新的源碼文件夾,也需要在這裏添加對應的靜態庫!
COMPONENTS_eagle.app.v6 =   \
    user/libuser.a          \
    driver/libdriver.a

# 比如添加network:
#COMPONENTS_eagle.app.v6 =   \
#   user/libuser.a          \
#   driver/libdriver.a  \
#   network/libnetwork.a


#############################################################
# 鏈接參數
# 參考lib文件夾裏的靜態鏈接庫
# 比如,如果需要使用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靜態庫,可見ESP8266使用的是lwip協議棧
    -lwpa                   \
    -lcrypto                \
    -lmain                  \ # main靜態庫
    -ljson                  \ # JSON靜態庫
    -lupgrade               \ # OTP在線升級相關庫
    -lssl                   \ # 安全鏈接SSL靜態庫
    -lpwm                   \ # 有關PWM的靜態庫
    -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
#

#############################################################
# 把當前目錄下的 include 文件夾包含進來
INCLUDES := $(INCLUDES) -I $(PDIR)include

# 把子目錄包含進來
PDIR := ../$(PDIR)

# 把子目錄下的Makefile加進來
# sinclude:以忽略錯誤的方式執行
sinclude $(PDIR)Makefile

.PHONY: FORCE
FORCE:

app/user/下的Makefile

app/Makefile可知,Makefile最後會把子目錄下的Makefile加進來,而且好像還添加了user/libuser.adriver/libdriver.a,但是這些.a文件怎麼生成我們還不知道。

所以我們來看下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 ()
#

# 仔細閱讀上面英文即可知道是什麼意思了
# 下面語句即是生成 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
#

# 查找頭文件時,進入當前文件夾的 include 文件夾進行查找(如果有)
INCLUDES := $(INCLUDES) -I $(PDIR)include

# 在當前文件夾的進行查找
INCLUDES += -I ./

# 在主目錄下的 include/ets/ 文件夾進行查找
# (實際上本人都沒有找到 include/ets/ 文件夾)
INCLUDES += -I ../../include/ets

PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

如何新添源碼文件夾

  1. app/目錄下新建一個文件夾,比如叫network
  2. 然後把app/user/Makefile文件拷貝過去,修改下面語句:

    ifndef PDIR
    GEN_LIBS = libuser.a
    endif

    改爲:

    ifndef PDIR
    GEN_LIBS = libnetwork.a
    endif
  3. 然後編輯app/Makefile,給SUBDIRS變量和COMPONENTS_eagle.app.v6添加對應的文件名稱即可(app/Makefile代碼分析小節已經有說明);

    
    # ...
    
    
    SUBDIRS=    \
        user    \
        driver
    
    
    # ...
    
    
    COMPONENTS_eagle.app.v6 =   \
    user/libuser.a          \
    driver/libdriver.a
    

    添加network:

    
    # ...
    
    
    SUBDIRS=    \
       user    \
       driver  \
       network
    
    
    # ...
    
    
    COMPONENTS_eagle.app.v6 =   \
       user/libuser.a          \
       driver/libdriver.a  \
       network/libnetwork.a
  4. 最後編譯的時候,network文件夾下的源碼即會被編譯進來了。

參考資料


打廣告時間~下面是本人做ESP8266項目收集的各種示例工程,已經放在Github:https://github.com/AngelLiang/ESP8266-Demos

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章