0

I'm working on a makefile for a simple program and it has two files associated with it: main.cpp and game.adt. From game.adt I'm supposed to split it into 2 parts for the header and source code (guess.h and guess.cpp) using csplit. I've tried compiling the makefile like this:

HEADERS=guess.h

#Targets:

default: guessGame

guessGame: guess.o main.o

                g++ guess.o main.o -o guessGame

guess.o: guess.cpp $(HEADERS) 

                g++ -c guess.cpp -o guess.o

main.o: main.cpp $(HEADERS)

         g++ -c main.cpp -o main.o

clean:

       -rm -f guessGame *.o

However it says there's 'no rule for target guess.cpp needed for guess.o.' Same goes for the header file. I know it's because the files 'guess.cpp' and 'guess.h' don't exist but it's because I'm supposed to split the .adt file to make it into guess.cpp and guess.h. How do I create a rule then for targets guess.cpp and guess.h using the adt file?

3
  • It's hard to understand what your question is, exactly - if you want help using cspilt then you will need to provide more information about the format and content of the game.adt file. Or are you asking how to add an existing csplit command as part of a Makefile? Commented Jun 29, 2018 at 17:55
  • To be able to come with suggestion on how to process the adt file, we must see the relevant bits of that file.
    – Kusalananda
    Commented Jun 29, 2018 at 18:14
  • Yes I guess what I'm asking is how to use csplit in the makefile in order to produce the guess.cpp and guess.h files. The guess.adt file is just the code for the header plus the source code. I'm supposed to use "csplit guess.adt '/Split Here/'" to split the file where it has the "split here" comment to divide it into xx00 (header file) and xx01 (source code). I'm trying to figure out how I'm supposed to do that within the makefile as the guess.cpp and guess.h are supposed to be targets.
    – CosmicCat
    Commented Jun 29, 2018 at 18:53

1 Answer 1

0

This can likely be improved. but it should get you started:

guess.cpp guess.h : game.adt
        csplit -sz $< '/Split Here/'
        mv xx00 guess.h
        mv xx01 guess.cpp

Make sure that the rules are indented with tabs not spaces.

1
  • Thank you! This is exactly what I was trying to do but I couldn't figure out how to go about it.
    – CosmicCat
    Commented Jun 29, 2018 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .