It was not long ago that U.S. President Donald Trump declared Afghanistan "a complete waste."

This week, as well as threatening to rip up NAFTA and shut down the U.S. government if Congress doesn't ante up for his Mexican wall, Trump made an open-ended commitment to keep spending money in Afghanistan that his predecessor Barack Obama never would.

While most experts say the first two will hurt the U.S. economy, the third will mean a long-term investment in a business where the U.S. is the undisputed leader.

The biggest spenders

According to the CIA's World Factbook, U.S. military spending ranks ninth in the world as a percentage of total economic output. But in absolute terms, the country is clearly top dog, in 2016 spending about three times as much as China and approaching 10 times as much as Russia, says the Stockholm International Peace Research Institute.

The ones that spend more as a percentage of GDP are smaller countries at war or those like Israel that foresee an imminent threat.

Large as U.S. military spending is today, it is dwarfed by the relative size of the country's military might in 1961 when Republican President Dwight Eisenhower warned in his farewell speech about what he called the military-industrial complex.

"In the councils of government, we must guard against the acquisition of unwarranted influence, whether sought or unsought, by the military-industrial complex," said Eisenhower, who had been supreme commander of Allied troops invading Europe in the Second World War.

Eisenhower worried that the growing clout of the military in the U.S. economy and all walks of life could overwhelm other parts of American life.

'Huge industrial and military machinery'

Why are we continuing to train these Afghanis who then shoot our soldiers in the back? Afghanistan is a complete waste. Time to come home! —@realDonaldTrump "The potential for the disastrous rise of misplaced power exists, and will persist," he said. "Only an alert and knowledgeable citizenry can compel the proper meshing of the huge industrial and military machinery of defence with our peaceful methods and goals so that security and liberty may prosper together."

Some have said that Trump's change of heart on Afghanistan five years after this tweet can be attributed to the generals on his White House team, "a textbook case of how personnel is policy," opined Politico.

In July, former general John Kelly became Trump's chief of staff. Many hoped the appointment would bring calm to a White House in chaos, but it also increased the influence of the military. (Joshua Roberts/Reuters) Former U.S. Marines general John Kelly is Trump's powerful chief of staff. Former general James (Mad Dog) Mattis is head of defence.

Another Trump-appointed former general, Michael Flynn, was ejected from his job as national security adviser after failing to reveal contacts with Russia, only to be replaced in the job by another general, H.R. McMaster.

No matter what government is in power, lobbyists and think-tanks are always pushing for military spending, often with success. But having so many generals close to the seat of power inevitably makes things easier for them, says Donald Abelson, author of the book Do Think Tanks Matter?, heading into its third edition this autumn.

Along with the best known military think-tanks like the Rand Corporation and the Hudson Institute, smaller groups such as the Centre for Security Policy, an anti-jihadist conservative group that favours missile defence spending, are gaining influence.

"CSP is doing quite well now because they would have strong connections to the generals in the Trump White House," says Abelson, a specialist in U.S. foreign policy at Ontario's Western University.

More than a spending ploy

Keeping troops in Afghanistan is not just a military spending ploy.

“Invincibility lies in the defence; the possibility of victory in the attack.” - Sun Tzu —@realDonaldTrump Pulling out and declaring defeat would be a political disaster that would only add to a series of political disasters for this administration, especially for Trump's core supporters primed with promises of "invincibility."

Despite his early plan to extract troops from the Afghanistan quagmire, Trump has never opposed military spending.

A U.S. Marines MV-22 Osprey flies over a jet before landing on the deck of an amphibious assault ship. Raising U.S. military spending creates jobs, but it also means cuts in other government activities. (Jason Reed/Reuters) "Hopefully we'll never have to use it, but nobody is going to mess with us. Nobody," he announced in April while promising a hike in the defence budget at the expense of other programs.​

Abelson listened to Trump's entire speech at this week's rally in Phoenix, Ariz.

"He talked about how during his administration the United States will witness the greatest military buildup in the history of the country. Who benefits? Well, the Pentagon benefits, defence contractors benefit and workers in particular states benefit," says Abelson.

From a military perspective there are other reasons to keep soldiers close to the action despite the human cost of war. Experienced or battle-hardened militaries perform better when called upon for real action.

But when it comes to Trump's crowd-pleasing proclamations, whether on NAFTA, shutting down the U.S. government or boosting military spending, it is always difficult to separate politics from policy.

Abelson says increasing military spending may create some of the "American jobs" Trump has promised, but at what cost?

"The military-industrial complex is alive and well," says Abelson. "It's one of the staples of the U.S. economy. But the issue is, if money is going into defence, what is it not going into?"

Follow Don @don_pittis

More analysis from Don Pittis