This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

"conditional source"

cross posted at 8052.com

I have a module, which is used in four different products, that has way too many #ifdef's to be readable in debug and, at the same time, there is so much common code that making four separate modules is not the right approach. I have used all the "usual tricks" (separating what is only for one to a separate libray module, making some conditionals inside a macro etc)

What I wonder is: is there some software that can "cut type x" out of the source before compilation. Since I am using a .bat operation (no IDE), a free standing program would be fine. This, probably, would require replacing the #ifdef with somrthing such a program "understood" no problem.

Erik

just so you know: I can NOT use the IDE due to its inability to make lots of slightly different builds in one go from the same source. Not a complaint, just a fact.

Parents
  • "is there some software that can "cut type x" out of the source before compilation"

    Although you can probably guess what my answer is, I am compelled to say it anyway.

    If you aren't nesting #ifdef's, a 3-line sed script should do it (1 line for each of the other three #ifdef PRODUCT_n/#endif clauses to delete).

    For example:

    # Leave only "#ifdef PRODUCT_3" clauses.
    /ifdef PRODUCT_1/,/endif/d
    /ifdef PRODUCT_2/,/endif/d
    /ifdef PRODUCT_4/,/endif/d

    Otherwise, if you *are* nesting #ifdef's, you'd probably have to step up to awk, perl, or their ilk.

Reply
  • "is there some software that can "cut type x" out of the source before compilation"

    Although you can probably guess what my answer is, I am compelled to say it anyway.

    If you aren't nesting #ifdef's, a 3-line sed script should do it (1 line for each of the other three #ifdef PRODUCT_n/#endif clauses to delete).

    For example:

    # Leave only "#ifdef PRODUCT_3" clauses.
    /ifdef PRODUCT_1/,/endif/d
    /ifdef PRODUCT_2/,/endif/d
    /ifdef PRODUCT_4/,/endif/d

    Otherwise, if you *are* nesting #ifdef's, you'd probably have to step up to awk, perl, or their ilk.

Children