I’m assuming you are really asking why the `ifdef’s are being used as a wrapper around the code, not necessarily how they work.
This is a technique take from other languages like C/C++ that have header files that get included in your source code. These header files contain definitions and function prototypes used by your source code. Sometimes you have multiple files that include the same header file, and the `ifdef wrapper prevents the file from being compiled twice. This saves compilation time, and prevents compiler errors in cases where the same definition is not allows to be declared twice.
Sometimes, people put these wrappers around all their code even if they know their compilation scripts only compile their code once. Modules, programs and interfaces are typically not `included, but the wrapper is a hard habit to break.