Detecting AVR type boards

Is it possible to detect AVR type boards VS non-AVR boards?

In my code I have as follows to include watchdog and interrupts:

#include <avr/wdt.h>
#include <avr/interrupt.h>

This is fine for the Uno, Nano or Mega 2560, however these libraries are not recognized when I compile for other boards such as the ESP8288 or ESP32. I would like to be able to add some conditional directives like this:

#ifdef AVR_BOARD
#include <avr/wdt.h>
#include <avr/interrupt.h>
#endif

and also;

#ifdef AVR_BOARD
(watchdog code)
(interrupt code)
#else
(alternative code)
#endif

It would be a bit tedious to specify a list of Arduino boards with AVR_ATmega328P, AVR_ATmega2560, AVR_ATmega32U4 etc. Is there a higher level identifier to recognize the AVR prefix?

e.g. AVR

That was too obvious!
I didn't think to try two underscores either side though. With two it does seem to be working.
Thank you.

BTW, by the same toke, is it possible to determine whether a board supports EEPROM and HardwareSerial?

Each AVR has EEPROM (maybe a few have not) the E2END and EEMEM should be defined.
For HardwareSerial see the header file. There is at the end:

#if defined(UBRRH) || defined(UBRR0H)
  extern HardwareSerial Serial;
  #define HAVE_HWSERIAL0
#endif
#if defined(UBRR1H)
  extern HardwareSerial Serial1;
  #define HAVE_HWSERIAL1
#endif
#if defined(UBRR2H)
  extern HardwareSerial Serial2;
  #define HAVE_HWSERIAL2
#endif
#if defined(UBRR3H)
  extern HardwareSerial Serial3;
  #define HAVE_HWSERIAL3
#endif

It is based on USART register presence.

Thank you for that. It is much appreciated.

You can also identify the exact part with similar defines, ex:

AVR_ATtiny3217

AVR_ATmega328

How does one identify an ESP8266 or an ESP32?

I tried a number of options including:
ESP
AVR_ESP8266
ESP8266
ESP8266_GENERIC

The last one is taken form the boards.txt file, but none of them seem to work?

Looks like the ESP does not need the preceding double underscores so something like:

#if defined (ESP8266) || defined(ESP32)

works just fine.