简体   繁体   中英

Where do i put CFLAGS in this makefile? Need the -g so i can use gdb debugger

I'm not used to this style of makefile my teacher created for one of our homeworks because it doesn't have the gcc command in it. Here is the makefile. All I need to know is where to put the -g cflag.

    ### Architecture choice

    #Uncomment for 64-bit
    LIBRARY = libmtron.a

    #Uncomment for 32-bit
    #LIBRARY = libmtron32.a

    ### File lists
    BINS = simulate
    OBJS = driver.o

    ### Phony targets all/clean

    .PHONY: all clean

    all: $(BINS)

    clean: 
        $(RM) $(BINS) $(OBJS)

    ### Build rules

    # Be sure to link in the library
    $(BINS): $(OBJS) $(LIBRARY)

    # update if the header file is changed
    driver.o: driver.h mtron.h

    simulate: mtron.h

Thanks for any help!

This makefile is utilizing make's built-in set of rules to create the objects and link executables, rather than having you type them in yourself.

Make has a default rule that looks (more or less) like this:

%.o : %.c
        $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

If you don't specify any rule yourself to build a .o and make needs to build one and it has a .c , it will use the default built-in rule.

So, the answer to your question is, "put the assignment of CFLAGS wherever you want". Wherever you put it, it will be used by the default rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM