Combining a project with multiple .c file into one .c
Hello Everyone,
I am using VEX open-source compiler and some of its ready to use benchmarks like "gsm" and "h264" in ubuntu to run and test the effects of options in the performance results. The point is I really need just one .c file containing all the i.e. H264 project to integrate with my so-far scripts and the other working programs. As I checked those benchmarks, they have their own makefile and compiler routine but I want them to be places inside my own scripts to run them several times in a looped chain. P.S: for the reference, this is the dl link of VEX : http://www.hpl.hp.com/downloads/vex/vex-3.43.i586.tgz the benchmarks can be found on the folder ~/share/apps Best, Amir |
This could be done with a combination of find and cat; you would find all the *.c files in a given directory (~/share/apps/gsm or ~/share/apps/h264) and concatenate them into individual files named; e.g., gsm.c and another, h264.c. I use /tmp/gsm and /tmp/h264 as directory targets for copying (after the copy is done, simply move those directories wherever you want them to live).
So, to do that Code:
mkdir /tmp/gsm Code:
cat >> /tmp/gsm/gsm.h $(find ~/share/gsm -name '*.h') Code:
# use whichever one of these is for your system (don't add any additoinal flags, not needed) This is not a trivial exercise, expect to have problems and be ready to deal with them. Hope this helps some. |
Thanks a lot for the reply.
So If I got it right, at the end I'll have i.e. one h262.c and one h262.h ? As I mentioned in the question, there is no need to have a makefile for compiling, cuz I will use the .c file in my own automated scripts. Is it a way to include the header files in the .c file as well ? all in one ? Thanks, Amir |
Close -- you'll end up with one (large) h264.c and h264.h (if there are any headers) in a directory h265, and one gsm.c and one hsm.h (ditto) in another directory gsm (if I understood the question correctly that is).
Yes, you can include the headers in one file at the begging of your .c, but you'd need to go through the entire .c file and remove all the #include directives for local header files -- the difference is Code:
#include <stdio.h> means it's in /include, /usr/include or similar What you can do is use, say, sed and uniq to create a little file of all the header directives, something like this Code:
<after you've created the giant .c file> Code:
sed '/#include/d' gsm.c > gsm_new.c There are, of course, other ways to do that (regular expressions is one) but the above is quick and easy. Again, this is not going to be trivial -- when you first try to compile this thing it's probably going to spit out a whole lot of errors and you're most likely going to be doing a whole lot of editing and moving things around before you'll get a clean compile. Make sure you keep back up copies before you edit things. Hope this helps some. |
Thanks a lot buddy. I am on it. Hope the standard structure of the project doesn't change by doing this since I wanna publish some official results out of optimization of compilation with the whole automated system.
Will let you know. regards, Amir |
Dear tronayne,
Why in the : <after you've created the giant .c file> sed -n '/#include/p' | uniq > file_name phase nothing wouldn't happen ? I mean just the curser standing in the next line without having anything on the output file_name. i have made the giant .c file, but this step forward i can't go through :| Thanks, Amir |
That's 'cause I missed putting the input file name in there -- duh!
Code:
<after you've created the giant .c file> You could make "file_name" something like "gsm.h" then, after you do the next step, simply Code:
#include "gsm.h" Sorry about the fumble-finger. |
you can use -E with gcc to preprocess only the sources. The result is one single file which can be simply compiled with gcc -o exe <preprocessed.c> -L ... -l .... I think this preprocessing stage can also be used with VEX sources because they looks compatible on this level.
|
Thanks tronayne for the revision.
But again it didn't work, also in the h264.c (giant file), there were other includes in "# include" style (I don't know why in this style it has been written??) which I added afterward, but again no satisfactions. I can compile the whole project with 15-20 .c files with 15-20 .h files (which i placed them in one folder together) but neither with one .c and one .h nor with one giant .c and one .h (lists). Dear pan64, Also I checked the "opt" C2C scripts where LLVM starts the first transformations, -E didn't help ( or maybe I used it wrong), the LLVM scripts are : Code:
/home/user/LLVM_2_8/llvm-gcc-4.2-2.8-i686-linux/bin/llvm-gcc -S -emit-llvm $infile -o $noopt Code:
######################################################### Amir |
All times are GMT -5. The time now is 12:25 PM. |