How to reduce code size in flash of atmega8?
Did you set the optimization flag as -Os (optimize for size)? Other tips:

In Atmel Studio:


check "Prepare functions for garbage collection (-ffunction-sections)"
check "Prepare data for garbage collection (-fdata-sections)"
check "Pack Structure members together (-fpack-struct)"
check "Garbage collect unused sections (-WI, --gc-sections)"


Also 


don't use printf or similar bloated stuff
utilize code reuse when possible (easier with C++ class derivation, method overriding etc)
check lst &amp; map files for other hints