How to write a .h that checks for chip type?

I work with CAN-bus technology and utilize the ATmega328, 1284 & 2560 in my prototyping and projects.

I would like to be able to re-write this file to allow for each of the 3 chips' pin defines. As it currently stands, if I'm working with say the 328 and the 2560 at the same time I'm having to quit the Arduino IDE, copy or rename the defaults.h for one type, copy or rename the defaults.h for the other into its place, launch the Arduino IDE, compile and upload, then do it again for the other type.

This is tedious.

I'm looking for a way to write the defaults.h file so the IDE can do a check for the appropriate type and utilize the matching #define.

How do I do this?

I'm utilizing the Spark Fun CAN-Bus library.

defaults.h for 328:

#ifndef	DEFAULTS_H
#define	DEFAULTS_H

#define	P_MOSI	B,3
#define	P_MISO	B,4
#define	P_SCK	B,5

//#define	MCP2515_CS			D,3	// Rev A
#define	MCP2515_CS			B,2 // Rev B
#define	MCP2515_INT			D,2
#define LED2_HIGH			B,0
#define LED2_LOW			B,0

#endif	// DEFAULTS_H

defaults.h for 2560:

#ifndef	DEFAULTS_H
#define	DEFAULTS_H

#define	P_MOSI	B,2
#define	P_MISO	B,3
#define	P_SCK	B,1

//#define	MCP2515_CS			D,3	// Rev A
#define	MCP2515_CS			B,0 // Rev B
#define	MCP2515_INT			D,0
#define LED2_HIGH			B,0
#define LED2_LOW			B,0

#endif	// DEFAULTS_H

Look at some libraries that support multiple platforms. Adafruit comes to mind. Actually, I think there is a lot of that in the core itself.

Wondering if should be differentiated by Board type instead of Processor type?

In the case of a custom-made "board" on a breadboard, how would that work?

something like this ?

#if defined(__AVR_ATmega2560__)

#define	P_MOSI	B,2
#define	P_MISO	B,3
#define	P_SCK	B,1

//#define	MCP2515_CS			D,3	// Rev A
#define	MCP2515_CS			B,0 // Rev B
#define	MCP2515_INT			D,0
#define LED2_HIGH			B,0
#define LED2_LOW			B,0


#elif defined(__AVR_ATmega328P__)

#define	P_MOSI	B,3
#define	P_MISO	B,4
#define	P_SCK	B,5

//#define	MCP2515_CS			D,3	// Rev A
#define	MCP2515_CS			B,2 // Rev B
#define	MCP2515_INT			D,2
#define LED2_HIGH			B,0
#define LED2_LOW			B,0

#elif defined(__AVR_ATmega1280__)

#else

#endif

I'm no expert, but I think you need a custom entry in 'boards.txt' for your custom board.

That worked perfectly.

Thank you!