############################################################################ # tools/Config.mk # # SPDX-License-Identifier: Apache-2.0 # # 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 # # http://www.apache.org/licenses/LICENSE-2.0 # # 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. # ############################################################################ ifeq ($(realpath ${NXBASE}),) $(error "NXBASE is not defined or invalid path") endif ifeq ($(realpath ${NXOUT}),) $(error "NXOUT is not defined or invalid path") endif ifeq ($(realpath ${TOOLCHAIN}),) $(error "TOOLCHAIN is not defined or invalid path") endif # These are configuration variables that are quoted by configuration tool # but which must be unquoted when used in the build system. ARCH_DIR := $(realpath ${NXBASE}/arch/${ARCH}) ARCH_CHIP := $(patsubst "%",%,$(strip ${CONFIG_ARCH_CHIP})) ARCH_FAMILY := $(patsubst "%",%,$(strip ${CONFIG_ARCH_FAMILY})) include ${TOOLCHAIN} # ARCHxxx means the predefined setting # (either toolchain, arch, or system specific) ARCHDEFINES += -D__NuttX__ CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) CFLAGS += $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) AFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) AFLAGS += $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) # ccache configuration. ifeq ($(CONFIG_CCACHE),y) CCACHE ?= ccache endif ifeq ($(ECHO_BEGIN),) export ECHO_BEGIN=@echo # keep a trailing space here export ECHO_END= endif # PREPROCESS - Default macro to run the C pre-processor # Example: $(call PREPROCESS, in-file, out-file) # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # CPP - The command to invoke the C pre-processor # CPPFLAGS - Options to pass to the C pre-processor # # '.c_CPPFLAGS += ' may also be used, as an example, to # change the options used with the single file .c (or # .S) define PREPROCESS $(ECHO_BEGIN)"CPP: $1->$2 " $(Q) $(CPP) $(CPPFLAGS) $($(strip $1)_CPPFLAGS) $1 -o $2 $(ECHO_END) endef # COMPILE - Default macro to compile one C file # Example: $(call COMPILE, in-file, out-file, flags) # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # CC - The command to invoke the C compiler # CFLAGS - Options to pass to the C compiler # # '.c_CFLAGS += ' may also be used, as an example, to # change the options used with the single file .c define COMPILE $(ECHO_BEGIN)"CC: $1 " $(Q) $(CCACHE) $(CC) -c $(CFLAGS) $3 $($(strip $1)_CFLAGS) $1 -o $2 $(ECHO_END) endef # COMPILEXX - Default macro to compile one C++ file # Example: $(call COMPILEXX, in-file, out-file, flags) # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # CXX - The command to invoke the C++ compiler # CXXFLAGS - Options to pass to the C++ compiler # # '.cxx_CXXFLAGS += ' may also be used, as an example, to # change the options used with the single file .cxx. The # extension .cpp could also be used. The same applies mutatis mutandis. define COMPILEXX $(ECHO_BEGIN)"CXX: $1 " $(Q) $(CCACHE) $(CXX) -c $(CXXFLAGS) $3 $($(strip $1)_CXXFLAGS) $1 -o $2 $(ECHO_END) endef # COMPILERUST - Default macro to compile one Rust file # Example: $(call COMPILERUST, in-file, out-file) # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # RUST - The command to invoke the Rust compiler # RUSTFLAGS - Options to pass to the Rust compiler # # '.rs_RUSTFLAGS += ' may also be used, as an example, to # change the options used with the single file .rs. The same # applies mutatis mutandis. define COMPILERUST $(ECHO_BEGIN)"RUSTC: $1 " $(Q) $(RUSTC) --emit obj $(RUSTFLAGS) $($(strip $1)_RUSTFLAGS) $1 -o $2 $(ECHO_END) endef # COMPILEZIG - Default macro to compile one Zig file # Example: $(call COMPILEZIG, in-file, out-file) # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # ZIG - The command to invoke the Zig compiler # ZIGFLAGS - Options to pass to the Zig compiler # # '.zig_ZIGFLAGS += ' may also be used, as an example, to # change the options used with the single file .zig. The same # applies mutatis mutandis. define COMPILEZIG $(ECHO_BEGIN)"ZIG: $1 " $(Q) $(ZIG) build-obj $(ZIGFLAGS) $($(strip $1)_ZIGFLAGS) --name $(basename $2) $1 $(ECHO_END) endef # COMPILED - Default macro to compile one D file # Example: $(call COMPILED, in-file, out-file) # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # DC - The command to invoke the D compiler # DFLAGS - Options to pass to the D compiler # # '.d_DFLAGS += ' may also be used, as an example, to # change the options used with the single file .d. The same # applies mutatis mutandis. define COMPILED $(ECHO_BEGIN)"DC: $1 " $(Q) $(DC) -c $(DFLAGS) $($(strip $1)_DFLAGS) $1 -of $2 $(ECHO_END) endef # COMPILESWIFT - Default macro to compile one Swift file # Example: $(call COMPILESWIFT, in-file, out-file) # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # SWIFTC - The command to invoke the Swift compiler # SWIFTFLAGS - Options to pass to the Swift compiler # # '.swift_SWIFTFLAGS += ' may also be used, as an example, to # change the options used with the single file .swift. The same # applies mutatis mutandis. define COMPILESWIFT $(ECHO_BEGIN)"SWIFTC: $1 " $(Q) $(SWIFTC) -c $(SWIFTFLAGS) $($(strip $1)_SWIFTFLAGS) $1 -o $2 $(ECHO_END) endef # ASSEMBLE - Default macro to assemble one assembly language file # Example: $(call ASSEMBLE, in-file, out-file) # # NOTE that the most common toolchain, GCC, uses the compiler to assemble # files because this has the advantage of running the C Pre-Processor against # the assembly language files. This is not possible with other toolchains; # platforms using those other tools should define AS and over-ride this # definition in order to use the assembler directly. # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # CC - By default, the C compiler is used to compile assembly language # files # AFLAGS - Options to pass to the C+compiler # # '.s_AFLAGS += ' may also be used, as an example, to change # the options used with the single file .s. The extension .asm # is used by some toolchains. The same applies mutatis mutandis. define ASSEMBLE $(ECHO_BEGIN)"AS: $1 " $(Q) $(CCACHE) $(CC) -c $(AFLAGS) $1 $($(strip $1)_AFLAGS) -o $2 $(ECHO_END) endef # ARCHIVE - Add a list of files to an archive # Example: $(call ARCHIVE, archive-file, "file1 file2 file3 ...") # # Note: The fileN strings may not contain spaces or characters that may be # interpreted strangely by the shell # # Depends on these settings defined in board-specific Make.defs file # installed at ${NXBASE}/Make.defs: # # AR - The command to invoke the archiver (includes any options) # # Depends on this settings defined in board-specific defconfig file installed # at ${NXBASE}/.config: # # CONFIG_WINDOWS_NATIVE - Defined for a Windows native build define ARCHIVE $(ECHO_BEGIN)"AS: $1 " $(Q) $(AR) $1 $2 $(ECHO_END) endef define LINK $(ECHO_BEGIN)"LN: $1 " $(Q) [ -L $2 ] || ln -s $1 $2 $(ECHO_END) endef define UNLINK $(ECHO_BEGIN)"RM: $1 " $(Q) [ -L $1 ] && rm -f $1 $(ECHO_END) endef # PREBUILD -- Perform pre build operations # Some architectures require the use of special tools and special handling # BEFORE building NuttX. The `Make.defs` files for those architectures # should override the following define with the correct operations for # that platform. define PREBUILD endef # POSTBUILD -- Perform post build operations # Some architectures require the use of special tools and special handling # AFTER building the NuttX binary. Make.defs files for those architectures # should override the following define with the correct operations for # that platform define POSTBUILD endef