#       $NetBSD: Makefile.cmachflags,v 1.4 2022/01/26 11:48:53 andvar Exp $

# Set CMACHFLAGS best target the specific CPU combination, based on
# their "options" setting.

# This should typically be included iff the config file has not already set
# CMACHFLAGS, eg:
#   .if !defined(CMACHFLAGS)
#   .include "$S/arch/m68k/Makefile.cmachflags"
#   CMACHFLAGS+=    -Wa,-m68030 -Wa,-m68851
#   .endif

# Table of CPUs targeted vs gcc flags. Note: -m68020 and -m68030 are
# ~identical, but they are both included for completeness.

# 020 030 040 060 -m68020-60
# 030 040 060     -m68020-60
# 020 040 060     -m68020-60
# 020 030 060     -m68020-60
# 040 060         -m68020-60 (Would have been nice to have a -m68040-60)
# 030 060         -m68020-60
# 020 060         -m68020-60
# 060             -m68060
#
# 020 030 040     -m68020-40
# 030 040         -m68020-40
# 020 040         -m68020-40
# 040             -m68040
#
# 020 030         -m68020
# 030             -m68030
# 020             -m68020

HAVE_M68020!=   grep '\#define[         ]*M68020' opt_m68k_arch.h 2>/dev/null || echo no
HAVE_M68030!=   grep '\#define[         ]*M68030' opt_m68k_arch.h 2>/dev/null || echo no
HAVE_M68040!=   grep '\#define[         ]*M68040' opt_m68k_arch.h 2>/dev/null || echo no
HAVE_M68060!=   grep '\#define[         ]*M68060' opt_m68k_arch.h 2>/dev/null || echo no

if ${HAVE_M68060} != "no"
if ${HAVE_M68020} != "no" || ${HAVE_M68030} != "no" || ${HAVE_M68040} != "no"
CMACHFLAGS=     -m68020-60
else
CMACHFLAGS=     -m68060
endif
elif ${HAVE_M68040} != "no"
if ${HAVE_M68020} != "no" || ${HAVE_M68030} != "no"
CMACHFLAGS=     -m68020-40
else   # !-DM68060
CMACHFLAGS=     -m68040
endif
elif ${HAVE_M68020} != "no"
CMACHFLAGS=     -m68020
else
CMACHFLAGS=     -m68030
endif   # !-DM68060