0

In a .bat file I'm executing a compiler with the line

cl -GL -Od -Zi <all .h files> <all .c files>

but I don't know how to reference all .c and .h files in that manner. I was thinking */.c and */.h, but both of those are invalid arguments. Is there any way I could reference all .c and .h files in this manner?

SSEMember
  • 2,103
  • 4
  • 20
  • 28
  • 2
    Masks are typically specified like this: `*.h`, `*.c`. If that's what you meant and actually tried and it didn't work, then please clarify what you are trying to do now. Do you mean you want to invoke the compiler multiple times for every individual pair of a `.h` & a `.c` files? – Andriy M Jun 29 '12 at 18:32
  • No, for some reason the text editor took out what I was refering to. I mean recursively get all .c and .h files from inside a folder and all it's subfolders. I think *.c and *.h only get files from the current directory. – SSEMember Jun 29 '12 at 21:00
  • 2
    Whatever the correct mask might be, I think it's up to the compiler to interpret it, and so the question may have nothing to do with batch scripting (I'm not absolutely sure, though). I.e. if you want to find a way to run the compiler once for all the files, you should refer to the compiler's manual to see if it accepts masks and if there's a way to reference files in subfolders (it might be a command line option instead of a sophisticated mask actually). – Andriy M Jun 29 '12 at 21:12

1 Answers1

0

cl doesn't let you do this, but if you want to compile all C files in every folder starting from a certain point, then you can do something like the following.

Note, with those command options you can't pass in a header file either.


@echo off
set USAGE=Usage: %~n0 "C:\Existent Start Dir"
if %1xx == xx ( echo %USAGE% & exit /b 2 )
if not exist "%~1" ( echo %USAGE% & exit /b 1 )
for /r "%~dpn1" %%f in (.) do (
  pushd %%f
  if exist *.c (
    echo *** Compiling C files in %%f ***
    call cl -GL -Od -Zi *.c
    echo.
  )
  popd
)

Test this with: test.cmd C:\mytest

If C:\mytest contains several folders of simple *.c and *.h files this will work. test.cmd C:\mytest

You might really be wanting to invoke nmake?

azhrei
  • 2,303
  • 16
  • 18