|
| 1 | +# tnx to mamalala |
| 2 | +# Changelog |
| 3 | +# Changed the variables to include the header file directory |
| 4 | +# Added global var for the XTENSA tool root |
| 5 | +# |
| 6 | +# This make file still needs some work. |
| 7 | +# |
| 8 | +# |
| 9 | +# Output directors to store intermediate compiled files |
| 10 | +# relative to the project directory |
| 11 | +BUILD_BASE = build |
| 12 | +FW_BASE = firmware |
| 13 | + |
| 14 | +# Base directory for the compiler |
| 15 | +#XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin |
| 16 | +XTENSA_TOOLS_ROOT ?= /home/main/esp8266/esp-open-sdk/xtensa-lx106-elf/bin |
| 17 | + |
| 18 | +# base directory of the ESP8266 SDK package, absolute |
| 19 | +#SDK_BASE ?= /opt/Espressif/ESP8266_SDK |
| 20 | +SDK_BASE ?= /home/main/esp8266/esp-open-sdk/sdk |
| 21 | + |
| 22 | +#Esptool.py path and port |
| 23 | +ESPTOOL ?= /home/main/esp8266/esp-open-sdk/esptool/esptool.py |
| 24 | +ESPPORT ?= /dev/ttyUSB0 |
| 25 | + |
| 26 | +# name for the target project |
| 27 | +TARGET = app |
| 28 | + |
| 29 | +# which modules (subdirectories) of the project to include in compiling |
| 30 | +MODULES = driver user softuart |
| 31 | +EXTRA_INCDIR = include /opt/Espressif/include |
| 32 | + |
| 33 | +# libraries used in this project, mainly provided by the SDK |
| 34 | +LIBS = c gcc hal pp phy net80211 lwip wpa main |
| 35 | + |
| 36 | +# compiler flags using during compilation of source files |
| 37 | +CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH |
| 38 | + |
| 39 | +# linker flags used to generate the main object file |
| 40 | +LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static |
| 41 | + |
| 42 | +# linker script used for the above linkier step |
| 43 | +LD_SCRIPT = eagle.app.v6.ld |
| 44 | + |
| 45 | +# various paths from the SDK used in this project |
| 46 | +SDK_LIBDIR = lib |
| 47 | +SDK_LDDIR = ld |
| 48 | +SDK_INCDIR = include include/json |
| 49 | + |
| 50 | +# we create two different files for uploading into the flash |
| 51 | +# these are the names and options to generate them |
| 52 | +FW_FILE_1 = 0x00000 |
| 53 | +FW_FILE_1_ARGS = -bo $@ -bs .text -bs .data -bs .rodata -bc -ec |
| 54 | +FW_FILE_2 = 0x40000 |
| 55 | +FW_FILE_2_ARGS = -es .irom0.text $@ -ec |
| 56 | + |
| 57 | +# select which tools to use as compiler, librarian and linker |
| 58 | +CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc |
| 59 | +AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar |
| 60 | +LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +#### |
| 65 | +#### no user configurable options below here |
| 66 | +#### |
| 67 | +SRC_DIR := $(MODULES) |
| 68 | +BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) |
| 69 | + |
| 70 | +SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR)) |
| 71 | +SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) |
| 72 | + |
| 73 | +SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) |
| 74 | +OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) |
| 75 | +LIBS := $(addprefix -l,$(LIBS)) |
| 76 | +APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) |
| 77 | +TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out) |
| 78 | + |
| 79 | +LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) |
| 80 | + |
| 81 | +INCDIR := $(addprefix -I,$(SRC_DIR)) |
| 82 | +EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) |
| 83 | +MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) |
| 84 | + |
| 85 | +FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin) |
| 86 | +FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin) |
| 87 | + |
| 88 | +V ?= $(VERBOSE) |
| 89 | +ifeq ("$(V)","1") |
| 90 | +Q := |
| 91 | +vecho := @true |
| 92 | +else |
| 93 | +Q := @ |
| 94 | +vecho := @echo |
| 95 | +endif |
| 96 | + |
| 97 | +vpath %.c $(SRC_DIR) |
| 98 | + |
| 99 | +define compile-objects |
| 100 | +$1/%.o: %.c |
| 101 | + $(vecho) "CC $$<" |
| 102 | + $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@ |
| 103 | +endef |
| 104 | + |
| 105 | +.PHONY: all checkdirs flash clean |
| 106 | + |
| 107 | +all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) |
| 108 | + |
| 109 | +$(FW_FILE_1): $(TARGET_OUT) |
| 110 | + $(vecho) "FW $@" |
| 111 | + $(ESPTOOL) elf2image $< -o $(FW_BASE)/ |
| 112 | + |
| 113 | +$(FW_FILE_2): $(TARGET_OUT) |
| 114 | + $(vecho) "FW $@" |
| 115 | + $(ESPTOOL) elf2image $< -o $(FW_BASE)/ |
| 116 | + |
| 117 | +$(TARGET_OUT): $(APP_AR) |
| 118 | + $(vecho) "LD $@" |
| 119 | + $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@ |
| 120 | + |
| 121 | +$(APP_AR): $(OBJ) |
| 122 | + $(vecho) "AR $@" |
| 123 | + $(Q) $(AR) cru $@ $^ |
| 124 | + |
| 125 | +checkdirs: $(BUILD_DIR) $(FW_BASE) |
| 126 | + |
| 127 | +$(BUILD_DIR): |
| 128 | + $(Q) mkdir -p $@ |
| 129 | + |
| 130 | +firmware: |
| 131 | + $(Q) mkdir -p $@ |
| 132 | + |
| 133 | +flash: firmware/0x00000.bin firmware/0x40000.bin |
| 134 | + -$(ESPTOOL) --baud 115200 --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin |
| 135 | + |
| 136 | +clean: |
| 137 | + $(Q) rm -f $(APP_AR) |
| 138 | + $(Q) rm -f $(TARGET_OUT) |
| 139 | + $(Q) rm -rf $(BUILD_DIR) |
| 140 | + $(Q) rm -rf $(BUILD_BASE) |
| 141 | + |
| 142 | + |
| 143 | + $(Q) rm -f $(FW_FILE_1) |
| 144 | + $(Q) rm -f $(FW_FILE_2) |
| 145 | + $(Q) rm -rf $(FW_BASE) |
| 146 | + |
| 147 | +$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir)))) |
0 commit comments