If you ever purchase a new vehicle through a manufacturer purchase program you receive a copy of the invoice, it shows what the dealer paid for the vehicle, the factory holdback and any ad fees for that particular manufacturer. It is not voodoo. The cost listed on this sheet has little to do with what it costs the dealer to sell the car but it is a starting point. Floor plan financing, holding costs, rebates, incentives all factor in to the final cost. The market determines what a given vehicle is worth, if a dealer does not make profit they go under. Pretty simple concepts at play here.
A car dealership is a business, they are not inherently evil or the bad guys they are sometimes made out to be. People get all bent out of shape over invoice price and what amounts to 1% or so then turn right around and finance a depreciating asset. To each his own and all but it is almost comical.
You can read the financial statements for publicly traded dealerships to better understand where a dealership makes money. For example this 2012 annual report for sonic automotive:
http://phx.corporate-ir.net/External.File?item=UGFyZW50SUQ9MTc5MTM3fENoaWxkSUQ9LTF8VHlwZT0z&t=1
For that company 56% of their revenue came from new vehicle sales while 47% of profit came from fixed operations. There is no second set of books, it is all there for anyone to read. Margin is low on new vehicles.
As a consumer I would rather buy factory direct and cut out the cost of the middlemen, but I do appreciate the service a dealership provides. Just look at Tesla motors and the state of Texas if you want to see a circus...