One of the build targets of the Solidity repository is solc, the solidity commandline compiler.
Using solc--help provides you with an explanation of all options. The compiler can produce various outputs, ranging from simple binaries and assembly over an abstract syntax tree (parse tree) to estimations of gas usage.
If you only want to compile a single file, you run it as solc--binsourceFile.sol and it will print the binary. Before you deploy your contract, activate the optimizer while compiling using solc--optimize--binsourceFile.sol. If you want to get some of the more advanced output variants of solc, it is probably better to tell it to output everything to separate files using solc-ooutputDirectory--bin--ast--asmsourceFile.sol.

The commandline compiler will automatically read imported files from the filesystem, but
it is also possible to provide path redirects using prefix=path in the following way:

This essentially instructs the compiler to search for anything starting with
github.com/ethereum/dapp-bin/ under /usr/local/lib/dapp-bin and if it does not
find the file there, it will look at /usr/local/lib/fallback (the empty prefix
always matches). solc will not read files from the filesystem that lie outside of
the remapping targets and outside of the directories where explicitly specified source
files reside, so things like import"/etc/passwd"; only work if you add =/ as a remapping.

If there are multiple matches due to remappings, the one with the longest common prefix is selected.

For security reasons the compiler has restrictions what directories it can access. Paths (and their subdirectories) of source files specified on the commandline and paths defined by remappings are allowed for import statements, but everything else is rejected. Additional paths (and their subdirectories) can be allowed via the --allow-paths/sample/path,/another/sample/path switch.

If your contracts use libraries, you will notice that the bytecode contains substrings of the form __LibraryName______. You can use solc as a linker meaning that it will insert the library addresses for you at those points:

Either add --libraries"Math:0x12345678901234567890Heap:0xabcdef0123456" to your command to provide an address for each library or store the string in a file (one library per line) and run solc using --librariesfileName.

If solc is called with the option --link, all input files are interpreted to be unlinked binaries (hex-encoded) in the __LibraryName____-format given above and are linked in-place (if the input is read from stdin, it is written to stdout). All options except --libraries are ignored (including -o) in this case.

If solc is called with the option --standard-json, it will expect a JSON input (as explained below) on the standard input, and return a JSON output on the standard output.

These JSON formats are used by the compiler API as well as are available through solc. These are subject to change,
some fields are optional (as noted), but it is aimed at to only make backwards compatible changes.

The compiler API expects a JSON formatted input and outputs the compilation result in a JSON formatted output.

Comments are of course not permitted and used here only for explanatory purposes.