If you really need different flags for cl.exe for different TUs, then I really think it is much easier to start use regular buildsystem like makefiles than hack up bat files. Result will be more readable and more maintainable.
Here's example with simple makefile that builds one executable with automatic dependency tracking. I use this template for most of my Linux stuff.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 | CC := clang
CFLAGS := -pipe -fPIE -fpie -fvisibility=hidden \
-std=c99 -ffast-math \
-Wall -Wextra -Werror \
-MMD
LDFLAGS :=
# debug
CFLAGS += -O0 -g
LDFLAGS +=
# release
#CFLAGS += -O3 -fdata-sections -ffunction-sections
#LDFLAGS += -s -Wl,-z,relro,-z,now,-gc-sections
SRC := file1.c \
file2.c \
other.c \
whatever.c \
OBJ := ${SRC:.c=.o}
DEP := ${SRC:.c=.d}
TARGET := target.exe
.PHONY: all clean
all: ${TARGET}
clean:
rm -f ${OBJ} ${DEP}
${TARGET}: ${OBJ}
@echo [L] ${TARGET}
@${CC} ${LDFLAGS} -o $@ $^
%.o: %.c Makefile
@echo [C] $<
@${CC} ${CFLAGS} -c -o $@ $<
-include ${DEP}
|
This is written for Linux and uses clang, but you can easily adjust it to use cl.exe and run on Windows.
Save it as "Makefile" and invoke it "make -j4" and it will compile everything in 4 codes as much as possible.
It should be pretty obvious how to extend it to support multiple target executables and different flags for different set of C files.