Have a look in your arduino folder for Arduino.h
./hardware/arduino/avr/cores/arduino/Arduino.h
Near the top of the file ~line 71, you can see a bunch of defines for the different MCUs, which you can use for conditional compiling within your own sketch.
#ifdef __AVR_ATmega328P__
//compile for uno
Serial.println("this is an Uno");
#endif
#ifdef __AVR_ATmega2560__
//compile for Mega
Serial.println("this is a mega");
#endif