help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Makefile not correctly rebuilding project


From: Alex Buell
Subject: Makefile not correctly rebuilding project
Date: Mon, 07 Jun 2010 11:52:46 +0100

Hi,

Normally my projects have files in the same directory and things get
rebuilt without a problem. But recently I started a new project with
separate directories for each program I'm developing, and have found a
problem that I've tried to solve with references to many articles on
makefile generation. 

The problem is that if I change one of the header files in the project
the makefile doesn't detect the changed header file and won't rebuild
correctly. 

Here's how my project is organised:

$ ls -lt
total 96
drwxr-xr-x 2 alex users  4096 Jun  7 00:36 assembler
-rwxr-xr-x 1 alex users 21732 Jun  7 00:35 vlink
drwxr-xr-x 2 alex users  4096 Jun  7 00:35 linker
-rwxr-xr-x 1 alex users 51266 Jun  7 00:35 vasm
-rw-r--r-- 1 alex users  1019 Jun  4 01:38 Makefile
drwxr-xr-x 2 alex users  4096 Jun  3 14:51 vpcm
drwxr-xr-x 2 alex users  4096 Jun  3 14:50 library

The header file (vasm.h) lives in assembler/,

$ ls -lt assembler/
total 80
-rw-r--r-- 1 alex users   142 Jun  7 00:36 vasm.h
-rw-r--r-- 1 alex users 16108 Jun  7 00:35 help.o
-rw-r--r-- 1 alex users 16132 Jun  7 00:35 version.o
-rw-r--r-- 1 alex users 17924 Jun  7 00:35 vasm.o
-rw-r--r-- 1 alex users   581 Jun  7 00:35 vasm.d
-rw-r--r-- 1 alex users   520 Jun  7 00:35 version.d
-rw-r--r-- 1 alex users   511 Jun  7 00:35 help.d
-rw-r--r-- 1 alex users   772 Jun  4 01:35 vasm.c
-rw-r--r-- 1 alex users    76 Jun  3 17:09 help.c
-rw-r--r-- 1 alex users    97 Jun  3 17:07 version.c

As you can see, I have .d files to help with automatic generation of
dependency information to help rebuild the project when I edit files. 

Note the timestamps above, in particular vasm.h, it is later than the
rest of the project files. 

Yet when I do this:
$ make
make: Nothing to be done for `all'.

Here's the vasm.d (which includes vasm.h)
$ more assembler/vasm.d
vasm.o: assembler/vasm.c /usr/include/stdio.h /usr/include/features.h \
 /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \
 /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h \
 /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/stddef.h \
 /usr/include/bits/types.h /usr/include/bits/typesizes.h \
 /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \
 /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/stdarg.h \
 /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
 /usr/include/string.h /usr/include/xlocale.h /usr/include/getopt.h \
 assembler/vasm.h

As you can see, it's including assembler/vasm.h so I'm not sure why it's
not rebuilding the project whenever that file changes. 

Here's the Makefile, maybe you can spot what the problem is, I'd be very
grateful:

#
# $Header$
#
# $Date$
# $Revision$
# $Author$
#
# Copyright (C) 2010 Alex Buell <address@hidden>
# All Rights Reserved.
#

CC      = gcc
LD      = gcc

CFLAGS  = -ggdb3

MAKEDEPEND = makedepend
SED = sed

VASMDIR = assembler/
VASMSRC = vasm.c version.c help.c

vasm_SRCS = $(addprefix $(VASMDIR), $(VASMSRC))
vasm_OBJS = $(vasm_SRCS:.c=.o)

VLINKDIR = linker/
VLINKSRC = linker.c 

vlink_SRCS = $(addprefix $(VLINKDIR), $(VLINKSRC))
vlink_OBJS = $(vlink_SRCS:.c=.o)

PROGRAMS = vasm vlink

.PHONY: all
all:    $(PROGRAMS)

$(PROGRAMS):
        $(LD) $^ -o $@

define PROGRAM_template
$(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%)
ALL_OBJS += $$($(1)_OBJS)
endef

$(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))

-include $(subst .c,.d,$(vasm_SRCS))

%.d: %.c
        $(CC) -M $(CFLAGS) $< > address@hidden; \
        $(SED) 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < address@hidden > $@; \
        rm -f address@hidden

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

.PHONY: clean
clean: 
        rm -f $(vasm_OBJS) $(subst .c,.d,$(vasm_SRCS)) $(vlink_OBJS) 
        rm -f $(PROGRAMS)


-- 
http://www.munted.org.uk

One very high maintenance cat living here.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]