2

I have a C header file, used by a program, that is generated from a script that takes a text file as input.

The problem is that when xmkmf -a is run, I get

myprogram.c:114:25: fatal error: generated_header.h: No such file or directory

The command to generate the header is like

myscript header_input.txt > generated_header.h

How do I handle a header being generated with imake?

I tried adding rules that say

 myprogram.c: generated_header.h

but the make depend gets ran and fails before this rule is ran to generate the file. (Things work fine if I just do xmkmf rather than xmkmf -a but the probably here is that running xmkmf -a is the standard way of using imake.)

I'm not experienced with imake and there doesn't seem to be a lot of documentation so I'm stumbling. Any help would be appreciated.

SO Stinks
  • 3,258
  • 4
  • 32
  • 37

1 Answers1

1

Found a workaround through comments. Question is still open for a more "correct" answer.

I tried adding rules that say

myprogram.c: generated_header.h

but the make depend gets ran and fails before this rule is ran to generate the file.

The above tells imake that myprogram.c needs a file generated_header.h. It is a dependency.

What it doesn't tell imake is how to generate generated_header.h.

For that, you would need something along these lines:

generated_header.h: header_input.txt
    myscript header_input.txt > generated_header.h

Note that the "recipee" ("how to generate generated_header.h") needs to be indented with a tab, not spaces. Make (and imake) do make a difference between tab and space that way.

The general syntax is:

target: dependency [dependency...]
    recipee
    [recipee...]

In this regard, imake isn't different from standard make. Actually, imake is "make with C preprocessor running first", so reading the generic make manuals might be helpful.

Community
  • 1
  • 1
DevSolar
  • 67,862
  • 21
  • 134
  • 209
  • Hi, DevSolar. I have such recipes in my Imakefile. I think the problem lies at the "make includes" stage. My current generated Makefile gives me "make: Nothing to be done for `includes'." when `make includes` is performed. This is the stage where my header generating rule should be ran so that the "make depends" stage succeeds. The problem is that I don't know how to tell imake which rules to run at the includes stage. – SO Stinks Aug 10 '15 at 11:45
  • 1
    @Dr.PersonPersonII: Well, what does the `includes:` rule look like? – DevSolar Aug 10 '15 at 12:03
  • I'm not sure if it's the right way to do it, but adding ``includes:: generated_header.h` to my Imakefile makes the Makefile do what I needed. (Note the use of the _double_ colon because this is an imake issue, not a make issue.) I suppose I was thinking there'd be something like `IncludeTarget(generated_header.h)` needed. What's the SO convention here? Do I accept your answer because we figured it (well, a way) out? Or does one of us create a new answer? Thank you for your interaction. – SO Stinks Aug 10 '15 at 13:53
  • 1
    The "correct" way to go about it would probably (?not an imake grok here?) to add `generated_header.h` to some *list* that is already given as dependency to `includes:`. If you find something along those lines, write it up as an answer of your own. (Perfectly legit to answer your own question on SO.) Or somebody comes up with a "right" / better answer. Or you're satisfied with my answer. I won't hold it against you if you don't accept, I'm here for the helping, not the rep. ;) – DevSolar Aug 10 '15 at 14:46
  • That was exactly the thinking that prompted me to ask my question. There may be a better, more scalable, more native imake way to do it than the one we found but it does what I need it to do. If I find it in the future, I'll update the question but for now I'm going to just accept your answer. You may wish to add an edit that says "EDIT: solved through comment discussion" or something so people know to read here. Thanks again. – SO Stinks Aug 10 '15 at 14:51