From ef5b03b0e5864bbf33e96d73d4cd9548f1f7f309 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Sat, 18 Sep 2021 09:56:29 +1000 Subject: [PATCH] Support clang and FreeBSD - Support clang is detected - Use c++ and cc for native host builds - Add dependencies --- Makefile | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 09896b9..58c25f1 100755 --- a/Makefile +++ b/Makefile @@ -34,23 +34,35 @@ else ifneq ($(CROSS_COMPILER), ) CXX = $(CROSS_COMPILER) CC = $(subst g++,gcc,$(CROSS_COMPILER)) else - CXX = g++ - CC = gcc + # Native host build, use the supplied compiler + CXX = c++ + CC = cc endif OBJ = o -CXXFLAGS ?= -std=c++0x -O -Wall -Wno-reorder -Wno-deprecated-declarations +CXX_NO_WARN ?= -Wno-reorder -Wno-deprecated-declarations +CXXFLAGS ?= -std=c++0x -O -Wall CFLAGS ?= -O -Wall +# A couple of steps to workaround gmake 3.81 issues +CLANGr = $(shell ${CXX} -dM -E - < /dev/null | grep __clang__) +CLANG = $(shell echo "$(CLANGr)" | sed "s/.*__clang__.*/yes/") + +ifeq ($(CLANG), yes) +CXX_NO_WARN += -Wno-deprecated-register +else GCCVERSIONGTEQ9 := $(shell expr `${CXX} -dumpversion | cut -f1 -d.` \>= 9) ifeq "$(GCCVERSIONGTEQ9)" "1" -CXXFLAGS += -Wno-aligned-new -Wno-misleading-indentation -Wno-class-memaccess +CXX_NO_WARN += -Wno-aligned-new -Wno-misleading-indentation -Wno-class-memaccess endif +endif + +CXXFLAGS += $(CXX_NO_WARN) EXEC = bootgen UNAME := $(shell uname) -ifeq ($(UNAME), Linux) +ifeq ($(UNAME),$(filter $(UNAME),Linux FreeBSD)) INCLUDE_SYS = -I. LIBS = -lssl -lcrypto RTLIBS = @@ -61,16 +73,20 @@ INCLUDE = $(INCLUDE_USER) $(INCLUDE_SYS) OPTIONS = $(OPTIONS_USER) +DEPS_GEN = -MD -MP -MF ${@:.o=.d} + all: $(EXEC) $(RTLIBS) OBJECTS = $(addsuffix .o, $(basename $(wildcard *.cpp))) OBJECTS += $(addsuffix .o, $(basename $(wildcard *.c))) +DEPS = $(OBJECTS:.o=.d) + %.${OBJ} : %.cpp - ${CXX} -c ${CXXFLAGS} $(OPTIONS) ${INCLUDE} $< + ${CXX} -c ${CXXFLAGS} $(OPTIONS) $(DEPS_GEN) ${INCLUDE} $< %.${OBJ} : %.c - ${CC} -c ${CFLAGS} $(OPTIONS) ${INCLUDE} $< + ${CC} -c ${CFLAGS} $(OPTIONS) $(DEPS_GEN) ${INCLUDE} $< ${EXEC}: $(OBJECTS) echo Building executable file: $@... @@ -82,3 +98,7 @@ clean: echo rm -rf ${EXEC} rm -f $(OBJECTS) + +ifneq ($(MAKECMDGOALS),clean) +-include $(DEPS) +endif