l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
September 2: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2003 Mar 21 13:24

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] makefile question - auto dependencies
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] makefile question - auto dependencies



On Fri, Mar 21, 2003 at 10:18:21AM -0800, Peter Jay Salzman wrote:
> i was playing around with auto-dependencies with makefiles the other
> day.  here's a hello world example of the technique:
> 

>    OBJS   = $(patsubst %.c, %.o, $(wildcard *.c))
>    SRCS   = $(wildcard *.c)

should use SRCS in OBJS list.

>    DEPDIR = .deps
>    vpath %.d ${DEPDIR}

I don't use vpath in the sample above... can add if you want.

> into a single line saying that all .o files depend on the corresponding
> .d file?

  I used to use a nasty sed expression to make the .d files, but for
some reason decided that they were not needed.

  The .o's do not depend on the .d.

  Both the .d and .o the depend on the .c.

  Here is a current sample of Makefile which I use to build programs
with, stripped down to only work on C code... below no user servicable
parts is the stuff that does auto building.
  Rules are written for C++, ProC, LaTeX, etc.

  If you only want a single target to make life simplier you can replace 
go,s2,s3 with:
===
${TARGET}: ${OFILES}
	gcc ${CFLAGS} -o $@ $^ ${LFLAGS}
===

  If you care to use a special LD variable to id the linker
stuff ...

====
TARGET := go

CC := gcc
CFLAGS := -g -Wall -W -O9
CFLAGS := -g -Wall -W
LFLAGS := -lm

all: ${TARGET}

go: main.o
	gcc ${CFLAGS} -o $@ $^ ${LFLAGS}
s2: s2.o
	gcc ${CFLAGS} -o $@ $^ ${LFLAGS}
s3: s3.o
	gcc ${CFLAGS} -o $@ $^ ${LFLAGS}

################
# no user servicable parts below here... so don't change below here
################
%.o: %.c
	gcc ${CFLAGS} -c $^

.%.d: %.c
	@gcc -MM ${CFLAGS} -o $@ $^

clean:
	rm -rf *.o

nuke: clean
	rm -rf ${DFILES} $(TARGET)

CFILES := ${wildcard *.c}
OFILES := ${patsubst %.c,%.o,${CFILES}}
DFILES := ${patsubst %.c,.%.d,${CFILES}}

ifneq ($(MAKECMDGOALS),nuke)
-include ${DFILES}
endif
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.