makefile usa a mesma receita para vários destinos

3

Eu amo esse makefile, mas se eu chamar 'all' ou 'lab4', o nome 'lab4' será construído usando o dbug receipe. se eu chamar 'dbug', o -o 'dbug' e usar o dbug receipe. O que estou fazendo de errado? Eu roubei isso do wiki.osdev.org/Makefile btw

CC := gcc
CFLAGS := -c -Wall -Werror
DBCFLAGS := $(CFLAGS) -DDEBUG -g
LDFLAGS :=
LAB := lab4

PROJDIRS := .
SRCFILES := $(shell find $(PROJDIRS) -maxdepth 1 -type f -name "*.c")
HDRFILES := $(shell find $(PROJDIRS) -maxdepth 1 -type f -name "*.h")
OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
AUXFILES := makefile README
ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)

-include $(DEPFILES) $(TSTDEPFILES)

.PHONY: all clean dist check testdrivers todolist

all: $(LAB)

$(LAB): $(OBJFILES)
    $(CC) $(LDFLAGS) $(OBJFILES) -o $@

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

dbug: $(OBJFILES)
    $(CC) $(LDFLAGS) $(OBJFILES) -o $@

%.o: %.c makefile
    $(CC) $(DBCFLAGS) $< -o $@

todolist:
    -@for file in $(ALLFILES:makefile=); do grep -H -e TODO -e FIXME $$file;     done; true

dist:
    @tar czf /mnt/backup/cis27/$(LAB)-'date +%m%d%y.%H%M'.tar.gz $(ALLFILES)

clean:
    -rm *.o *~ *.d 
    
por skinney6 08.03.2014 / 19:47

1 resposta

1

Eu mudei o makefile um pouco. A principal diferença é

dbug: 
    @$(MAKE) CFLAGS="$(DBCFLAGS)" LDFLAGS="$(DBLDFLAGS)"

Então, se você executar make dbug CFLAGS e LDFLAGS serão redefinidos novamente.

CC := gcc
CFLAGS = -O2 -c -Wall -Werror
DBCFLAGS = $(CFLAGS) -O0 -DDEBUG -g
LDFLAGS =
DBLDFLAGS = $(LDFLAGS) -g
LAB := lab4

PROJDIRS := .
SRCFILES := $(shell find $(PROJDIRS) -maxdepth 1 -type f -name "*.c")
HDRFILES := $(shell find $(PROJDIRS) -maxdepth 1 -type f -name "*.h")
OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
TSTFILES := $(patsubst %.c,%_t,$(SRCFILES))
AUXFILES := makefile README
ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)

-include $(DEPFILES) $(TSTDEPFILES)

.PHONY: all clean dist check testdrivers todolist

all: $(LAB)

dbug: 
        @$(MAKE) CFLAGS="$(DBCFLAGS)" LDFLAGS="$(DBLDFLAGS)"

$(LAB): $(OBJFILES)
        $(CC) $(LDFLAGS) $(OBJFILES) -o $@

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

todolist:
        -@for file in $(ALLFILES:makefile=); do grep -H -e TODO -e FIXME $$file;     done; true

dist:
        @tar czf /mnt/backup/cis27/$(LAB)-'date +%m%d%y.%H%M'.tar.gz $(ALLFILES)

clean:
        -rm *.o *~ *.d 
    
por 08.03.2014 / 22:02

Tags