Encountered lousy boo-boo in arduino IDE generated compilation commands

From my observation this is what I learned:

  1. The sketch files in the sketch folder are compiled with path to their required headers in alphabetic order.
  2. Then standard and contributed library .cpps are built in the order their headers show up in the main sketch. This includes things like LiquidCrystal or my own library.
  3. Then the arduino core library .cpps are build in an unknown fashion, probably in the order they were enumerated in a file or mentioned in arduino.h. This includes all the wiring stuff, hardware serial, etc.

All above compiled .o files reside in the same temp folder as Paul mentioned, including the source file in step 1. After that some linker options (I can't understand fully) to mention all the .o file to be linked.