Gnu Makefile - Handling dependencies

后端 未结 12 2505
滥情空心
滥情空心 2021-02-07 20:24

What approach do C++ programmers on Unix platform use to create and manage Makefiles?

I was using hand made Makefiles for my projects but they don\'t handle header file

12条回答
  •  你的背包
    2021-02-07 21:03

    I use BSD make (pmake?) which does lot of work for me (my lang is C, but I think no difference here). This is my common 'local.prog.mk', I never change it:

    .PHONY: tags .depend
    
    # .depend depends only on $(SRCS) in bsd.dep.mk, so we can't track changes of
    # header's own dependencies properly. so .depend is .PHONY target here.
    
    CSTD    ?=c99
    WARNS   ?=9
    .if !empty(PC_LIST)
    PC_CF   !=pkg-config --cflags $(PC_LIST)
    PC_LD   !=pkg-config --libs   $(PC_LIST)
    .endif
    CFLAGS  +=$(PC_CF) -fgnu89-inline
    .if !defined(NO_DEBUG)
    CFLAGS  +=-O0 -ggdb3
    .endif
    LDFLAGS +=$(PC_LD)
    CTAGS   =exctags
    
    NO_MAN=
    NO_OBJ=
    CLEANFILES+=$(PROG).core
    
    .include 
    $(PROG): $(SUBDIR)
    build: clean cleandepend depend all
    run: $(PROG)
        ./$(PROG)
    

    Note 'bsd.prog.mk' inclusion -- this handles all, build, depend, clean targets. Project-specific BSDmakefiles are simple:

    .SILENT:
    
    PROG    =hello
    SRCS    =hello.c world.c
    PC_LIST =gtk+-2.0 gnet-2.0
    
    .include "../local.prog.mk"
    
    proto:
        cproto -siv `pkg-config --cflags $(PC_LIST)` $(SRCS) > prototypes
    CLEANFILES+=prototypes
    

    I just make depend every time I insert/remove any #include directives.

提交回复
热议问题