To keep the government operating through September, in first major piece of legislation.

President Donald Trump signed his first piece of major legislation on Friday, a $1 trillion spending bill to keep the government operating through September.

The bill was cleared by both houses of the Congress this week and Mr. Trump signed it into law behind closed doors at his home in central New Jersey, well ahead of a midnight Friday deadline for some government operations to begin shutting down.

But other budget battles lie ahead as the White House and Congress hammer out a spending plan for the fiscal year that starts October 1.

Republicans praised $15 billion in additional Pentagon spending obtained by Mr. Trump, as well as $1.5 billion in emergency spending for border security, though not for the wall he has vowed to build along the U.S.-Mexico border to deter illegal immigration, and the extension of a school voucher program in the District of Columbia.

Wants big military build-up

Mr. Trump also wants a huge military build-up matched by cuts to popular domestic programs and foreign aid accounts. He signed the bill despite his objections to numerous provisions included in the measure. One such provision prohibits the Justice Department from using any funds to block implementation of medical marijuana laws by states and U.S. territories.

In a signing statement that accompanied the bill and that laid out his objections, Mr. Trump said he reserved the right to ignore the provision. He held out the possibility that the administration could pursue legal action against states and territories that legalise marijuana for medical use.

Marijuana remains illegal for any purpose under federal law. The White House previously signalled a looming crackdown on recreational pot use.

“I will treat this provision consistently with my constitutional responsibility to take care that the laws be faithfully executed,” Mr. Trump said in the signing statement, a tool that previous presidents have used to explain their positions on appropriations bills.

On Gitmo

Mr. Trump also objects to provision governing the transfer of prisoners held at a U.S. facility in Guantanamo Bay, Cuba. But the White House said his objection should not be seen as a shift in policy, but as a statement of his view that the provision could conflict with his constitutional authority and duties in some circumstances.

Mr. Trump said during the presidential campaign that he wanted the detention centre, known as “Gitmo,” kept open. At one point, he pledged to “load it up with some bad dudes.”

Republicans and Democrats, who negotiated the spending bill in recent days had successfully defended other accounts Mr. Trump had targeted for spending cuts, such as foreign aid, the Environmental Protection Agency, support for the arts and economic development grants, among others.

The sweeping, 1,665-page bill also increases spending for NASA, medical research, and the FBI and other federal law enforcement agencies.

Mr. Trump took to Twitter earlier this week to complain about the bipartisan process that produced the measure but later changed his tone and began highlighting the spending that was added for the military and for border security. He advocated in one tweet for a “good shutdown” in September to fix the “mess” that produced the bill, but then appeared in the White House Rose Garden hours later to boast that the measure amounted to a big win for him.

In other areas, retired union coal miners won a $1.3 billion provision to preserve health benefits for more than 22,000 retirees. House Democrats won funding to give Puerto Rico’s cash-strapped government $295 million to help ease its Medicaid burden.