2016-10-16 17:47:07 +02:00
|
|
|
############################################################################
|
|
|
|
# arch/risc-v/src/Makefile
|
|
|
|
#
|
2021-04-10 08:50:57 +02:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership. The
|
|
|
|
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance with the
|
|
|
|
# License. You may obtain a copy of the License at
|
2016-10-16 17:47:07 +02:00
|
|
|
#
|
2021-04-10 08:50:57 +02:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2016-10-16 17:47:07 +02:00
|
|
|
#
|
2021-04-10 08:50:57 +02:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2016-10-16 17:47:07 +02:00
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
2024-02-28 08:29:35 +01:00
|
|
|
include $(TOPDIR)/tools/apps-or-nuttx-Make.defs
|
2021-07-21 18:48:05 +02:00
|
|
|
include chip/Make.defs
|
2021-12-20 13:20:47 +01:00
|
|
|
ifeq ($(CONFIG_OPENSBI),y)
|
|
|
|
include opensbi/Make.defs
|
2022-04-11 12:46:41 +02:00
|
|
|
else ifeq ($(CONFIG_NUTTSBI),y)
|
|
|
|
include nuttsbi/Make.defs
|
2021-12-20 13:20:47 +01:00
|
|
|
endif
|
2016-10-16 17:47:07 +02:00
|
|
|
|
2020-05-19 11:43:29 +02:00
|
|
|
ARCH_SRCDIR = $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src
|
|
|
|
|
2022-11-01 14:47:53 +01:00
|
|
|
INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)chip
|
|
|
|
INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)common
|
|
|
|
INCLUDES += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)sched
|
2020-05-19 11:43:29 +02:00
|
|
|
|
2020-09-14 00:14:28 +02:00
|
|
|
CPPFLAGS += $(INCLUDES)
|
|
|
|
CFLAGS += $(INCLUDES)
|
|
|
|
CXXFLAGS += $(INCLUDES)
|
|
|
|
AFLAGS += $(INCLUDES)
|
2020-05-19 11:43:29 +02:00
|
|
|
|
2022-02-20 03:34:50 +01:00
|
|
|
NUTTX = $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx$(EXEEXT))
|
2016-10-16 17:47:07 +02:00
|
|
|
|
2020-07-22 15:21:42 +02:00
|
|
|
# Additional rules for system call wrapper
|
|
|
|
|
|
|
|
ifeq ($(CONFIG_SCHED_INSTRUMENTATION_SYSCALL),y)
|
|
|
|
EXTRALINKCMDS += @$(TOPDIR)/syscall/syscall_wraps.ldcmd
|
|
|
|
endif
|
|
|
|
|
2016-10-16 17:47:07 +02:00
|
|
|
# The "head" object
|
|
|
|
|
|
|
|
HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT))
|
|
|
|
STARTUP_OBJS ?= $(HEAD_OBJ)
|
|
|
|
|
|
|
|
# Flat build or kernel-mode objects
|
|
|
|
|
2022-05-18 09:10:49 +02:00
|
|
|
ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS) $(SBI_ASRCS)
|
2016-10-16 17:47:07 +02:00
|
|
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
|
|
|
2022-05-18 09:10:49 +02:00
|
|
|
CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS) $(SBI_CSRCS)
|
2016-10-16 17:47:07 +02:00
|
|
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
|
|
|
|
|
|
SRCS = $(ASRCS) $(CSRCS)
|
|
|
|
OBJS = $(AOBJS) $(COBJS)
|
|
|
|
|
|
|
|
# User-mode objects
|
|
|
|
|
|
|
|
UASRCS = $(CHIP_UASRCS) $(CMN_UASRCS)
|
|
|
|
UAOBJS = $(UASRCS:.S=$(OBJEXT))
|
|
|
|
|
|
|
|
UCSRCS = $(CHIP_UCSRCS) $(CMN_UCSRCS)
|
|
|
|
UCOBJS = $(UCSRCS:.c=$(OBJEXT))
|
|
|
|
|
|
|
|
USRCS = $(UASRCS) $(UCSRCS)
|
|
|
|
UOBJS = $(UAOBJS) $(UCOBJS)
|
|
|
|
|
|
|
|
KBIN = libkarch$(LIBEXT)
|
|
|
|
BIN = libarch$(LIBEXT)
|
|
|
|
|
2022-10-16 16:59:58 +02:00
|
|
|
$(foreach lib,$(notdir $(wildcard $(APPDIR)$(DELIM)staging$(DELIM)*$(LIBEXT))), \
|
|
|
|
$(foreach elib,$(EXTRA_LIBS), \
|
|
|
|
$(if $(filter $(notdir $(elib)),$(lib)), \
|
|
|
|
$(eval NAMEFULL_LIBS+=$(elib)), \
|
|
|
|
$(if $(filter $(notdir $(elib)),$(patsubst lib%$(LIBEXT),-l%,$(lib))), \
|
|
|
|
$(eval NAMESPEC_LIBS+=$(elib)) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
) \
|
|
|
|
)
|
|
|
|
|
|
|
|
EXTRA_LIBS := $(filter-out $(NAMEFULL_LIBS) $(NAMESPEC_LIBS),$(EXTRA_LIBS))
|
|
|
|
EXTRA_LIBS += $(wildcard $(APPDIR)$(DELIM)staging$(DELIM)*$(LIBEXT))
|
|
|
|
|
2022-09-28 10:32:02 +02:00
|
|
|
ARCHSCRIPT := $(call CONVERT_PATH,$(ARCHSCRIPT))
|
2022-11-01 21:12:15 +01:00
|
|
|
LDFLAGS += $(addprefix -T,$(addsuffix .tmp,$(ARCHSCRIPT))) $(EXTRALINKCMDS)
|
2016-10-16 17:47:07 +02:00
|
|
|
|
2022-04-22 08:38:49 +02:00
|
|
|
ifeq ($(LD),$(CC))
|
2023-07-20 11:07:55 +02:00
|
|
|
ifeq ($(CONFIG_STACK_CANARIES),y)
|
|
|
|
# filter out ssp(Stack Smashing Protector) related flags:
|
|
|
|
# -fstack-protector
|
|
|
|
# -fstack-protector-all
|
|
|
|
# -fstack-protector-strong
|
|
|
|
# -fstack-protector-explicit
|
|
|
|
STRIPCFLAGS = $(filter -fstack-protector%,$(CFLAGS))
|
|
|
|
endif
|
2024-04-18 08:01:18 +02:00
|
|
|
LDENTRY ?= -Wl,--entry=__start
|
2022-04-22 08:38:49 +02:00
|
|
|
LDSTARTGROUP ?= -Wl,--start-group
|
|
|
|
LDENDGROUP ?= -Wl,--end-group
|
|
|
|
LDFLAGS := $(addprefix -Xlinker ,$(LDFLAGS))
|
2023-07-20 11:07:55 +02:00
|
|
|
LDFLAGS += $(filter-out $(STRIPCFLAGS),$(CFLAGS))
|
2022-04-22 08:38:49 +02:00
|
|
|
else
|
2024-04-18 08:01:18 +02:00
|
|
|
LDENTRY ?= --entry=__start
|
2022-04-22 08:38:49 +02:00
|
|
|
LDSTARTGROUP ?= --start-group
|
|
|
|
LDENDGROUP ?= --end-group
|
|
|
|
endif
|
2020-03-31 13:43:31 +02:00
|
|
|
|
2020-05-19 11:43:29 +02:00
|
|
|
BOARDMAKE = $(if $(wildcard board$(DELIM)Makefile),y,)
|
2016-10-16 17:47:07 +02:00
|
|
|
|
2022-02-20 03:34:50 +01:00
|
|
|
LIBPATHS += -L $(call CONVERT_PATH,$(TOPDIR)$(DELIM)staging)
|
2016-10-16 17:47:07 +02:00
|
|
|
ifeq ($(BOARDMAKE),y)
|
2022-02-20 03:34:50 +01:00
|
|
|
LIBPATHS += -L $(call CONVERT_PATH,$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board)
|
2016-10-16 17:47:07 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
LDLIBS = $(patsubst %.a,%,$(patsubst lib%,-l%,$(LINKLIBS)))
|
|
|
|
ifeq ($(BOARDMAKE),y)
|
|
|
|
LDLIBS += -lboard
|
|
|
|
endif
|
|
|
|
|
|
|
|
VPATH += chip
|
|
|
|
VPATH += common
|
2024-01-31 20:07:58 +01:00
|
|
|
VPATH += common/espressif
|
2022-05-18 09:10:49 +02:00
|
|
|
VPATH += $(SBI_DIR)
|
2016-10-16 17:47:07 +02:00
|
|
|
VPATH += $(ARCH_SUBDIR)
|
|
|
|
VPATH += $(CHIP_DIR)
|
|
|
|
|
|
|
|
all: $(HEAD_OBJ) $(BIN)
|
|
|
|
|
2017-06-28 21:16:48 +02:00
|
|
|
.PHONY: board/libboard$(LIBEXT)
|
2016-10-16 17:47:07 +02:00
|
|
|
|
|
|
|
$(AOBJS) $(UAOBJS) $(HEAD_OBJ): %$(OBJEXT): %.S
|
|
|
|
$(call ASSEMBLE, $<, $@)
|
|
|
|
|
|
|
|
$(COBJS) $(UCOBJS): %$(OBJEXT): %.c
|
|
|
|
$(call COMPILE, $<, $@)
|
|
|
|
|
2022-01-25 15:00:09 +01:00
|
|
|
crt0$(OBJEXT): %$(OBJEXT): %.c
|
|
|
|
$(call COMPILE, $<, $@)
|
|
|
|
|
2020-05-01 21:23:04 +02:00
|
|
|
ifeq ($(CONFIG_BUILD_FLAT),y)
|
|
|
|
$(BIN): $(OBJS)
|
2016-10-16 17:47:07 +02:00
|
|
|
$(call ARCHIVE, $@, $(OBJS))
|
2020-05-01 21:23:04 +02:00
|
|
|
else
|
|
|
|
$(BIN): $(UOBJS)
|
2016-10-16 17:47:07 +02:00
|
|
|
$(call ARCHIVE, $@, $(UOBJS))
|
2020-05-01 21:23:04 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
$(KBIN): $(OBJS)
|
|
|
|
$(call ARCHIVE, $@, $(OBJS))
|
2016-10-16 17:47:07 +02:00
|
|
|
|
|
|
|
board/libboard$(LIBEXT):
|
2020-09-14 18:53:37 +02:00
|
|
|
$(Q) $(MAKE) -C board libboard$(LIBEXT) EXTRAFLAGS="$(EXTRAFLAGS)"
|
2016-10-16 17:47:07 +02:00
|
|
|
|
2024-04-07 12:20:17 +02:00
|
|
|
# When multiple linking, these two additional linking objects will be included
|
|
|
|
|
|
|
|
ifeq ($(CONFIG_MM_KASAN_GLOBAL),y)
|
|
|
|
EXTRA_LIBS += kasan_globals$(OBJEXT)
|
|
|
|
endif
|
|
|
|
ifeq ($(CONFIG_ALLSYMS),y)
|
|
|
|
EXTRA_LIBS += allsyms$(OBJEXT)
|
|
|
|
endif
|
|
|
|
|
|
|
|
define LINK_ALLSYMS_KASAN
|
|
|
|
$(if $(CONFIG_ALLSYMS),
|
2023-11-27 10:28:38 +01:00
|
|
|
$(Q) $(TOPDIR)/tools/mkallsyms.py $(NUTTX) allsyms.tmp --orderbyname $(CONFIG_SYMTAB_ORDEREDBYNAME)
|
2023-01-30 08:20:55 +01:00
|
|
|
$(Q) $(call COMPILE, allsyms.tmp, allsyms$(OBJEXT), -x c)
|
2024-04-07 12:20:17 +02:00
|
|
|
$(Q) $(call DELFILE, allsyms.tmp))
|
|
|
|
$(if $(CONFIG_MM_KASAN_GLOBAL),
|
|
|
|
$(Q) $(TOPDIR)/tools/kasan_global.py -e $(NUTTX) -o kasan_globals.tmp
|
|
|
|
$(Q) $(call COMPILE, kasan_globals.tmp, kasan_globals$(OBJEXT) -fno-sanitize=kernel-address, -x c)
|
|
|
|
$(Q) $(call DELFILE, kasan_globals.tmp))
|
2024-04-18 08:01:18 +02:00
|
|
|
$(Q) $(LD) $(LDENTRY) $(LDFLAGS) $(LIBPATHS) $(EXTRA_LIBPATHS) \
|
2024-04-07 12:20:17 +02:00
|
|
|
-o $(NUTTX) $(HEAD_OBJ) $(EXTRA_OBJS) \
|
2021-12-07 06:00:28 +01:00
|
|
|
$(LDSTARTGROUP) $(LDLIBS) $(EXTRA_LIBS) $(LDENDGROUP)
|
|
|
|
endef
|
|
|
|
|
2022-09-28 10:32:02 +02:00
|
|
|
$(addsuffix .tmp,$(ARCHSCRIPT)): $(ARCHSCRIPT)
|
|
|
|
$(call PREPROCESS, $(patsubst %.tmp,%,$@), $@)
|
|
|
|
|
|
|
|
nuttx$(EXEEXT): $(HEAD_OBJ) board/libboard$(LIBEXT) $(addsuffix .tmp,$(ARCHSCRIPT))
|
2016-10-16 17:47:07 +02:00
|
|
|
$(Q) echo "LD: nuttx"
|
2024-04-07 12:20:17 +02:00
|
|
|
ifeq ($(CONFIG_ALLSYMS)$(CONFIG_MM_KASAN_GLOBAL),)
|
2024-04-18 08:01:18 +02:00
|
|
|
$(Q) $(LD) $(LDENTRY) $(LDFLAGS) $(LIBPATHS) $(EXTRA_LIBPATHS) \
|
2016-10-16 17:47:07 +02:00
|
|
|
-o $(NUTTX) $(HEAD_OBJ) $(EXTRA_OBJS) \
|
2020-07-15 14:51:26 +02:00
|
|
|
$(LDSTARTGROUP) $(LDLIBS) $(EXTRA_LIBS) $(LDENDGROUP)
|
2021-12-07 06:00:28 +01:00
|
|
|
else
|
2024-04-07 12:20:17 +02:00
|
|
|
$(Q) $(call LINK_ALLSYMS_KASAN)
|
|
|
|
$(Q) $(call LINK_ALLSYMS_KASAN)
|
|
|
|
$(Q) $(call LINK_ALLSYMS_KASAN)
|
|
|
|
$(Q) $(call LINK_ALLSYMS_KASAN)
|
|
|
|
endif
|
|
|
|
ifeq ($(CONFIG_MM_KASAN_GLOBAL),y)
|
|
|
|
$(Q) $(OBJCOPY) -R .kasan.global $(NUTTX)
|
|
|
|
$(Q) $(OBJCOPY) -R .kasan.unused $(NUTTX)
|
2021-12-07 06:00:28 +01:00
|
|
|
endif
|
2016-10-16 17:47:07 +02:00
|
|
|
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
|
|
$(Q) $(NM) $(NUTTX) | \
|
|
|
|
grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
|
|
|
|
sort > $(TOPDIR)/System.map
|
|
|
|
endif
|
2022-09-28 10:32:02 +02:00
|
|
|
$(Q) $(call DELFILE, $(addsuffix .tmp,$(ARCHSCRIPT)))
|
2016-10-16 17:47:07 +02:00
|
|
|
|
|
|
|
# This is part of the top-level export target
|
|
|
|
# Note that there may not be a head object if layout is handled
|
|
|
|
# by the linker configuration.
|
|
|
|
|
2022-05-12 12:41:27 +02:00
|
|
|
export_startup: $(STARTUP_OBJS)
|
2016-10-16 17:47:07 +02:00
|
|
|
ifneq ($(STARTUP_OBJS),)
|
|
|
|
$(Q) if [ -d "$(EXPORT_DIR)/startup" ]; then \
|
|
|
|
cp -f $(STARTUP_OBJS) "$(EXPORT_DIR)/startup/."; \
|
|
|
|
else \
|
|
|
|
echo "$(EXPORT_DIR)/startup does not exist"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Dependencies
|
|
|
|
|
2020-12-15 14:52:41 +01:00
|
|
|
makedepfile: $(CSRCS:.c=.ddc) $(ASRCS:.S=.dds) $(HEAD_ASRC:.S=.dds)
|
2020-11-18 17:44:58 +01:00
|
|
|
$(call CATFILE, Make.dep, $^)
|
|
|
|
$(call DELFILE, $^)
|
|
|
|
|
2020-07-22 09:54:29 +02:00
|
|
|
.depend: Makefile $(SRCS) $(TOPDIR)$(DELIM).config
|
2016-10-16 17:47:07 +02:00
|
|
|
ifeq ($(BOARDMAKE),y)
|
2020-09-14 18:53:37 +02:00
|
|
|
$(Q) $(MAKE) -C board depend
|
2016-10-16 17:47:07 +02:00
|
|
|
endif
|
2020-11-18 17:44:58 +01:00
|
|
|
$(Q) $(MAKE) makedepfile DEPPATH="$(patsubst %,--dep-path %,$(subst :, ,$(VPATH)))"
|
2020-03-23 03:44:03 +01:00
|
|
|
$(Q) touch $@
|
2016-10-16 17:47:07 +02:00
|
|
|
|
2020-03-23 03:44:03 +01:00
|
|
|
depend: .depend
|
2016-10-16 17:47:07 +02:00
|
|
|
|
2020-09-23 13:48:02 +02:00
|
|
|
context::
|
|
|
|
|
2016-10-16 17:47:07 +02:00
|
|
|
clean:
|
|
|
|
ifeq ($(BOARDMAKE),y)
|
2020-09-14 18:53:37 +02:00
|
|
|
$(Q) $(MAKE) -C board clean
|
2016-10-16 17:47:07 +02:00
|
|
|
endif
|
2022-09-28 10:32:02 +02:00
|
|
|
$(call DELFILE, $(addsuffix .tmp,$(ARCHSCRIPT)))
|
2016-10-16 17:47:07 +02:00
|
|
|
$(call DELFILE, $(KBIN))
|
|
|
|
$(call DELFILE, $(BIN))
|
|
|
|
$(call DELFILE, $(HEAD_OBJ))
|
|
|
|
$(call CLEAN)
|
|
|
|
|
2021-07-21 18:48:05 +02:00
|
|
|
distclean:: clean
|
2016-10-16 17:47:07 +02:00
|
|
|
ifeq ($(BOARDMAKE),y)
|
2020-09-14 18:53:37 +02:00
|
|
|
$(Q) $(MAKE) -C board distclean
|
2016-10-16 17:47:07 +02:00
|
|
|
endif
|
|
|
|
$(call DELFILE, Make.dep)
|
2020-03-23 03:44:03 +01:00
|
|
|
$(call DELFILE, .depend)
|
2016-10-16 17:47:07 +02:00
|
|
|
|
2019-11-28 21:37:24 +01:00
|
|
|
-include Make.dep
|