For simple programs, special compiler commands can be used. For large projects, it is best to use a standard Makefile.
The MPICH implementation provides the commands mpicc and mpif77 as well as Makefile examples in /usr/local/mpi/examples/Makefile.in