Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #18884 > unrolled thread

Makefile doesn't detect header file change

Started bylovecreatesbeauty <lovecreatesbeauty@gmail.com>
First post2012-03-19 19:15 -0700
Last post2012-03-20 11:48 -0700
Articles 6 — 4 participants

Back to article view | Back to comp.lang.c


Contents

  Makefile doesn't detect header file change lovecreatesbeauty <lovecreatesbeauty@gmail.com> - 2012-03-19 19:15 -0700
    Re: Makefile doesn't detect header file change Ian Collins <ian-news@hotmail.com> - 2012-03-20 15:46 +1300
    Re: Makefile doesn't detect header file change Kaz Kylheku <kaz@kylheku.com> - 2012-03-20 02:48 +0000
      Re: Makefile doesn't detect header file change lovecreatesbeauty <lovecreatesbeauty@gmail.com> - 2012-03-19 23:08 -0700
      Re: Makefile doesn't detect header file change lovecreatesbeauty <lovecreatesbeauty@gmail.com> - 2012-03-20 02:32 -0700
        Re: Makefile doesn't detect header file change Keith Thompson <kst-u@mib.org> - 2012-03-20 11:48 -0700

#18884 — Makefile doesn't detect header file change

Fromlovecreatesbeauty <lovecreatesbeauty@gmail.com>
Date2012-03-19 19:15 -0700
SubjectMakefile doesn't detect header file change
Message-ID<5ff2f2a1-d2e7-4c2b-bd24-d728d7588904@9g2000pbn.googlegroups.com>
My Makefile doesn't detect the change of header files.

This little makefile follows sec 2.6 of GNU make manual, and I
remember it worked before when header files changed.

Where am i wrong?

Thanks

$ touch b.h
$ make
make: `a.out' is up to date.
$

$ pwd
/home/ljh/temp/src
$ ls
a.c  b.c  b.h  Makefile
$ cat Makefile
CC      = gcc
CFLAGS  = -ansi -pedantic -Wall -W
LDFLAGS =
OBJS    = a.o b.o
OUT     = a.out

$(OUT)  : $(OBJS)
        $(CC) $(LDFLAGS) $^ -o $@

a.c b.c : b.h

.PHONY  : clean

clean   :
        rm $(OUT) $(OBJS)

$ make
gcc -ansi -pedantic -Wall -W    -c -o a.o a.c
a.c: In function ¡®main¡¯:
a.c:7: warning: implicit declaration of function ¡®b¡¯
gcc -ansi -pedantic -Wall -W    -c -o b.o b.c
gcc  a.o b.o -o a.out
$ touch b.c
$ make
gcc -ansi -pedantic -Wall -W    -c -o b.o b.c
gcc  a.o b.o -o a.out
$ make
make: `a.out' is up to date.
$ touch b.h
$ make
make: `a.out' is up to date.
$
$ make -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i486-pc-linux-gnu
$ uname -a
Linux debian 2.6.32-5-686 #1 SMP Mon Jan 16 16:04:25 UTC 2012 i686 GNU/
Linux
$ cat /etc/debian_version
6.0.4
$

[toc] | [next] | [standalone]


#18886

FromIan Collins <ian-news@hotmail.com>
Date2012-03-20 15:46 +1300
Message-ID<9sq9biFuerU2@mid.individual.net>
In reply to#18884
On 03/20/12 03:15 PM, lovecreatesbeauty wrote:
> My Makefile doesn't detect the change of header files.
>
> This little makefile follows sec 2.6 of GNU make manual, and I
> remember it worked before when header files changed.
>
> Where am i wrong?

Posting here?  Try are more appropriate group.

You probably need the enable dependency checking in your makefile.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#18887

FromKaz Kylheku <kaz@kylheku.com>
Date2012-03-20 02:48 +0000
Message-ID<20120319193313.571@kylheku.com>
In reply to#18884
On 2012-03-20, lovecreatesbeauty <lovecreatesbeauty@gmail.com> wrote:
> My Makefile doesn't detect the change of header files.
>
> a.c b.c : b.h

Here you are saying that a.c and b.c are objects that are built from b.h.

But that is not the case, since they are not built; a.c and b.c they are
primary objects with no dependencies.

It is b.o and a.o which depend on b.h.

> $ touch b.h
> $ make

Hmm, a better message might be "no rule to make a.c from b.h",
since you've declared the dependency, and a.c is out of date
with respect to b.h under that dependency, and there isn't 
any way to make a.c from b.h".

[toc] | [prev] | [next] | [standalone]


#18891

Fromlovecreatesbeauty <lovecreatesbeauty@gmail.com>
Date2012-03-19 23:08 -0700
Message-ID<51f2b5b1-7035-4648-a815-17f749bd50dc@pg2g2000pbb.googlegroups.com>
In reply to#18887
On Mar 20, 10:48 am, Kaz Kylheku <k...@kylheku.com> wrote:
> On 2012-03-20, lovecreatesbeauty <lovecreatesbea...@gmail.com> wrote:
>
> > My Makefile doesn't detect the change of header files.
>
> > a.c b.c : b.h
>
> Here you are saying that a.c and b.c are objects that are built from b.h.
>
> But that is not the case, since they are not built; a.c and b.c they are
> primary objects with no dependencies.
>
> It is b.o and a.o which depend on b.h.
>

Thank you very much for pointing this out.

> > $ touch b.h
> > $ make
>
> Hmm, a better message might be "no rule to make a.c from b.h",
> since you've declared the dependency, and a.c is out of date
> with respect to b.h under that dependency, and there isn't
> any way to make a.c from b.h".

Does my implicit rule for compiling cause the "no rule.." message, or
is it an implementation bug:)

[toc] | [prev] | [next] | [standalone]


#18899

Fromlovecreatesbeauty <lovecreatesbeauty@gmail.com>
Date2012-03-20 02:32 -0700
Message-ID<9fb30f83-8ba7-44dc-bf59-61c5df26c127@sv8g2000pbc.googlegroups.com>
In reply to#18887
On Mar 20, 10:48 am, Kaz Kylheku <k...@kylheku.com> wrote:
> On 2012-03-20, lovecreatesbeauty <lovecreatesbea...@gmail.com> wrote:
>
> > My Makefile doesn't detect the change of header files.
>
> > a.c b.c : b.h
>
> Here you are saying that a.c and b.c are objects that are built from b.h.
>
> But that is not the case, since they are not built; a.c and b.c they are
> primary objects with no dependencies.
>
> It is b.o and a.o which depend on b.h.
>

I add auto-dependencies generation for header files to avoid specify
individual header for source files.

I tried use wildcard for the SRCS variable in Makefile, but caused
some errors.

$ cat Makefile
CC       = gcc
CFLAGS   = -ansi -pedantic -Wall -W
CPPFLAGS = -I include
LDFLAGS  =
SRCS     = a.c b.c
OBJS     = $(patsubst %.c,%.o,$(SRCS))
OUT      = a.out

vpath %.c src
vpath %.h include

$(OUT): $(OBJS)
        $(CC) $(LDFLAGS) $^ -o $@

include $(SRCS:.c=.d)

%.d: %.c
        @set -e; rm -f $@; \
        $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
        sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
        rm -f $@.$$$$

.PHONY  : clean
clean:
        rm *.d $(OBJS) $(OUT)

$
$ pwd
/home/ljh/temp
$
$ ls . ./src/ ./include/
.:
include  Makefile  src

./include/:
b.h

./src/:
a.c  b.c
$

[toc] | [prev] | [next] | [standalone]


#18911

FromKeith Thompson <kst-u@mib.org>
Date2012-03-20 11:48 -0700
Message-ID<lnaa3bhzwb.fsf@nuthaus.mib.org>
In reply to#18899
lovecreatesbeauty <lovecreatesbeauty@gmail.com> writes:
[snip]
> I add auto-dependencies generation for header files to avoid specify
> individual header for source files.
>
> I tried use wildcard for the SRCS variable in Makefile, but caused
> some errors.
>
> $ cat Makefile
> CC       = gcc
> CFLAGS   = -ansi -pedantic -Wall -W
[snip]

Makefiles aren't specific to C.  You're likely to get better help in
comp.unix.programmer.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web