You do this by measuring productivity in terms of what each person actually achieves each day, not by how many hours they spend in the office.
I have done this for a development team by agreeing milestones and targets for my team with both the developers involved and the internal customers. The devs are then responsible for hitting their targets, and notifying everyone else if they slip or are unable to meet them. The customers are responsible for notifying everyone if the requirements or context changes. I was responsible for notifying everyone if the priorities changed.
It then became the dev's responsibility to determine how many and which hours they needed to work to achieve the goals set, with some simple rules (like a maximum of 8 hours coding per day and 6 days working in a row). We had some weekly meetings that the entire team needed to show up at, otherwise it was their call. They could work from home or from the office, although we generally preferred office because of the network effects. If they completed a task early, they got to go home if they wanted (some didn't).
We got some flak from other departments because it appeared to them that we were never around, but they got used to it. The fact that we were consistently hitting deadlines was a HUGE plus to the whole thing; they could see this worked. As a bonus, we had decent support cover for some of the evening and night shifts as there were devs who preferred working those hours.
TL;DR: Don't measure people on how long they sit behind their desks. Measure them on what they actually do. Then set targets based on what you expect someone to do in a week. Then send them home once they've hit target. To grow the company, set harder targets.