[comp.unix.questions] Preprocessor dependencies in MAKE

perl@dwrsun2.UUCP (Robert Perlberg) (06/15/91)

Environment: Sun3 under SunOS 4.0.3

I'm using a language (Ingres embedded SQL for C) which preprocesses
into C.  I need to generate a command sequence like the following:

	esqlc runme.sc
	cc -g -c runme.c
	cc -g -o runme runme.o -lingres -lm

where esqlc creates runme.c.  Since I have to compile an application
which is made up of many `.sc' files, I would like to create a Make
rule that will understand this general dependency so I don't have to
create an explicit dependency for each file.  I have tried the
following:

	.SUFFIXES: .sc

	.sc.c:
		esqlc $*.sc

	runme: runme.o
		$(CC) $(CFLAGS) -o $@ runme.o -lingres -lm

With this I get the error "make: don't know how to make `runme.o'"

If I change the rule to:

	.sc.o:
		esqlc $*.sc
		$(CC) $(CFLAGS) -c $*.c

it works the first time, but then if I modify runme.sc and run make it
says "`runme' is up to date".

I don't want to remove the `.c' file after compiling since it's needed
if I want to debug the program with dbx.  How do I do this?

Thanks in advance.

Robert Perlberg
Dean Witter Reynolds Inc., New York
murphy!dwrsun2!perl
	-- "I am not a language ... I am a free man!"

cpcahil@virtech.uucp (Conor P. Cahill) (06/15/91)

perl@dwrsun2.UUCP (Robert Perlberg) writes:
>which is made up of many `.sc' files, I would like to create a Make
>rule that will understand this general dependency so I don't have to
>create an explicit dependency for each file.  I have tried the
>following:
>	.SUFFIXES: .sc
>	runme: runme.o
>		$(CC) $(CFLAGS) -o $@ runme.o -lingres -lm
>	.sc.o:
>		esqlc $*.sc
>		$(CC) $(CFLAGS) -c $*.c
>it works the first time, but then if I modify runme.sc and run make it
>says "`runme' is up to date".

The problem is that the .c.o rule is taking precedence.  So what you need
to do is the following:

	.SUFFIXES:
	.SUFFIXES: .o .sc .c .c~ .....

The first line clears the suffixes list.  The second line will cause
your .sc.o rule to be applied (assuming it fits) before the .c.o rule
would be applied.  Note that you sould ensure that you don't leave off
any of the predefined suffixes on the second line or else they 
won't be usable.

You can see what the default list of suffixes is by entering:
	
	make -fp - 2>/dev/null < /dev/null | grep SUFFIX

Have fun.
-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

smfst2@unix.cis.pitt.edu (Seth M Fuller) (06/17/91)

In article <2331@prodigal.dwrsun2.UUCP> perl@dwrsun2.UUCP (Robert Perlberg) writes:
>	.sc.o:
>		esqlc $*.sc
>		$(CC) $(CFLAGS) -c $*.c
>
>it works the first time, but then if I modify runme.sc and run make it
>says "`runme' is up to date".
>
>I don't want to remove the `.c' file after compiling since it's needed
>if I want to debug the program with dbx.  How do I do this?

The problem is that you have eliminate make's knowledge of how to create
a .o file from a .c file. You do this with the .SUFFIXES statement  before
your rules statement. The empty .SUFFIXES statement eliminates make's 
knowledge of all the suffixes it usually knows. I use the following for 
4GL code and it works fine.

.SUFFIXES:
.SUFFIXES: .4gl .per .frm .c .o

If you have any purely C files you want to make in this directory you
will have to create a .c.o rule after your .sc.o rule.

Seth M. Fuller