1

I have a C project with many header files, but I do not want to deliver to the client one specific header file with bunch of defines. I want all other files to be preprocessed with just that specific header file, and I want to regenerate all sources to a new directory, so that client is able to compile this project's new source although he wouldn't have the mentioned header file.

Is there a Linux or Windows way to do this without manual search/replace in editor?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
avra
  • 3,690
  • 19
  • 19
  • 1
    I suppose you can cripple the other #includes like `#inc lude` and then run the C preprocessor on the files (gcc -E or so). This could get pretty ugly though--why not just give your client the file? – John Zwinck Mar 27 '14 at 14:44
  • 1
    I would use a tool like `m4` - convert the special header to a bunch of m4 macros and then apply this to all the source files. – Paul R Mar 27 '14 at 14:46
  • 1
    Thanks Paul. Please write your reply as an answer so I can accept it. – avra Mar 28 '14 at 07:49
  • @avra: Consider it done! – Paul R Mar 28 '14 at 11:05
  • 1
    You might find the answers to [Is there a C prep-processor which eliminates `#ifdef` blocks based on values defined/undefined?](https://stackoverflow.com/questions/525283/is-there-a-c-pre-processor-which-eliminates-ifdef-blocks-based-on-values-define) useful. Either `sunifdef` or `coan` would probably help. – Jonathan Leffler May 15 '16 at 19:14

1 Answers1

1

I would use a macro processing tool such as m4, which is widely available (it's standard on most Linux and *nix distributions, as it's used by autoconf, sendmail, et al). Convert the special header to a bunch of m4 macros and then apply this to all the source files.

Note that there are plenty of other alternatives to m4, and scripting languages such as Perl could also be considered.

Paul R
  • 208,748
  • 37
  • 389
  • 560