NEW YORK — Major stock indexes eked out small gains Tuesday after an upturn in technology companies outweighed weakness in other parts of the market, including a drop in airlines.

The gain in technology stocks was driven by Apple. The technology company surged after billionaire investor Carl Icahn said on Twitter that he held a large position in Apple and that its stock was undervalued.

August is shaping up to be a lackluster month for the stock market as major indexes fail to add significantly to the gains they made in July. The Standard & Poor's 500 index has drifted lower, fluctuating between small losses and gains, since closing at an all-time high Aug. 2.

A sharp rise in Treasury yields also rippled through the stock market on Tuesday.

The yield on the 10-year note climbed to 2.72 percent, close to its highest in two years, on the latest signs that Europe is emerging from its recession. Industrial production in the 17 countries that use the euro rose in June and investor confidence increased in Germany, the region's biggest economy.

The sharp rise in yields lifted financial companies because higher interest rates could help them generate better profit margins. That helped offset declines in homebuilders and other stocks that are sensitive to rising borrowing costs.

The yield is also climbing on speculation that the Federal Reserve will cut its stimulus as the economy recovers. Atlanta Fed President Dennis Lockhart said Tuesday that it was too early to say when the bank would ease back on its stimulus, but hinted that it would likely happen before the end of the year.

"You could argue that stocks would be up higher today if the bond market was behaving," said John Canally, Investment Strategist for LPL Financial. "The market's trend right now is higher."

Homebuilder stocks slid on concern that mortgage rates will climb, raising the cost of buying a home and potentially blunting a recovery in the housing market. The stocks of phone companies and utilities that typically pay big dividends also fell. Those stocks have been slumping as Treasury yields have risen, because some investors had been buying them as an alternative to bonds as a source of investment income.

Airline stocks slumped after the federal government challenged the proposed merger of US Airways and American Airlines, a deal between two of the largest carriers. The government says the deal would result in "substantial harm to consumers" in higher fares and fees.

Major indexes started slightly higher, drifted lower at mid-morning, and were back up again in the afternoon. Trading has been unusually light this week and last as many investors take vacation.

"The market is drifting and consolidating here, and we think this is likely (to continue) over the next week or so," said Jim Russell, a Regional Investment Director at US Bank.

The S&P 500 index rose 4.69 points, or 0.3 percent, to 1,694.16. Although its advance has slowed this month, the index is still up 18.8 percent this year.

The Nasdaq composite rose 14.49 points, or 0.4 percent, to 3,684.44. The Dow Jones industrial average rose 31.33 points, or 0.2 percent, to 15,451.01.

Other indexes fell. The Dow Jones Transportation average dropped 42.48, or 0.7 percent, to 6,452, dragged down by the slump in airline stocks. Indexes measuring utilities and small-company stocks also fell.

In government bond trading, the yield on the 10-year Treasury note jumped to 2.72 percent from 2.62 percent Monday. The yield is used as a benchmark to set interest rates on many kinds of loans including home mortgages.

In commodities trading, the price of oil rose 72 cents, or 0.7 percent, to $106.83 a barrel. Gold dropped $13.70, or 1 percent, to $1,320.50 an ounce.

The dollar rose against the euro and the Japanese yen.

Among stocks making big moves:

— J.C. Penney fell 49 cents, or 3.7 percent, to $12.68. The struggling department store chain faces an uncertain future after activist investor William Ackman resigned from the company's board.

— Yum Brands, which owns the Taco Bell, Pizza Hut and KFC fast-food chains, slumped $1.50, or 2 percent, to $72.97 after reporting that its sales in China fell 13 percent in July.

— Eli Lilly and Co. rose $1.40, or 2.6 percent, to $54.96 after the company said its potential lung cancer treatment necitumumab met a key research goal by helping to increase survival time for patients in a late-stage study.

— PulteGroup fell 36 cents, or 2.3 percent, to $15.37, leading a broad decline in homebuilder stocks.

— US Airways plunged $2.46, or 13.1 percent, to $16.36. Other airlines also fell. Delta Air Lines dropped $1.49, or 7.1 percent, to $19.55 and United Continental fell $2.48, or 7.5 percent, to $30.73.