makefiles - compile all c files at once

后端 未结 3 1610
心在旅途
心在旅途 2020-12-07 13:10

I want to experiment with GCC whole program optimizations. To do so I have to pass all C-files at once to the compiler frontend. However, I use makefiles to automate my buil

相关标签:
3条回答
  • 2020-12-07 13:45
    SRCS=$(wildcard *.c)
    
    OBJS=$(SRCS:.c=.o)
    
    all: $(OBJS)
    
    0 讨论(0)
  • 2020-12-07 13:59

    You need to take out your suffix rule (%.o: %.c) in favour of a big-bang rule. Something like this:

    LIBS  = -lkernel32 -luser32 -lgdi32 -lopengl32
    CFLAGS = -Wall
    
    OBJ = 64bitmath.o    \
          monotone.o     \
          node_sort.o    \
          planesweep.o   \
          triangulate.o  \
          prim_combine.o \
          welding.o      \
          test.o         \
          main.o
    
    SRCS = $(OBJ:%.o=%.c)
    
    test: $(SRCS)
        gcc -o $@  $(CFLAGS) $(LIBS) $(SRCS)
    

    If you're going to experiment with GCC's whole-program optimization, make sure that you add the appropriate flag to CFLAGS, above.

    On reading through the docs for those flags, I see notes about link-time optimization as well; you should investigate those too.

    0 讨论(0)
  • 2020-12-07 14:06
    LIBS  = -lkernel32 -luser32 -lgdi32 -lopengl32
    CFLAGS = -Wall
    
    # Should be equivalent to your list of C files, if you don't build selectively
    SRC=$(wildcard *.c)
    
    test: $(SRC)
        gcc -o $@ $^ $(CFLAGS) $(LIBS)
    
    0 讨论(0)
提交回复
热议问题