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 cleared both houses of Congress this week and 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.

Trump 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, 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 legalize marijuana for medical use.

Marijuana remains illegal for any purpose under federal law. The White House previously signaled 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,” Trump said in the signing statement, a tool that previous presidents have used to explain their positions on appropriations bills.

Trump also objects to a 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.

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

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 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.

Trump also wants a huge military buildup matched by cuts to popular domestic programs and foreign aid accounts.

Republicans and Democrats who negotiated the spending bill in recent days had successfully defended other accounts 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.

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.

Associated Press writer Andrew Taylor in Washington contributed to this report.