I am currently trying to convert a series of batch files into powershell scripts. I would like to run the compiler for the source files that exist in the directory, recursively. The compiler requires a long list of arguments. Trap, I want the arguments to be variables, so I can change them as needed. This is a typical call from a batch file (simplified for readability and length):
"C: \ PICC Compilers \ picc18.exe" --pass1 "C: \ Src Files \ somefile.c" "-IC: \ Include Files" "-IC: \ Header Files" -P --runtime = default, + clear, + prim, -keep + download + stackwarn, -config + CLIB, -plib --opt = default, + asm, -speed, + space, 9 --warn = 0 --debugger = realice -Blarge - double = 24 --cp = 16 -g --asmlist "--errformat = Error [% n]% f;% l.% c% s" "--msgformat = Advisory [% n]% s" --OBJDIR = "C: \ Built Files" "--warnformat = Warning [% n]% f;% l.% C% s"
This command runs fine if it is included in the batch file, but I'm starting to get errors when copying and pasting the command in powershell. This is only my second day working with powershell, but I have developed this with .NET in the past. I managed to make the following attempt:
$srcFiles = Get-ChildItem . -Recurse -Include "*.c" $srcFiles | % { $argList = "--pass1 " + $_.FullName; $argList += "-IC:\Include Files -IC:\Header Files -P --runtime=default,+clear,+init,-keep,+download,+stackwarn,-config,+clib,-plib --opt=default,+asm,-speed,+space,9 --warn=0 --debugger=realice -Blarge --double=24 --cp=16 -g --asmlist '--errformat=Error [%n] %f; %l.%c %s' '--msgformat=Advisory[%n] %s' '--warnformat=Warning [%n] %f; %l.%c %s" $argList += "--OBJDIR=" + $_.DirectoryName; &"C:\PICC Compilers\picc18.exe" $argList }
I know that I probably have several problems with the above code, namely how to pass arguments and how I deal with quotes in the argument list. Wrong, it is, it should illustrate what I am trying to achieve. Any suggestions on where to start?