English 中文(简体)
报表一
原标题:Makefile : Exclude a dependency from $^

I m 编印Lex和Yacc。 为了汇编我的<代码>main,首先需要打上文件ytab.h。 然而,我不想将这一档案列入<代码>$的变数中,因为汇编者不喜欢把该文档列入main

是否有办法使这一规则/对应办法取决于y.tab.h ,但将其排除在$^/code>之外?

如果不是的话,(如果这个问题是一个XY问题的话),是否有更好的办法来安排这一文件,以实现这一目标?

我在此作如下陈述:

targets := ccpy

################################### Options ####################################

cc            := gcc
cFlags        := -c -O3
cFlagsLenient := $(cFlags) -w
cFlagsHard    := $(cFlags) -Wall -pedantic
cFlagsDebug   := -c -W -Wall -pedantic -g -Og
ldFlags       := -lm -ly -ll
ldFlagsDebug  := -g $(ldFlags)

################################### Folders ####################################

binDir   := ./bin
debugDir := ./debug
objDir   := ./obj
srcDir   := ./src
testDir  := ./test

################################ File categories ###############################

mains    := $(targets:%=$(objDir)/%.o)

srcL     := $(wildcard $(srcDir)/*.l)
srcY     := $(wildcard $(srcDir)/*.y)

outL     := $(srcL:$(srcDir)/%.l=$(srcDir)/%.c)
outY     := $(srcY:$(srcDir)/%.y=$(srcDir)/%.c)

objL     := $(outL:$(srcDir)/%.c=$(objDir)/%.o)
objY     := $(outY:$(srcDir)/%.c=$(objDir)/%.o)
cleanY   := $(outY) $(srcY:$(srcDir)/%.y=$(srcDir)/%.h) $(srcDir)/y.output $(srcdir)/y.gv

srcC     := $(filter-out $(outL) $(outY), $(wildcard $(srcDir)/*.c))
objC     := $(srcC:$(srcDir)/%.c=$(objDir)/%.o)

obj      := $(objC) $(objL) $(objY)
objDebug := $(obj:$(objDir)/%.o=$(debugDir)/%.do)

srcTest  := $(wildcard $(testDir)/*.c)
tests    := $(srcTest:$(testDir)/%.c=$(binDir)/%)

#################################### Recipes ###################################

# Basic
all  : $(targets)
again : clean all
debug: $(targets:%=%.db)
test : $(tests)
objects: $(obj)

# Check Variables
info: 
    $(info mains    : $(mains))
    $(info srcC     : $(srcC))
    $(info objC     : $(objC))
    $(info srcL     : $(srcL))
    $(info outL     : $(outL))
    $(info objL     : $(objL))
    $(info srcY     : $(srcY))
    $(info outY     : $(outY))
    $(info objY     : $(objY))
    $(info obj      : $(obj))
    $(info objDebug : $(objDebug))
    $(info srcTest  : $(srcTest))
    $(info tests    : $(tests))

# Final Executables
$(targets): % : $(objDir)/%.o $(obj)
    $(cc) -o $@ $^ $(ldFlags)

# Objects directly compiled from C
$(objC): $(objDir)/%.o : $(srcDir)/%.c
    $(cc) $(cFlagsHard) $^ -o $@

# Objects made by Lex and Yacc
$(objL) $(objY): $(objDir)/%.o : $(srcDir)/%.c
    $(cc) $(cFlagsLenient) $^ -o $@

# Files made by Lex
$(outL): $(srcDir)/%.c : $(srcDir)/%.l $(outY)
    lex -o $@ $<

# Files made by Yacc
$(outY): $(srcDir)/%.c : $(srcDir)/%.y
    yacc -v -d -Wcounterexamples --file-prefix="$(srcDir)/y" $^

# Debug executables (outdated)
$(targets:%=%.db): $(objDebug)
    $(cc) -o $@ $^ $(ldFlagsDebug)

# Debug objects (outdated)
$(objDebug): $(debugDir)/%.do : $(srcDir)/%.c
    $(cc) $(cFlagsDebug) $^ -o $@

# Automated testing
$(tests): $(binDir)/%_test : $(testDir)/%_test.c $(filter-out $(mains), $(obj))
    $(cc) -o $@ $^ $(ldFlags) 
    $@

clean: 
    rm -rf $(objDir)/*.o $(debugDir)/*.do $(targets) $(tests) $(cleanY) $(outL)

问题回答

更改<代码>$$(filter-out %.h,$^)/code>。 <代码>过滤-out功能除去了与模型相符的所有词语(非太阳特性的频率)。

总的来说,在compiling source file(而不是链接)时,你要具体说明single。 提交single的物体档案。 这正是<代码>$<,因为你只想像:

$(objDir)/%.o: $(srcDir)/%.c
        $(CC) $(CFLAGS) -c $< -o $@

鞭.将使你能够单独汇编每个来源的指挥。 如果你试图以汇编者单一发票汇编多种来源档案,那么你会遇到麻烦,因为你可以随后使用<代码>-o,以具体说明产出,因此,你最终以与文件目录或现行工作名录相同的目录(取决于您的C汇编者如何工作)上的所有卷宗。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签