President Trump has held out as long as he can on the wall. But now it’s time for him to pack it in.

He never really made the sale, except with the 30 percent of hard-core supporters who chanted “Build the Wall!” Or with the band of online yes-men who support everything he does.

For the rest of us, we never quite understood about walls. We aren’t engineers. We aren’t in the construction business. We don’t know walls from fences, and we don’t know whether the Border Patrol can do the job without a wall. We have heard ­arguments both ways.

Mind you, I’m disposed to think that we need a wall. Or a fence. But it isn’t the biggest ­immigration issue out there. What is more important is our crazy legal-immigration system.

Unlike other countries, we don’t select immigrants on the basis of whether they would make life better for Americans. If backing merit-based immigration is right wing, then call the Canadians right wing, because that is how they choose newcomers.

But good arguments don’t matter when you can’t make the sale. The RAISE Act, a merit-based ­immigration bill introduced in 2017 by Sens. Tom Cotton and David Perdue, never got off the ground, and a new Rasmussen poll suggests most Americans want Trump to yield on the wall. He lost the independent voters in the November congressional elections, and now he’s lost them over the shutdown.

November should have sent him the message that we wanted him to chill. We are getting tired of the drama. Instead, Trump doubled down. It’s time to reverse course.

Trump is adversarial by nature, and I can sympathize. The media have been unremittingly hostile to him since his inauguration. And the hectoring from NeverTrumpers, including those in the GOP establishment and even the White House, inclines the president to listen to his hard-core supporters.

But that has been a mistake and requires a correction. It is time for him to stop paying ­attention to people who tell him not to give in. And if they are in the White House, to fire them. They are like British military advisers who didn’t want to bring the troops home from Dunkirk. But now it is time for a strategic retreat, to fight again on issues that are winnable.

There is even a way to do it gracefully. The Framers intended that funding bills should come from the House of Representatives, and gave them the power to micromanage appropriations.

They feared what George Mason called an “elective monarch” in the White House, the sort of person who would override the House by declaring an emergency. That is the dismal path toward one-man rule that other presidential governments have followed, and over time it has meant a loss of freedom in those countries.

That was the way Obama governed, bypassing Congress to make up rules on his own. “I’ve got a pen,” he said, and ignored a Republican Congress when it ­refused to pass an immigration law he wanted. Conservatives faulted him for that, and if we aren’t hypocrites, we need to ­oppose any attempt by Trump to employ emergency powers to build the wall without congressional ­approval.

Trump should sign the funding bill the House sends him and end the impasse. And in so doing, he should tell us he would be acting in the manner the Framers ­intended.

He can also say that he has stood up for the American people as long as he could, in the face of Democratic indifference. In their refusal to compromise over any effort to enforce our borders, the Democrats have flipped the bird at Americans. Compared to the people streaming across the border, we don’t matter to them.

That was the great issue in the 2016 election. We got the sense that the other Republican candidates were wedded to abstract economic dogmas, and that the Democrats were in bed with a bicoastal elite, and that neither much cared about the steel worker in Pennsylvania.

With Trump, the Republican Party has made a start on shifting course, notwithstanding all the NeverTrumpers. But the Democrats haven’t changed a bit. Encouraged by the Trump haters in the media, they have become even more radical and abandoned sensible middle-of-the-road positions that were mainstream for the left just a few years ago.

Their new policies are idiotic and will cost them elections. Trump Republicans need to ­oppose them — but only within the spirit of the Constitution.

F.H. Buckley teaches at Scalia Law School and is the author of “The Republican Workers Party: How the Trump Victory Drove Everyone Crazy, and Why It Was Just What We Needed.”