I've the following error:
'for' loop initial declarations are only allowed in C99 mode
use option -std=c99 or -std=gnu99 to compile your code.
How can I add this option to my makefile? This is my makefile: (I think that this option should be in the first lines of the makefile)
NATIVE = $(shell uname --machine)
BOARD ?= $(NATIVE)
V2XATK ?= 0
V2XLLC ?= 1
V2XQTI ?= 0
APP = obu-hmi-cohda
# Versioning
APPVERSION := 2.4.0.RC3 (2021-10-19)
# Comment/uncomment the following line to disable/enable debugging
DEBUG := y
ifeq ($(DEBUG),y)
# "-O" is needed to expand inlines
EXTRA_CFLAGS = -O -ggdb -DDEBUG -DDEBUG_PRINT_TIMES
else
EXTRA_CFLAGS = -O2
endif
#Modificato puntamento a librerie compilate per x86 --> per compilazione x86
STACKDIR := $(realpath /home/duser/mk5/stack)
#STACKDIR := $(realpath /home/duser/x86/stack)
SRCDIR := $(realpath $(CURDIR))
OUTDIR := $(realpath $(CURDIR))/$(BOARD)
#############################################################################
# Import board configuration
#############################################################################
-include $(STACKDIR)/boards/$(BOARD).mk
#############################################################################
# Defaults for security libraries
#############################################################################
ifneq ($(NO_VIICSEC),1)
SEC_V2XLIBS := libviicsec.so libviicsec.so.1 libaerolinkPKI.so libaerolinkPKI.so.1 \
libmisbehaviorReport.so libmisbehaviorReport.so.1 \
libssl.so libssl.so.1.1 libcrypto.so libcrypto.so.1.1
SEC_LDLIBS := -Wl,--no-as-needed -ldl -lviicsec -lmisbehaviorReport -lssl -lcrypto
ifeq ($(NO_LIBC2X),0)
SEC_V2XLIBS = libc2x.so libc2x.so.1 libc2x.so.1.0 libc2x-compat.so libc2x-compat.so.1 \
libNxDispatcher.so libNxDispatcher.so.1.9 libNxDispatcher.so.1.9.3
SEC_LDLIBS = -lc2x -lNxDispatcher
endif
ifeq ($(NO_LIBV2XCRYPTO),0)
SEC_V2XLIBS = libv2xCrypto.so libv2xCrypto.so.2.7 libv2xCrypto.so.2.7.1 \
libv2xCryptoPal.so libv2xCryptoPal.so.2.7 libv2xCryptoPal.so.2.7.1 \
libNxDispatcher.so libNxDispatcher.so.1.9 libNxDispatcher.so.1.9.3
SEC_LDLIBS = -lv2xCrypto -lv2xCryptoPal -lNxDispatcher
endif
ifeq ($(NO_AEROLINK_SCMS),0)
SEC_V2XLIBS = libaerolinkSCMS.so
SEC_LDLIBS = -laerolinkSCMS
endif
else
SEC_V2XLIBS :=
SEC_LDLIBS :=
endif
#############################################################################
# BOARD specific setup
# - Folder locations, CROSSCOMPILE, CCOPTS, INSTALLDIR etc.
#############################################################################
# Allow ccache to be disabled for static analysis
CCACHE ?= ccache
ifneq (,$(findstring $(BOARD),mk5 flowradar bach pateo ubxp3))
# MK5 etc.
ARCH := arm
CROSS_COMPILE ?= "$(CCACHE) arm-linux-gnueabihf-"
INSTALLDIR ?= $(STACKDIR)/../bsp/image/rootfs
SEC_V2XLIBS := libviicsec.so libviicsec.so.1 libaerolinkPKI.so libaerolinkPKI.so.1 \
libmisbehaviorReport.so libmisbehaviorReport.so.1 \
libaerolinkSCMS.so libssl.so libssl.so.1.1 libcrypto.so libcrypto.so.1.1 \
libc2x.so libc2x.so.1 libc2x.so.1.0 \
libNxDispatcher.so libNxDispatcher.so.1.9 libNxDispatcher.so.1.9.3
SEC_LDLIBS := -lviicsec -laerolinkSCMS -lssl -lcrypto -lc2x -Wl,--no-as-needed -lNxDispatcher -ldl
else ifneq (,$(findstring $(BOARD),re2l))
ARCH := arm
CROSS_COMPILE ?= ccache arm-poky-linux-gnueabi-
INSTALLDIR ?=
INSTALLDIR ?= $(STACKDIR)/../bsp/image/rootfs
#SDKDIR ?= $(CURDIR)/../../../bsp/atk/craton2-sdk # TODO
CCOPTS = -mfloat-abi=hard -mfpu=neon --sysroot=/opt/imx-v2x/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi
#CFLAGS = -I$(SDKDIR)/include
CFLAGS = -I/opt/imx-v2x/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include
#LDFLAGS = -L$(SDKDIR)/sdk/local_linux_u/lib/ --sysroot=/opt/poky-craton2/2.2.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi
SEC_V2XLIBS := libviicsec.so libviicsec.so.1 libaerolinkPKI.so libaerolinkPKI.so.1 \
libmisbehaviorReport.so libmisbehaviorReport.so.1 \
libaerolinkSCMS.so libssl.so libssl.so.1.1 libcrypto.so libcrypto.so.1.1 \
libc2x.so libc2x.so.1 libc2x.so.1.0 \
libNxDispatcher.so libNxDispatcher.so.1.9 libNxDispatcher.so.1.9.3
SEC_LDLIBS := -lviicsec -laerolinkSCMS -lssl -lcrypto -lc2x -Wl,--no-as-needed -lNxDispatcher -ldl
#/opt/imx-v2x/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
# SEC_V2XLIBS ?= libviicsec.so libviicsec.so.1 libaerolinkPKI.so libaerolinkPKI.so.1
# SEC_LDLIBS ?= -lviicsec -laerolinkPKI
else ifneq (,$(findstring $(BOARD),mq5))
ARCH := arm
QNX_BASE ?= /opt/qnx660
CROSS_COMPILE := "$(CCACHE) arm-unknown-nto-qnx6.6.0eabi-"
INSTALLDIR ?=
CPPFLAGS = -DNO_SYSINFO
CFLAGS = -fpic
SEC_V2XLIBS :=
SEC_LDLIBS :=
V2XATK := 0
V2XLLC := 1
else ifneq (,$(findstring $(BOARD),craton2))
ARCH := arm
CROSS_COMPILE ?= "$(CCACHE) arm-poky-linux-gnueabi-"
INSTALLDIR ?=
SDKDIR ?= $(CURDIR)/../../../bsp/atk/craton2-sdk
CCOPTS = -mfloat-abi=hard -mthumb -mfpu=neon --sysroot=/opt/poky-craton2/2.2.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi
CFLAGS = -I$(SDKDIR)/include
LDFLAGS = -L$(SDKDIR)/sdk/local_linux_u/lib/ --sysroot=/opt/poky-craton2/2.2.1/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi
# SEC_V2XLIBS := libviicsec.so libviicsec.so.1 libaerolinkPKI.so libaerolinkPKI.so.1
# SEC_LDLIBS := -lviicsec -laerolinkPKI
V2XATK := 1
V2XLLC := 0
else ifneq (,$(findstring $(BOARD),dg2))
ifeq (,$(findstring atks,$(CC)))
$(error Setup the cross compilation environment first: 'source /mnt/atks/atks_yocto_sdk/atks_env_setup.sh')
endif
ARCH := arm
CROSS_COMPILE ?= "$(CCACHE) arm-poky-linux-gnueabi-"
INSTALLDIR ?=
SDKDIR ?= $(CURDIR)/../../../bsp/atk/craton2-sdk
CCOPTS = -mfloat-abi=hard -mthumb -mfpu=neon
CPPFLAGS = -DNO_VIICSEC
CFLAGS = -I$(SDKDIR)/include
LDFLAGS = -L$(SDKDIR)/sdk/local_linux_u/lib/
SEC_V2XLIBS := libviicsec.so libviicsec.so.1 \
libaerolinkSCMS.so libssl.so libssl.so.1.1 libcrypto.so libcrypto.so.1.1 libaerolinkPKI.so libaerolinkPKI.so.1
SEC_LDLIBS := -lviicsec \
-laerolinkSCMS -lssl -lcrypto
V2XATK := 1
V2XLLC := 0
else ifneq (,$(findstring $(BOARD),qti))
ARCH := arm64
CROSS_COMPILE ?= "$(CCACHE) aarch64-agl-linux-"
INSTALLDIR ?=
SDKTARGETSYSROOT ?= /opt/poky-agl/3.0.0 snapshot/sysroots/aarch64-agl-linux
CCOPTS = -fPIC --sysroot=$(SDKTARGETSYSROOT)
CPPFLAGS = -DNO_VIICSEC
CFLAGS = -I$(SDKTARGETSYSROOT)/usr/include
LDFLAGS = --sysroot=$(SDKTARGETSYSROOT)
SEC_V2XLIBS :=
SEC_LDLIBS :=
V2XLLC := 0
V2XQTI := 1
CFLAGS = -I$(CURDIR)/../../../bsp/QTI/include
else ifneq (,$(findstring $(BOARD),mk6c))
ARCH := arm64
CROSS_COMPILE ?= "$(CCACHE) aarch64-linux-gnu-"
INSTALLDIR ?= $(STACKDIR)/../bsp/image/rootfs
CCOPTS = -fPIC
CPPFLAGS =
SEC_V2XLIBS := libviicsec.so libviicsec.so.1 libaerolinkPKI.so libaerolinkPKI.so.1 \
libmisbehaviorReport.so libmisbehaviorReport.so.1 \
libaerolinkSCMS.so \
libv2xCrypto.so libv2xCrypto.so.2.6 libv2xCrypto.so.2.6.0 \
libv2xCryptoPal.so libv2xCryptoPal.so.2.6 libv2xCryptoPal.so.2.6.0 \
libNxDispatcher.so libNxDispatcher.so.1.2 libNxDispatcher.so.1.2.0 \
libssl.so libssl.so.1.1 libcrypto.so libcrypto.so.1.1
SEC_LDLIBS := -Wl,--no-as-needed -ldl \
-lviicsec \
-lmisbehaviorReport \
-laerolinkSCMS \
-lv2xCrypto -lv2xCryptoPal \
-lNxDispatcher \
-lssl -lcrypto
V2XLLC := 0
V2XQTI := 1
CFLAGS = -I$(CURDIR)/../../../bsp/QTI/include
else ifneq (,$(findstring $(BOARD),ir800))
ARCH := x86_64
CROSS_COMPILE ?= "$(CCACHE) "
INSTALLDIR ?=
CFLAGS = -Wall -Wextra #-Werror Rimosso gestione warning as error --> per compilazione x86
CPPFLAGS = -DNO_VIICSEC
SEC_V2XLIBS :=
SEC_LDLIBS :=
else ifneq ($(BOARD),$(NATIVE))
# Generic non-x86
ifneq ($(SDKTARGETSYSROOT),)
CCOPTS = -fPIC --sysroot=$(SDKTARGETSYSROOT)
CFLAGS = -I$(SDKTARGETSYSROOT)/usr/include
LDFLAGS = --sysroot=$(SDKTARGETSYSROOT)
endif
else
# Native (PC)
ARCH ?= $(NATIVE)
CROSS_COMPILE ?= "$(CCACHE) "
INSTALLDIR ?=
CFLAGS = -Wall -Wextra #-Werror Rimosso gestione warning as error --> per compilazione x86
SEC_V2XLIBS := libviicsec.so libviicsec.so.1 libaerolinkPKI.so libaerolinkPKI.so.1 \
libmisbehaviorReport.so libmisbehaviorReport.so.1 \
libcrypto.so libcrypto.so.1.1
SEC_LDLIBS := -lviicsec -laerolinkPKI -lmisbehaviorReport
endif
#############################################################################
# File locations
#############################################################################
# Source directories
SRCDIRS := $(SRCDIR)/src
# Add this list to VPATH, the place $(MAKE) will look for the source files
VPATH := $(SRCDIRS)
# Matching output tree
OUTDIRS := $(subst $(SRCDIR),$(OUTDIR),$(SRCDIRS))
# Include folders
INCDIRS := $(SRCDIRS) \
$(OUTDIR)/include \
$(OUTDIR)/include/asn1 \
$(realpath $(STACKDIR)/../cohda/kernel/include) \
$(realpath $(STACKDIR)/../ieee1609/kernel/include) \
$(SRCDIR)/lib/cjson/arm/include
# Aerolink
ifneq (,$(findstring $(BOARD),$(NATIVE) mk5 mk6c jabiru flowradar bach craton2 pateo re2l ubxp3 ctx0800))
AEROLINK_SRCDIR = $(STACKDIR)/v2x-lib/aerolink
AEROLINK_CONFIG = $(OUTDIR)/aerolink/default
AEROLINK_SCRIPT = $(OUTDIR)/aerolink/rc.aerolink
AEROLINK_TOOLS = \
$(OUTDIR)/aerolink/certadm \
$(OUTDIR)/aerolink/crladm \
$(OUTDIR)/aerolink/acfGenerator \
$(OUTDIR)/aerolink/acfBuilder \
$(OUTDIR)/aerolink/acfInfo \
$(OUTDIR)/aerolink/extractSignerTlmFromEctl \
$(OUTDIR)/aerolink/createEtsiInitRequest \
$(OUTDIR)/aerolink/processEtsiInitResponse
endif
# ffasn1c location/options/etc.
FFASN1DIR = $(STACKDIR)/../tools/ffasn1c
FFASN1C = $(FFASN1DIR)/ffasn1c
FFASN1C_OPTS = -fdefine-int-values
FFASN1PY = $(STACKDIR)/tools/ffasn1.py
FFASN1PREFIX = RAW_
FFASN1DEF = $(SRCDIR)/src/RAW.asn1
FFASN1OUT = $(SRCDIR)/src/raw-asn
#############################################################################
# CPPFLAGS, CFLAGS, LDFLAGS, LDLIBS
#############################################################################
# If using yocto/poky toolchain, use CC in environment
ifeq (,$(TARGET_PREFIX))
CC := $(shell echo $(CROSS_COMPILE)gcc)
endif
CFLAGS = -DBOARD_$(shell echo $(BOARD) | tr a-z A-Z)
CFLAGS = -fpic -Wall -Wextra #-Werror Rimosso gestione warning as error --> per compilazione x86
LDFLAGS = -L$(OUTDIR) \
-L$(OUTDIR)/lib \
-L$(SRCDIR)/lib/cjson/arm/lib \
-Wl,--disable-new-dtags -Wl,-rpath,./lib
# Generate the include folders' associated CFLAGS entry by adding '-I' before each include folder
CFLAGS = $(foreach DIR, $(INCDIRS), $(addprefix -I, $(DIR)))
ifneq ($(INSTALLDIR),)
CFLAGS = -I$(INSTALLDIR)/usr/include
LDFLAGS = -L$(INSTALLDIR)/usr/lib
endif
ifneq (,$(LIBCFG_LIB_DIR))
LDFLAGS = -L$(LIBCFG_LIB_DIR)/lib/.libs
endif
ifneq (,$(GPSD_LIB_DIR))
LDFLAGS = -L$(GPSD_LIB_DIR)
endif
ifneq (,$(OPENSSL_LIB_DIR))
LDFLAGS = -L$(OPENSSL_LIB_DIR)
endif
ifneq (,$(DISPATCHER_LIB_DIR))
LDFLAGS = -L$(DISPATCHER_LIB_DIR)
endif
ifneq (,$(LIBV2XCRYPTO_LIB_DIR))
LDFLAGS = -L$(LIBV2XCRYPTO_LIB_DIR)
endif
# Plugins
V2XLIBS = libCANUDP.so
#V2XLIBS = libDNPW.so
V2XLIBS = libEEBL.so
#V2XLIBS = libEVW.so
V2XLIBS = libFCW.so
#V2XLIBS = libGLOSA.so
#V2XLIBS = libGMLAN.so
#V2XLIBS = libHLW.so
#V2XLIBS = libICW.so
#V2XLIBS = libIHW.so
#V2XLIBS = libIVS.so
#V2XLIBS = libLCW.so
#V2XLIBS = libLTA.so
V2XLIBS = libRWW.so
#V2XLIBS = libSVA.so
#V2XLIBS = libSVW.so
#V2XLIBS = libTJA.so
# Cohda libraries (platform, network & facilities layer)
V2XLIBS = libhmi.so libtm.so
LDLIBS = -lhmi -ltm
V2XLIBS = libtc.so libta.so libJudy.a
LDLIBS = -ltc -lta -lJudy
V2XLIBS = libspatmap.so
LDLIBS = -lspatmap
V2XLIBS = libivi.so libldm.so
LDLIBS = -livi -lldm
V2XLIBS = libext.so
LDLIBS = -lext
V2XLIBS = libitsfac.so libitsasn.so libitsnet.so
LDLIBS = -litsfac -litsasn -litsnet
ifneq (,$(findstring $(BOARD),ubxp3))
LDLIBS = -lubxp3
V2XLIBS = libubxp3.so
endif
V2XLIBS = libpos.so libubx.so
LDLIBS = -lpos -lubx
ifneq (,$(findstring $(BOARD),ir800))
V2XLIBS = libplatsv.so libclv.so
LDLIBS = -lplatsv -lclv
else
V2XLIBS = libplat.so libclv.so
LDLIBS = -lplat -lclv
endif
V2XLIBS = libtimechange.so
V2XLIBS = libconfig.a
LDLIBS = -lconfig
V2XLIBS = libgps_static.a libpcap.a
LDLIBS = -lgps_static -lpcap
V2XLIBS = $(SEC_V2XLIBS)
LDLIBS = $(SEC_LDLIBS)
ifeq ($(V2XLLC),1)
CPPFLAGS = -DV2XLLC
V2XLIBS = libLLC.so
LDLIBS = -lLLC
endif
ifeq ($(V2XATK),1)
CPPFLAGS = -DV2XATK
V2XLIBS = libatlklocal_linux_u.a
LDLIBS = -latlklocal_linux_u -ltomcrypt -ltommath
endif
ifeq ($(V2XQTI),1)
CPPFLAGS = -DV2XQTI
V2XLIBS = libv2x_radio.so libcv2x-kinematics.so libv2x_veh.so
V2XLIBS = libQTIVData.so
LDLIBS = -lv2x_radio -lcv2x-kinematics -lv2x_veh
endif
ifeq ($(BOARD),mq5)
LDLIBS = -lsocket -lmq -lc -lm
else
LDLIBS = -lpthread -lrt -ldl -lstdc -lm
endif
LDLIBS = -l:libcjson.a
# v2x-libs are installed locally in $(OUTDIR)/lib
V2XLIBS := $(addprefix $(OUTDIR)/lib/, $(V2XLIBS))
#############################################################################
# SRCS, OBJS, DEPS, LIBS etc.
#############################################################################
# Create a list of *.c sources in SRCDIRS
SRCS = $(foreach DIR,$(SRCDIRS),$(wildcard $(DIR)/*.c))
# Define objects for all sources
OBJS = $(subst $(SRCDIR),$(OUTDIR),$(SRCS:.c=.o))
# Define dependency files for all objects
DEPS = $(OBJS:.o=.d)
#############################################################################
# Rule generation function
#############################################################################
define GenerateRules
$(1)/%.o: %.c $(1)/%.d
@mkdir -p $$(@D) # Create the required OUTDIR.. folder
@# Generate dependency information as a side-effect of compilation, not instead of compilation.
@# -MMD omits system headers from the generated dependencies: if you prefer to preserve system headers as prerequisites, use -MD.
$$(CC) \
-MT $$@ -MMD -MP -MF $(1)/$$*.Td \
$$(CCOPTS) $$(CPPFLAGS) $$(CFLAGS) $$(EXTRA_CFLAGS) -c $$< -o $$@
@# First rename the generated temporary dependency file to the real dependency file.
@# We do this in a separate step so that failures during the compilation won’t leave a corrupted dependency file.
mv -f $(1)/$$*.Td $(1)/$$*.d
@# Second touch the object file; it’s been reported that some versions of GCC may leave the object file older than the dependency file, which causes unnecessary rebuilds.
touch $$@
# Create a pattern rule with an empty recipe, so that make won’t fail if the dependency file doesn’t yet exist.
$(1)/%.d: ;
# Mark the dependency files precious to make, so they won’t be automatically deleted as intermediate files.
.PRECIOUS: $(1)/%.d
$(1)/%.gpp: %.c src-gen $(OUTDIR)/include
@mkdir -p $$(@D) # Create the required OUTDIR.. folder
$$(CC) -dD -E $$(CCOPTS) $$(CPPFLAGS) $$(CFLAGS) $$(EXTRA_CFLAGS) -c $$< -o $$@
$(1)/%.lst: %.c src-gen $(OUTDIR)/include
@mkdir -p $$(@D) # Create the required OUTDIR.. folder
$$(CC) -S $$(CCOPTS) $$(CPPFLAGS) $$(CFLAGS) $$(EXTRA_CFLAGS) -c $$< -o $$@
$(1)/%.lint: %.c src-gen $(OUTDIR)/include
@mkdir -p $$(@D) # Create the required OUTDIR.. folder
-splint -shiftimplementation -warnposix -badflag --likelybool $$(CPPFLAGS) $$(CFLAGS) $$< | tee $$@
endef
#############################################################################
# Rules
#############################################################################
all:
env BOARD=$(BOARD) $(MAKE) app
# Generate rules
$(foreach DIR, $(OUTDIRS), $(eval $(call GenerateRules, $(DIR))))
# Include dependencies
-include $(DEPS)
src-gen: asn-gen ## Create all generated code
.PHONY: src-gen
app: version src-gen $(OUTDIR) ## Build $(APP) binary (Append BOARD=? to specify a non-host target)
$(MAKE) $(OUTDIR)/$(APP) aerolink
cpp: $(DEPS:.d=.gpp) ## Preprocess all $(APP) sources (Append BOARD=? to specify a non-host target)
lst: $(DEPS:.d=.lst) ## Generate assembler listings for all $(APP) sources (Append BOARD=? to specify a non-host target)
lint: $(DEPS:.d=.lint) ## Generate assembler listings for all $(APP) sources (Append BOARD=? to specify a non-host target)
.PHONY: all app cpp list lint
# Aerolink rule/targets
aerolink: $(V2XLIBS) $(AEROLINK_SCRIPT) $(AEROLINK_TOOLS) $(AEROLINK_CONFIG)
$(AEROLINK_CONFIG) : $(AEROLINK_SRCDIR)/config
@mkdir -p $@
@rsync -q -av --exclude="*.svn" $</* $@
$(AEROLINK_SCRIPT) : $(OUTDIR)/aerolink/% : $(AEROLINK_SRCDIR)/%
@mkdir -p $(dir $@)
@cp $< $@
$(AEROLINK_TOOLS) : $(OUTDIR)/aerolink/% : $(AEROLINK_SRCDIR)/$(BOARD)/%
@mkdir -p $(dir $@)
@cp $< $@
.PHONY: aerolink
# ffasn1c rules
$(FFASN1DEF):
@ls $(FFASN1DEF) # Nothing to do
$(FFASN1OUT).c: $(OUTDIR) $(FFASN1DEF)
-$(MAKE) --directory $(FFASN1DIR)
$(FFASN1C) $(FFASN1C_OPTS) -fprefix=$(FFASN1PREFIX) -o $(FFASN1OUT).junk $(FFASN1DEF)
$(FFASN1PY) -fprefix=$(FFASN1PREFIX) $(FFASN1OUT).junk $(FFASN1DEF)
# Since we're linking against itsasn, we don't need to create a link to (and complile) the asn.1 codec files
#@mkdir -p $(SRCDIR)/src/libffasn1
#ln -sf $(FFASN1DIR)/src/libffasn1/*.[ch] $(SRCDIR)/libffasn1
asn-gen: $(FFASN1OUT).c ## Create all ASN.1 generated code
.PHONY: asn-gen
# v2x-lib targets
$(STACKDIR)/v2x-lib/include $(STACKDIR)/v2x-lib/lib/$(BOARD):
# Build the v2x-libs via the $(STACKDIR)'s makefile
if [ -e $(STACKDIR)/Makefile ]; then \
$(MAKE) -C $(STACKDIR) BOARD=$(BOARD) lib-package; \
fi;
$(subst $(OUTDIR)/lib,$(STACKDIR)/v2x-lib/lib/$(BOARD),$(V2XLIBS)): $(STACKDIR)/v2x-lib/lib/$(BOARD)
$(OUTDIR)/include: $(STACKDIR)/v2x-lib/include $(OUTDIR)
@mkdir -p $@
@cp -ar $</* $@/
$(V2XLIBS): $(OUTDIR)/lib/%: $(STACKDIR)/v2x-lib/lib/$(BOARD)/% $(OUTDIR)
@mkdir -p $(dir $@)
@# The referenced lib*.so library may not exist due to licensing constraints
@if [ -e $< ]; then \
cp -a $< $@ ;\
fi;
# Build the application
$(OUTDIR)/$(APP): $(OUTDIR)/include $(V2XLIBS) $(OBJS) $(LIBS)
ifeq ($(BOARD),mq5)
# The QNX linker assumes the presence of '-fpic' means we want a shared library rather than an executable
$(CC) $(filter-out -fpic,$(CCOPTS) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) $(LDLIBS)) -o $@
else
$(CC) $(CCOPTS) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) $(LDLIBS) -o $@
endif
$(OUTDIR): # Create a per-target $(OUTDIR)
@mkdir -p $(OUTDIR)
@ln -sf $(SRCDIR)/* $(OUTDIR)/ # Link the contents of $(SRCDIR) en-mass to $(OUTDIR)
@rm -f $(OUTDIR)/$(BOARD) # No circular references allowed
@rm -f $(OUTDIR)/Makefile # A makefile in $(OUTDIR) is just confusing
@rm -f $(OUTDIR)/src && mkdir -p $(OUTDIR)/src # Remove the link to src/ and make our own (for build artefacts)
version: $(OUTDIR)
touch $(OUTDIR)/$@
echo '$(APPVERSION)' > $(OUTDIR)/$@
.PHONY: version
DESTDIR:=$(shell mktemp -d)
# Note the lack of folder prefixes below. TOSHIP files are sourced from $(CURDIR) *and* $(BOARD)
TOSHIP = $(APP) \
rc.$(APP) \
board.conf \
obu.cfg obu.conf \
rsu.cfg rsu.conf \
ui \
lib \
aerolink \
post_install \
version
board.conf:
rm -rf board.conf && ln -s $(BOARD).conf board.conf
tarball: app board.conf ## Create a $(APP) tarball. Use `BOARD`-tarball to generate for other targets (e.g. mk5-tarball)
@rm -f $(APP)-$(BOARD)-*.tgz
@rm -rf $(DESTDIR)
@mkdir -p $(DESTDIR)/$(APP)
@cd $(CURDIR) && rsync -avRL \
--exclude="*src*" --exclude="lib*.a" --ignore-missing-args \
$(TOSHIP) $(DESTDIR)/$(APP) 2>/dev/null || true
@cd $(OUTDIR) && rsync -avRL \
--exclude="*src*" --exclude="lib*.a" --ignore-missing-args \
$(TOSHIP) $(DESTDIR)/$(APP) 2>/dev/null || true
@sudo chown -R root:root $(DESTDIR)
@tar -C $(DESTDIR) \
--exclude-vcs -czf $(CURDIR)/build/$(APP)-$(BOARD)-Exported.tgz ./
@sudo chown $(USER):$(USER) $(CURDIR)/build/$(APP)-$(BOARD)-Exported.tgz
@sudo rm -rf $(DESTDIR)
@echo "== tarball =="
@du -h $(realpath $(CURDIR))/build/$(APP)-$(BOARD)-Exported.tgz
@echo "== installer =="
@base64 $(CURDIR)/build/$(APP)-$(BOARD)-Exported.tgz | cat installer_header.sh - > $(CURDIR)/build/$(APP)-$(BOARD)-installer.sh
@chmod x $(CURDIR)/build/$(APP)-$(BOARD)-installer.sh
%-tarball:
env BOARD=$* $(MAKE) tarball
.PHONY: tarball,%-tarball
install: $(BOARD)-tarball ## Install $(NATIVE) $(APP) to $(INSTALLDIR)/opt/cohda/application
sudo install -d $(INSTALLDIR)/opt/cohda/application
ifneq (,$(findstring $(BOARD),mq5))
# QNX's buildfile doesn't seem to support globbing so temporarily remove the version number when installing
@mv -f $(CURDIR)/$(APP)-$(BOARD)-Exported.tgz $(CURDIR)/$(APP)-$(BOARD).tgz
sudo install -c $(CURDIR)/$(APP)-$(BOARD).tgz $(INSTALLDIR)/opt/cohda/application
@mv -f $(CURDIR)/$(APP)-$(BOARD).tgz $(CURDIR)/$(APP)-$(BOARD)-Exported.tgz
else
sudo install -c $(CURDIR)/$(APP)-$(BOARD)-Exported.tgz $(INSTALLDIR)/opt/cohda/application
endif
.PHONY: install
# Note the 'clean's
# Use 'clean' to remove locally compiled objects (and associated executables & files)
# Use 'v2xclean' to remove the 'v2x-lib' artefacts too
v2xclean: clean
@if [ -d "$(STACKDIR)/src" ]; then \
echo "Cleaning v2x-lib" ; \
rm -rf $(STACKDIR)/v2x-lib/include ; \
rm -rf $(STACKDIR)/v2x-lib/lib/$(BOARD) ; \
fi
clean: ## Clean up. Use `BOARD`-clean to specify the target (e.g. mk5-clean)
@# Generated source(s)
rm -f $(FFASN1OUT)*
@# Build tree
sudo rm -rf $(OUTDIR)
@# Deployment files & folders
rm -f $(APP)-$(BOARD)-*.tgz
%-clean:
env BOARD=$* $(MAKE) clean
.PHONY: clean,%-clean
help:
@echo -e "$$(grep -hE '^\S :.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\ \):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)"
.PHONY: help
#############################################################################
# $(BOARD) specific rules
#############################################################################
$(NATIVE):
env BOARD=$@ $(MAKE) app
mk5:
env BOARD=$@ $(MAKE) app
mk6c:
env BOARD=$@ $(MAKE) app
mq5:
env BOARD=$@ $(MAKE) app
.PHONY: $(NATIVE)
.PHONY: mk5
.PHONY: mk6c
.PHONY: mq5
CodePudding user response:
You have a line:
CFLAGS = -DBOARD_$(shell echo $(BOARD) | tr a-z A-Z)
You can add it to the end of this line so it reads:
CFLAGS = -DBOARD_$(shell echo $(BOARD) | tr a-z A-Z) -std=c99