Why does make always update this target?

两盒软妹~` 提交于 2019-12-08 08:26:53

问题


Using make on my Gentoo machine (which is GNU make 3.82) with the following Makefile, I wonder why the target data/spectra/o4_greenblatt_296K.dat gets updated every time I execute make data/spectra/o4_greenblatt_296K.dat, even though none of the files params/base/fwhm.dat, params/base/wavelength_grid.dat, and data/raw/o4green_gpp.dat has changed, and the file data/spectra/o4_greenblatt_296K.dat already exists:

FWHM = params/base/fwhm.dat
WLGRID = params/base/wavelength_grid.dat

$(WLGRID): code/create_wavelength_grid.py
    cp code/create_wavelength_grid.py params/base/wavelength_grid.dat

$(FWHM): code/create_fwhm_param.py
    cp code/create_fwhm_param.py params/base/fwhm.dat

data/raw/o4green_gpp.dat:
    echo 1 > data/raw//o4green_gpp.dat

input_spectra_o4_raw: data/raw/o4green_gpp.dat

data/spectra/o4_greenblatt_296K.dat: $(WLGRID) $(FWHM) input_spectra_o4_raw 
    echo 1 > data/spectra/o4_greenblatt_296K.dat

input_spectra_o4: data/spectra/o4_greenblatt_296K.dat

Any help you guys can give a make newbie is greatly appreciated :)


回答1:


I would guess that it's because there is no file named input_spectra_o4_raw, which is a prerequisite of your data/spectra/o4_greenblatt_296K.dat.

The decision looks kind of like this:

1. params/base/wavelength_grid.dat and params/base/fwhm.dat are both up to date
2. check input_spectra_o4_raw - file does not exist, so build it first
3. there is a target for input_spectra_o4_raw, and it's prerequisite
   data/raw/o4green_gpp.dat is up to date, so run all the commands to build 
   input_spectra_o4_raw (there are none, though, so we essentially just mark that we've 
   done everything we need to for input_spectra_o4_raw and that we built it new)
4. we just built input_spectra_o4_raw, so data/spectra/o4_greenblatt_296K.dat is out of 
   date with respect to that prerequisite and needs to be rebuilt

You should research how to use the .PHONY: pseudo-target.



来源:https://stackoverflow.com/questions/18764544/why-does-make-always-update-this-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!