The art of achieving good sustain begins with how well the strings are anchored at both ends of the scale. You could follow all the best rules of thumb in terms of wood, neck attachment and pickup selection, but if you ignore how well the strings are anchored at the nut and bridge, you're bound to be disappointed.
In an ideal situation, only the very bottom of each string should contact a knife-like edge where it leaves the nut and bridge. At the nut, no part of the slot should be in contact with the string except on the knife-like edge at the face. Same with the bridge. The string should only touch a knife-like edge as it leaves the saddle. No other part of the saddle's slot should be in contact with the string. This is how you achieve optimal bell-like sustain.
In the real world, however, this approach doesn't last very long since the strings act like mini grinders when played against these sharp edges. As a result, optimal sustain begins to fade as a guitar is played over time. How fast this happens depends on playing style, string gauge and tunings.
To achieve a good balance between optimal sustain and how long it will last requires slightly rounding off the knife-like edge. Unfortunately, the degree to which you round off the edges takes some practice and experience to master. However, if you have a guitar that lacks sustain, check the slots at the nut and bridge to make sure the strings aren't contacting too much of their respective slots. You should be able to press the strings down into the slot behind the face of the nut and bridge saddles. They should also move slightly from side to side behind the face of the nut and saddles. If there is no movement in any direction, it's likely the strings are in contact with the length of the slot and that, my friends, is what kills sustain.