Nahim
Nahim

Reputation: 3

How to use/compile this file?

I was given this example file called pMakefile and I am unsure how to execute it. What command would be used and how it would be used?

I have tried to compile using make and it seems different from a regular makefile. I am using a UNIX environment for this.

wombat aardvark.o manatee.o penguin.o velociraptor.o wombat.o [gcc -o 
wombat aardvark.o manatee.o penguin.o velociraptor.o wombat.o]
aardvark.o aardvark.h aardvark.c [gcc -c aardvark.c]
aardvark.h aardvark1.txt aardvark2.txt [date | sed 's/\(.*\)/"\1"/g' | 
cat -s aardvark1.txt - aardvark2.txt > aardvark.h]
manatee.o manatee.h manatee.c [gcc -c manatee.c]
penguin.o penguin.h penguin.c [gcc -c penguin.c]
velociraptor.o velociraptor.h velociraptor.c [gcc -c velociraptor.c]
wombat.o aardvark.h manatee.h penguin.h velociraptor.h wombat.h wombat.c 
[gcc -c wombat.c]

Just want to know how to use the file. executing using:

make -f pMakefile gives
pMakefile:1: *** Missing separator. Stop 

Upvotes: 0

Views: 92

Answers (2)

John Bollinger
John Bollinger

Reputation: 180181

The code presented does not constitute a valid makefile. I'm not sure what utility is supposed to consume it, but it looks like it is structured as lines of this form:

target prerequisite ... '[' recipe ']'

In that case, a corresponding standard makefile would be

wombat: aardvark.o manatee.o penguin.o velociraptor.o wombat.o
    gcc -o $@ aardvark.o manatee.o penguin.o velociraptor.o wombat.o

aardvark.o: aardvark.h aardvark.c
    gcc -c -o $@ aardvark.c

aardvark.h: aardvark1.txt aardvark2.txt
    date | sed 's/\(.*\)/"\1"/g' | cat -s aardvark1.txt - aardvark2.txt > $@

manatee.o: manatee.h manatee.c
    gcc -c -o $@ manatee.c

penguin.o: penguin.h penguin.c
    gcc -c -o $@ penguin.c

velociraptor.o: velociraptor.h velociraptor.c
    gcc -c -o $@ velociraptor.c

wombat.o: aardvark.h manatee.h penguin.h velociraptor.h wombat.h wombat.c
    gcc -c -o $@ wombat.c

Upvotes: 1

user149341
user149341

Reputation:

This isn't a standard Makefile, but I think I see how it could be converted into one. On each line, the first filename is the target, subsequent filenames are dependencies, and the text in brackets is the rule.

For example, the first two lines:

wombat aardvark.o manatee.o penguin.o velociraptor.o wombat.o [gcc -o 
wombat aardvark.o manatee.o penguin.o velociraptor.o wombat.o]

would be represented in a Makefile as:

wombat: aardvark.o manatee.o penguin.o velociraptor.o wombat.o
    gcc -o wombat aardvark.o manatee.o penguin.o velociraptor.o wombat.o

Even with that fixed, though, this is a very poorly written Makefile -- it makes no use of basic features like variables or wildcard rules, making it highly repetitive. You'd really be better off rewriting it entirely.

Upvotes: 2

Related Questions