←to practical programming

Questions "make"

  1. What is the meaning of the following makefile variables: $@, $<, $^, CFLAGS, LDFLAGS, LDLIBS.
    Hint: GNU make manual: automatic variables, implicit variables, implicit rules.

  2. What will the following makefile print (after running command make) and why,

    CFLAGS = -Wall -Ofast -std=c1x
    C = F
    all:
    	echo CFLAGS
    	echo $CFLAGS
    	echo $(C)FLAGS
    	echo $(CFLAGS)
    
  3. Suppose you have your whole C-program in one file main.c. Which of the following makefiles will compile and link the program into the executable file main?

    1. all: main
      
    2. main: main.c
      
    3. main: main.o
      
    4. all: main
      main: main.o
      main.o: main.c
      
    5. all: main
      main.o: main.c
      main: main.o
      
    6. main.o: main.c
      all: main
      main: main.o
      
    7. main: main.c
      	cc main.c -o main
      
    8. main: main.c
      	$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
      
    9. all: main
      main: main.o
      	cc main.o -o main
      main.o: main.c
      	cc -c main.c -o main.o
      
    Remember that the tabulator-sign before the command may not be copy-pasted correctly.