sw: Makefile: support litex build environment
Allow this software package to be built from within the Litex build system. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
6435aec3db
commit
2437e8b5c1
237
sw/Makefile
237
sw/Makefile
@ -1,115 +1,122 @@
|
|||||||
PACKAGE := foboot
|
PACKAGE := foboot
|
||||||
FOMU_SDK ?= .
|
|
||||||
ADD_CFLAGS := -I$(FOMU_SDK)/include -D__vexriscv__ -march=rv32im -mabi=ilp32
|
GIT_VERSION := $(shell git describe --tags)
|
||||||
ADD_LFLAGS :=
|
TRGT ?= riscv64-unknown-elf-
|
||||||
SRC_DIR := src
|
CC := $(TRGT)gcc
|
||||||
|
CXX := $(TRGT)g++
|
||||||
GIT_VERSION := $(shell git describe --tags)
|
OBJCOPY := $(TRGT)objcopy
|
||||||
TRGT ?= riscv64-unknown-elf-
|
|
||||||
CC := $(TRGT)gcc
|
RM := rm -rf
|
||||||
CXX := $(TRGT)g++
|
COPY := cp -a
|
||||||
OBJCOPY := $(TRGT)objcopy
|
PATH_SEP := /
|
||||||
|
|
||||||
RM := rm -rf
|
ifeq ($(OS),Windows_NT)
|
||||||
COPY := cp -a
|
COPY := copy
|
||||||
PATH_SEP := /
|
RM := del
|
||||||
|
PATH_SEP := \\
|
||||||
ifeq ($(OS),Windows_NT)
|
endif
|
||||||
COPY := copy
|
|
||||||
RM := del
|
ifeq ($(LITEX),1)
|
||||||
PATH_SEP := \\
|
BASE_DIR := ../../../../sw
|
||||||
endif
|
LDSCRIPT := $(BASE_DIR)/ld/linker.ld
|
||||||
|
LD_DIR := ../include/generated
|
||||||
LDSCRIPT := $(FOMU_SDK)/ld/linker.ld
|
ADD_CFLAGS := -I../include -I$(BASE_DIR)/include -D__vexriscv__ -march=rv32im -mabi=ilp32
|
||||||
LDSCRIPTS := $(LDSCRIPT) $(FOMU_SDK)/ld/output_format.ld $(FOMU_SDK)/ld/regions.ld
|
ADD_LFLAGS :=
|
||||||
DBG_CFLAGS := -ggdb -g -DDEBUG -Wall
|
else
|
||||||
DBG_LFLAGS := -ggdb -g -Wall
|
BASE_DIR := .
|
||||||
CFLAGS := $(ADD_CFLAGS) \
|
LD_DIR := $(BASE_DIR)/ld
|
||||||
-Wall -Wextra \
|
LDSCRIPT := $(BASE_DIR)/ld/linker.ld
|
||||||
-ffunction-sections -fdata-sections -fno-common \
|
ADD_CFLAGS := -I$(BASE_DIR)/include -D__vexriscv__ -march=rv32im -mabi=ilp32
|
||||||
-fomit-frame-pointer -Os \
|
ADD_LFLAGS :=
|
||||||
-march=rv32i \
|
endif
|
||||||
-DGIT_VERSION=u\"$(GIT_VERSION)\" -std=gnu11
|
|
||||||
CXXFLAGS := $(CFLAGS) -std=c++11 -fno-rtti -fno-exceptions
|
LDSCRIPTS := $(LDSCRIPT) $(LD_DIR)/output_format.ld $(LD_DIR)/regions.ld
|
||||||
LFLAGS := $(CFLAGS) $(ADD_LFLAGS) \
|
SRC_DIR := $(BASE_DIR)/src
|
||||||
-nostartfiles \
|
THIRD_PARTY := $(BASE_DIR)third_party
|
||||||
-nostdlib \
|
DBG_CFLAGS := -ggdb -g -DDEBUG -Wall
|
||||||
-Wl,--gc-sections \
|
DBG_LFLAGS := -ggdb -g -Wall
|
||||||
-Wl,--no-warn-mismatch \
|
CFLAGS := $(ADD_CFLAGS) \
|
||||||
-Wl,--script=$(LDSCRIPT) \
|
-Wall -Wextra \
|
||||||
-Wl,--build-id=none
|
-ffunction-sections -fdata-sections -fno-common \
|
||||||
|
-fomit-frame-pointer -Os \
|
||||||
OBJ_DIR := .obj
|
-march=rv32i \
|
||||||
|
-DGIT_VERSION=u\"$(GIT_VERSION)\" -std=gnu11
|
||||||
CSOURCES := $(wildcard $(SRC_DIR)/*.c) $(wildcard third_party/libbase/*.c) $(wildcard third_party/*.c)
|
CXXFLAGS := $(CFLAGS) -std=c++11 -fno-rtti -fno-exceptions
|
||||||
CPPSOURCES := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard third_party/libbase/*.cpp) $(wildcard third_party/*.cpp)
|
LFLAGS := $(CFLAGS) $(ADD_LFLAGS) -L$(LD_DIR) \
|
||||||
ASOURCES := $(wildcard $(SRC_DIR)/*.S) $(wildcard third_party/libbase/*.S) $(wildcard third_party/*.S)
|
-nostartfiles \
|
||||||
COBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(CSOURCES:.c=.o)))
|
-nostdlib \
|
||||||
CXXOBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(CPPSOURCES:.cpp=.o)))
|
-Wl,--gc-sections \
|
||||||
AOBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(ASOURCES:.S=.o)))
|
-Wl,--no-warn-mismatch \
|
||||||
OBJECTS := $(COBJS) $(CXXOBJS) $(AOBJS)
|
-Wl,--script=$(LDSCRIPT) \
|
||||||
VPATH := $(SRC_DIR) third_party/libbase third_party
|
-Wl,--build-id=none
|
||||||
|
|
||||||
QUIET := @
|
OBJ_DIR := .obj
|
||||||
|
|
||||||
ALL := all
|
CSOURCES := $(wildcard $(SRC_DIR)/*.c) $(wildcard $(THIRD_PARTY)/libbase/*.c) $(wildcard $(THIRD_PARTY)/*.c)
|
||||||
TARGET := $(PACKAGE).elf
|
CPPSOURCES := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(THIRD_PARTY)/libbase/*.cpp) $(wildcard $(THIRD_PARTY)/*.cpp)
|
||||||
CLEAN := clean
|
ASOURCES := $(wildcard $(SRC_DIR)/*.S) $(wildcard $(THIRD_PARTY)/libbase/*.S) $(wildcard $(THIRD_PARTY)/*.S)
|
||||||
|
COBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(CSOURCES:.c=.o)))
|
||||||
$(ALL): $(TARGET) $(PACKAGE).bin $(PACKAGE).ihex
|
CXXOBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(CPPSOURCES:.cpp=.o)))
|
||||||
|
AOBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(ASOURCES:.S=.o)))
|
||||||
$(OBJECTS): | $(OBJ_DIR)
|
OBJECTS := $(COBJS) $(CXXOBJS) $(AOBJS)
|
||||||
|
VPATH := $(SRC_DIR) $(THIRD_PARTY) $(THIRD_PARTY)/libbase
|
||||||
$(TARGET): $(OBJECTS) $(LDSCRIPTS)
|
|
||||||
$(QUIET) echo " LD $@"
|
QUIET := @
|
||||||
$(QUIET) $(CC) $(OBJECTS) $(LFLAGS) -o $@
|
|
||||||
|
ALL := all
|
||||||
$(PACKAGE).bin: $(TARGET)
|
TARGET := $(PACKAGE).elf
|
||||||
$(QUIET) echo " OBJCOPY $@"
|
CLEAN := clean
|
||||||
$(QUIET) $(OBJCOPY) -O binary $(TARGET) $@
|
|
||||||
|
$(ALL): $(TARGET) $(PACKAGE).bin $(PACKAGE).ihex
|
||||||
$(PACKAGE).dfu: $(TARGET)
|
|
||||||
$(QUIET) echo " DFU $@"
|
$(OBJECTS): | $(OBJ_DIR)
|
||||||
$(QUIET) $(COPY) $(PACKAGE).bin $@
|
|
||||||
$(QUIET) dfu-suffix -v 1209 -p 70b1 -a $@
|
$(TARGET): $(OBJECTS) $(LDSCRIPTS)
|
||||||
|
$(QUIET) echo " LD $@"
|
||||||
#$(PACKAGE).bit: $(TARGET)
|
$(QUIET) $(CC) $(OBJECTS) $(LFLAGS) -o $@
|
||||||
# $(QUIET) echo " BIT $@"
|
|
||||||
# # $(QUIET) ice40-repack input/top.bin input/mem_1.init ./foboot.bin ./foboot.bit
|
$(PACKAGE).bin: $(TARGET)
|
||||||
|
$(QUIET) echo " OBJCOPY $@"
|
||||||
$(PACKAGE).ihex: $(TARGET)
|
$(QUIET) $(OBJCOPY) -O binary $(TARGET) $@
|
||||||
$(QUIET) echo " IHEX $(PACKAGE).ihex"
|
|
||||||
$(QUIET) $(OBJCOPY) -O ihex $(TARGET) $@
|
$(PACKAGE).dfu: $(TARGET)
|
||||||
|
$(QUIET) echo " DFU $@"
|
||||||
$(DEBUG): CFLAGS += $(DBG_CFLAGS)
|
$(QUIET) $(COPY) $(PACKAGE).bin $@
|
||||||
$(DEBUG): LFLAGS += $(DBG_LFLAGS)
|
$(QUIET) dfu-suffix -v 1209 -p 70b1 -a $@
|
||||||
CFLAGS += $(DBG_CFLAGS)
|
|
||||||
LFLAGS += $(DBG_LFLAGS)
|
$(PACKAGE).ihex: $(TARGET)
|
||||||
$(DEBUG): $(TARGET)
|
$(QUIET) echo " IHEX $(PACKAGE).ihex"
|
||||||
|
$(QUIET) $(OBJCOPY) -O ihex $(TARGET) $@
|
||||||
$(OBJ_DIR):
|
|
||||||
$(QUIET) mkdir $(OBJ_DIR)
|
$(DEBUG): CFLAGS += $(DBG_CFLAGS)
|
||||||
|
$(DEBUG): LFLAGS += $(DBG_LFLAGS)
|
||||||
$(COBJS) : $(OBJ_DIR)/%.o : %.c Makefile
|
CFLAGS += $(DBG_CFLAGS)
|
||||||
$(QUIET) echo " CC $< $(notdir $@)"
|
LFLAGS += $(DBG_LFLAGS)
|
||||||
$(QUIET) $(CC) -c $< $(CFLAGS) -o $@ -MMD
|
$(DEBUG): $(TARGET)
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: %.cpp
|
$(OBJ_DIR):
|
||||||
$(QUIET) echo " CXX $< $(notdir $@)"
|
$(QUIET) mkdir $(OBJ_DIR)
|
||||||
$(QUIET) $(CXX) -c $< $(CXXFLAGS) -o $@ -MMD
|
|
||||||
|
$(COBJS) : $(OBJ_DIR)/%.o : %.c $(BASE_DIR)/Makefile
|
||||||
$(OBJ_DIR)/%.o: %.S
|
$(QUIET) echo " CC $< $(notdir $@)"
|
||||||
$(QUIET) echo " AS $< $(notdir $@)"
|
$(QUIET) $(CC) -c $< $(CFLAGS) -o $@ -MMD
|
||||||
$(QUIET) $(CC) -x assembler-with-cpp -c $< $(CFLAGS) -o $@ -MMD
|
|
||||||
|
$(OBJ_DIR)/%.o: %.cpp
|
||||||
.PHONY: clean
|
$(QUIET) echo " CXX $< $(notdir $@)"
|
||||||
|
$(QUIET) $(CXX) -c $< $(CXXFLAGS) -o $@ -MMD
|
||||||
clean:
|
|
||||||
$(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))"
|
$(OBJ_DIR)/%.o: %.S
|
||||||
-$(QUIET) $(RM) $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))
|
$(QUIET) echo " AS $< $(notdir $@)"
|
||||||
$(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))"
|
$(QUIET) $(CC) -x assembler-with-cpp -c $< $(CFLAGS) -o $@ -MMD
|
||||||
-$(QUIET) $(RM) $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.o))
|
|
||||||
$(QUIET) echo " RM $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu"
|
.PHONY: clean
|
||||||
-$(QUIET) $(RM) $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu
|
|
||||||
|
clean:
|
||||||
include $(wildcard $(OBJ_DIR)/*.d)
|
$(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))"
|
||||||
|
-$(QUIET) $(RM) $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))
|
||||||
|
$(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))"
|
||||||
|
-$(QUIET) $(RM) $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.o))
|
||||||
|
$(QUIET) echo " RM $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu"
|
||||||
|
-$(QUIET) $(RM) $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu
|
||||||
|
|
||||||
|
include $(wildcard $(OBJ_DIR)/*.d)
|
||||||
|
Loading…
Reference in New Issue
Block a user