delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/23/03:00:40

Message-ID: <395309A1.881A2311@pacbell.net>
From: Wesel <nospam AT pacbell DOT net>
X-Mailer: Mozilla 4.73 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Make file wildcards
Lines: 71
Date: Thu, 22 Jun 2000 23:54:25 -0700
NNTP-Posting-Host: 63.197.122.98
X-Complaints-To: abuse AT pacbell DOT net
X-Trace: news.pacbell.net 961742928 63.197.122.98 (Thu, 22 Jun 2000 23:48:48 PDT)
NNTP-Posting-Date: Thu, 22 Jun 2000 23:48:48 PDT
Organization: SBC Internet Services
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I'm sorry, this message didn't seem to get through the first time.  I've
never had that happen... O.o  Anyway...

I'm sure this topic has gone around before, and I apologise for not
lurking long.  I have a question about the format of a makefile I was
hoping (praying?) that you might be able to help me with.

The makefile suggested by the good people at delorie.com went as
follows:
--------------------------------------------------------
CC = gcc
CFLAGS = -g -O2
OBJECTS = main.o foo.o

main.exe : $(OBJECTS)
        $(CC) $(CFLAGS) $(OBJECTS) -o main.exe

%.o : %.c
        $(CC) $(CFLAGS) -c $<
--------------------------------------------------------

The rule that stated %.o : %.c was supposed to happen whenever a file
with the extension .c got modified.  Taking this knowledge to heart, I
proceeded to make a single source file test.cpp.  I built my makefile as
follows:

--------------------------------------------------------
CC = gcc
CFLAGS = -g
OBJECTS = test.o

main.exe : $(OBJECTS)
	$(CC) $(CFLAGS) $(OBJECTS) -o main.exe

%.o : %.c %.cpp %.h
	$(CC) $(CFLAGS) -c $<
--------------------------------------------------------

My hopes were that upon discovering a modified .cpp file, make would
compile test.o then, finding a modified (created) test.o file, it would
build main.exe from the object file.  The makefile compiled fine, but it
used a sneaky implicit rule.  Apparantly %.o : %.cpp is built-in, so
what I saw was

--------------------------------------------------------
make -k
gpp    -c -o test.o test.cpp
gcc -g test.o -o main.exe

Compilation finished at Thu Jun 22 20:29:34
--------------------------------------------------------

One might notice that the implicit rule generates NO debug information
for test.o.  When I ran gdb on main.exe, it found no information about
line numbers, and couldn't show me the related source code.  Upon
disabling implicit rules, make returned with an error stating that a
rule for test.o was missing.

Why didn't "%.o : %.c %.cpp %.h" generate a rule for compiling test.o? 
Is there any way I can use wildcards with the make utility provided by
djgpp?  Do I have to write out every rule for every object-source pair I
use?  I do intend to have more than one source file eventually.

Thank you kindly.


Wesel

-- 
To send me an email, just replace the @ and the .
     -----wassdamo at pacbell dot net

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019