delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/25/09:21:11

Comments: Authenticated sender is <mert0407 AT sable DOT ox DOT ac DOT uk>
From: "George Foot" <george DOT foot AT merton DOT ox DOT ac DOT uk>
To: rylan AT intekom DOT co DOT za
Date: Fri, 25 Sep 1998 14:08:46 +0000
MIME-Version: 1.0
Subject: Re: Making MAKE call NASM like it calls GCC
Reply-to: mert0407 AT sable DOT ox DOT ac DOT uk
CC: djgpp AT delorie DOT com
Message-Id: <E0zMXeP-00036d-00@orange.easynet.co.uk>

On 25 Sep 98 at 11:01, Rylan wrote:

> I have a small problem with make.  With this make file:
> 
> CC = gcc
> CFLAGS = -m486 -s -Wall -Werror
> OBJ = gplan.o gal.o ggfx.o gglobal.o gspecies.o gship.o gsound.o
> 
> gal.exe: $(OBJ); \
>   $(CC) -o gal.exe $(OBJ) -lalleg -lseal -m486 -s -Wall -Werror
> 
> GCC automatically gets called for each .c specified in $(OBJ).

Make has an internal rule that says to call a certain command 
(specified by various variables, including $(CC) and $(CFLAGS)) 
to convert .c files into .o files.

> However, why
> does make not behave the same with NASM? That is, if I try to do exactly the
> same with nasm just adding it and doing
> 
> asmobjs: $(ASMOBJ);\
>  $(NASM) -f coff ($ASMOBJ)
> 
> make tries to call NASM once for all the .ASM files that are to be compiled?

You misunderstood what Make did.  Calling gcc to compile .c 
files into .o files was done automatically -- nothing to do 
with the rule you posted above.  You could have just written:

    gal.exe: $(OBJ)
    	@echo "Hello world!"

and it would still have compiled the .c files to .o files.

> A solution is to explicitly call NASM repeatedly and individually in the
> make file, but my question is is can't make do this automatically like it
> does for GCC? Or is this behaviour "hardwired" into make when it works with
> GCC only?

Half.  It's hardwired in, but you can almost add to it (on a 
per makefile basis) and it's also not gcc-specific -- you use 
the CC variable to specify what compiler to use, the CFLAGS 
variable to specify the switches to pass...

> The summation is then - is there a way to make "make" call NASM repeatedly,
> automatically, like GCC gets called repeatedly and automatically on the .C
> files for a given set of .O filenames?

I don't know how to call NASM, but supposing it takes `-i' to 
specify the input file and `-o' to specify the output file, and 
`-switches' are the switches to use, e.g.:

    nasm -i input.asm -o output.o -switches

You could put:

    %.o: %.asm
    	nasm -i $< -o $@ -switches

($< and $@ are automatic variables; $< is the first dependency 
and $@ is the target file)

That means "to convert foo.asm into foo.o, you call: nasm -i
foo.asm -o foo.o -switches".  See the GNU Make manual and look
up "Implicit Rules", and in particular how to define your own
"Pattern Rules":

    info make "Implicit Rules"
    info make "Pattern Rules"

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

- Raw text -


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