Search code examples
cwindowsmakefilenmakecl

Compiling multiple files using CL


How would this GNU makefile look for windows (I must use nmake and CL):

CC = gcc
CFLAGS = -Wall -Wextra -g

build: main

main: utils.o bucket.o hashset.o main.o

utils.o: utils.c utils.h

bucket.o: bucket.c bucket.h

hashset.o: hashset.c hashset.h

main.o: main.c

.PHONY:
clean:
    rm -f *.o *~ main

All I could come up with was this:

CPP = cl
CFLAGS   = /nologo /W4 /EHsc /Za

build : main

main: utils.obj bucket.obj hashset.obj main.obj
    $(CPP) $(CFLAGS) /Fe$@ $**

utils.obj: utils.c
    $(CPP) $(CFLAGS) /Fo$@ $**

bucket.obj: bucket.c
    $(CPP) $(CFLAGS) /Fo$@ $**

hashset.obj: hashset.c
    $(CPP) $(CFLAGS) /Fo$@ $**

main.obj: main.c
    $(CPP) $(CFLAGS) /Fo$@ $**

clean:
    del *.obj main

Note that my homework was implementing a hashset, which I have done, it's just the makefile that troubles me for now. I keep getting errors for every file: unexpected end of file


Solution

  • Thanks for helping, in the meanwhile I figured out the answer myself:

    CPP = cl
    OBJ_LIST = main.obj utils.obj bucket.obj hashset.obj
    
    build: main
    
    main: $(OBJ_LIST)
        $(CPP) /Fe$@ $**
    
    clean:
        del *.obj main.exe