Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, I can, and so can you, without a doubt.

If I wanted to distribute a single file library, but have the two file option for users, I'd make it so that a specific Awk one-liner produces the two. For instance, the file might look like this:

   #ifndef FOOBAR_LIB_H_D3B94F3C
   #define FOOBAR_LIB_H_D3B94F3C

   // header stuff here

   #endif // FOOBAR_LIB_H_D3B94F3

   #if FOOBAR_LIB_IMPL

   // impl here

   #endif
Then to people who want two, I would say, just run this command in your shell and paste the content into it:

   awk 'BEGIN { print "#include \"foobar.h\"" > "foobar.c"
                print "#define FOOBAR_LIB_IMPL" > "foobar.c" }
        /#ifndef FOOBAR_LIB/,/#endif.*FOOBAR_LIB/ { print > "foobar.h"; next }
        { print > "foobar.c" }'
that way I wouldn't need a build step on my end to generate parallel files.

I would have the extra build step if it were a large project of multiple .c files that I wanted to deploy as a single file for the users who want that. (Not only would I build the single file out of multiple files, but also have some test cases which actually use it. Things have ways of breaking when you combine files, like giving the same name two two static variables or functions in different files.)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: