diff options
author | Angelo Rossi <angelo.rossi.homelab@gmail.com> | 2023-06-21 12:04:16 +0000 |
---|---|---|
committer | Angelo Rossi <angelo.rossi.homelab@gmail.com> | 2023-06-21 12:04:16 +0000 |
commit | b18347ffc9db9641e215995edea1c04c363b2bdf (patch) | |
tree | f3908dc911399f1a21e17d950355ee56dc0919ee /Makefile.global |
Initial commit.
Diffstat (limited to 'Makefile.global')
-rw-r--r-- | Makefile.global | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/Makefile.global b/Makefile.global new file mode 100644 index 0000000..60a2c48 --- /dev/null +++ b/Makefile.global @@ -0,0 +1,230 @@ +#-*- mode: makefile; indent-tabs-mode: t; coding: utf-8; show-trailing-whitespace: t -*- +# Makefile.global +# Copyright 2022 Angelo Rossi <angelo.rossi.homelab@gmail.com> +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +# +# Get the operating system name. If this is Cygwin, the .d files will be +# munged to convert c: into /cygdrive/c so that "make" will be happy with the +# auto-generated dependencies. +# + +# The command for calling the compiler. +ifeq (${shell uname},linux) + AS=${shell which as} + CC=${shell which gcc} + CXX=${shell which g++} + LD=${shell which ld} + OBJCOPY=${shell which objcopy} + OBJDUMP=${shell which objdump} + AR=${shell which ar} + NM=${shell which nm} +else + ifeq (${shell uname},OpenBSD) + AS=${shell which gas} + CC=${shell which egcc} + CXX=${shell which eg++} + LD=${shell which ld} + OBJCOPY=${shell which objcopy} + OBJDUMP=${shell which objdump} + AR=${shell which egcc-ar} + NM=${shell which egcc-nm} + endif +endif +LINKER=${CXX} + +# The flags passed to the assembler. + +AS_FLAGS= + +ifdef ARCH + AS_FLAGS+=-march=${ARCH} +endif + +# The flags passed to the c compiler. + +CC_FLAGS=-O0 \ + -Wall \ + -std=c99 \ + -pthread \ + -c + +# The flags passed to the c++ compiler. + +CXX_FLAGS=-O0 \ + -Wall \ + -std=gnu++11 \ + -pthread \ + -c + +ifdef WITH_OVER1 +CXX_FLAGS+=-DWITH_OVER1 +endif +ifdef WITH_OVER20 +CXX_FLAGS+=-DWITH_OVER20 +endif +ifdef WITH_OVER51 +CXX_FLAGS+=-DWITH_OVER51 +endif + + +# The flags passed to the linker. +LD_SCRIPT_FLAGS= +ifneq (${LINKER_SCRIPT},) + LD_SCRIPT_FLAGS+=-T ${SCRIPTS_PATH}/${LINKER_SCRIPT}.lnk +endif + +# Specs files. +SPECS_FILES= + +ifneq (${SPECS_FILES},) + SPECS_FLAGS=${patsubst %,--specs=%,${subst :, ,${SPECS_FILES}}} +else + SPECS_FLAGS= +endif + +LD_FLAGS= + +LD_FLAGS+=-Wl,--start-group \ + ${LD_SCRIPT_FLAGS} \ + ${SPECS_FLAGS} \ + -Wl,-Map=${TOOLCHAIN}/${TARGET}.map \ + -Wl,--end-group + +# ar most common flags. +AR_FLAGS=-cr + +# objdump most common flags. +OBJDUMP_FLAGS= -h \ + -EL \ + -s \ + -S \ + -d + +# objcopy most common flags. +OBJCOPY_FLAGS= -S \ + -R .data + +# Get the location of libgcc.a, libc.a, libstdc++ and +# libm.a from the GCC front-end. +LIBGCC=${shell ${CC} ${CC_FLAGS} -print-libgcc-file-name} +LIBC=${shell ${CC} ${CC_FLAGS} -print-file-name=libc.a} +LIBM=${shell ${CC} ${CC_FLAGS} -print-file-name=libm.a} +LIBPTHREAD=${shell ${CC} ${CC_FLAGS} --print-file-name=libpthread.a} +LIBSTDCXX=${shell ${CXX} ${CXX_FLAGS} --print-file-name=libstdc++.a} + +# Libraries to link. +LIBRARIES=pthread + +# Tell the compiler to include debugging information if the DEBUG environment +# variable is set. +ifneq (${DEBUG},) + AS_FLAGS+=-ggdb3 + CC_FLAGS+=-ggdb3 -DDEBUG + CXX_FLAGS+=-ggdb3 -DDEBUG + LD_FLAGS+=-ggdb3 +endif + +# Add the include file paths to AS_FLAGS, CC_FLAGS and CXX_FLAGS. +AS_FLAGS+=${patsubst %,-I%,${subst :, ,${INCLUDES_PATH}}} +CC_FLAGS+=${patsubst %,-I%,${subst :, ,${INCLUDES_PATH}}} +CXX_FLAGS+=${patsubst %,-I%,${subst :, ,${INCLUDES_PATH}}} + +LD_FLAGS+=-pthread + +ifneq (${LIBRARIES_PATH},) +LD_FLAGS+=${patsubst %,-L%,${subst :, ,${LIBRARIES_PATH}}} +endif + +ifneq (${LIBRARIES},) +LD_FLAGS+=${patsubst %,-l%,${subst :, ,${LIBRARIES}}} +endif + +# Rule for building the object file from each assembly source files. +${TOOLCHAIN}/%.o: %.S + @if [ 'x${VERBOSE}' = x ]; \ + then \ + echo " [ AS ] ${<}"; \ + else \ + echo "${AS} ${AS_FLAGS} ${<} -o ${@}"; \ + fi + @${AS} ${AS_FLAGS} ${<} -o ${@} + +# Rule for building the object file from each C source file. + +${TOOLCHAIN}/%.o: %.c + @if [ 'x${VERBOSE}' = x ]; \ + then \ + echo " [ CC ] ${<}"; \ + else \ + echo ${CC} ${CC_FLAGS} -o ${@} ${<}; \ + fi + @${CC} ${CC_FLAGS} -o ${@} ${<} + +${TOOLCHAIN}/%.o: %.cpp + @if [ 'x${VERBOSE}' = x ]; \ + then \ + echo " [ CPP ] ${<}"; \ + else \ + echo ${CXX} ${CXX_FLAGS} -o ${@} ${<}; \ + fi + @${CXX} ${CXX_FLAGS} -o ${@} ${<} + +# Rule for creating an object library. +${TOOLCHAIN}/%.a: + @if [ 'x${VERBOSE}' = x ]; \ + then \ + echo " [ AR ] ${@}"; \ + else \ + echo ${AR} ${AR_FLAGS} ${@} ${^}; \ + fi + @${AR} ${AR_FLAGS} ${@} ${^} + +# Rule for linking the application. +${TOOLCHAIN}/%: + @if [ 'x${VERBOSE}' = x ]; \ + then \ + echo " [ LD ] ${@}"; \ + else \ + echo ${LINKER} $(filter %.o %.a, ${^}) \ + ${LD_FLAGS} \ + -o ${@}; \ + fi + @${LINKER} $(filter %.o %.a, ${^}) \ + ${LD_FLAGS} \ + -o ${@} + +# Rule to create a .lst file. +${TOOLCHAIN}/%.lst: + @if [ 'x${VERBOSE}' = x ]; \ + then \ + echo " [ OBJDUMP ] ${@}"; \ + else \ + echo "${OBJDUMP} ${OBJDUMP_FLAGS} ${TOOLCHAIN}/${TARGET} > ${@}"; \ + fi + @${OBJDUMP} ${OBJDUMP_FLAGS} ${TOOLCHAIN}/${TARGET} > ${@} |