What do you do when your highly cyclical business must endure a very rough period? If you're smart, you conserve cash. Builders FirstSource's (NASDAQ:BLDR) second-quarter earnings release shows the company doing exactly that.

The Q2 numbers
Nothing on the income statement is pretty. Total sales dropped 27%, although the company estimated that the housing slowdown actually reduced demand by 39%. The difference is an estimated 9% gain in market share.

Gross margin of 25.1% fell 150 basis points from the prior year, as similarly hurting homebuilders demanded lower prices. SG&A expense rose to 21.4% of sales, from 18.3% last year, but in actual dollars, those costs fell by $18.8 million year over year. At $17.1 million, operating income plunged a precipitous 67% from the prior year, and EPS fell to $0.23 from last year's $0.79. Like I said: not pretty.

Thankfully, the balance sheet and cash flow statement show a more encouraging picture. For the first six months of this year, even with earnings down more than 80%, free cash flow increased by $34 million year over year. Lower capital expenditures and careful working capital management (receivables, payables, and inventories) drove that figure up. Working capital has grown from $261 million to $316 million, but that increase mainly owes to cash generation, rather than increases in receivables or inventory. Should the company need a little extra cash, its available borrowing capacity is $108 million.

Executing the strategy
Last fall, the company saw the early warning signs of a severe housing-market downturn. Its strategy to cope included reducing capital spending, cutting expenses, holding margins, and carefully managing working capital. The impressive second-quarter liquidity results show the effectiveness of this approach. Not all companies have the foresight or fortitude to carry off this kind of expense-reduction and cash-conservation effort. The gains in market share Builders has made in the process speak to the relative success of its efforts.

Looking to the future
The company isn't expecting improvements in the housing market anytime soon. In its release, management surprised no one by predicting "difficult market conditions" extending into 2008. Still, investors shouldn't pay much mind to the doom and gloom surrounding Builders FirstSource, even though its stock price has been hammered since early 2006. All building-related stocks will trend lower when the housing market weakens. Both Lowe's (NYSE:LOW) and Home Depot (NYSE:HD) are also suffering compared to their early 2006 numbers, although their hardy retail components have left their shares a bit better off than Builders FirstSource's.

Investors should ask themselves who will emerge from this downturn in a position to benefit strongly from a recovering housing market, and what price might be appropriate for those companies now. Builders FirstSource is a Motley Fool Inside Value recommendation for precisely this reason. Fellow writer Rich Smith compared Builders FirstSource to Home Depot's supply business, concluding that Builders FirstSource looks attractive on a price-to-sales basis. This stock may not be ready for near-term improvements, but second-quarter results show me that the company is positioning itself to be a winner in the future.

For more insights on Builders FirstSource, check out:

Home Depot is also a Motley Fool Inside Value recommendation. Come visit the market-beating newsletter free for 30 days to find out how all intelligent investing is value investing.

Fool contributor Timothy M. Otte surveys the retail scene from Dallas. He welcomes comments on his articles, but doesn't own shares of any companies mentioned in this article. The Fool's disclosure policy is sturdily built.