Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generating c++ code from c++ code ???

Status
Not open for further replies.

tryfekid

Programmer
Aug 16, 2001
9
US
Hi,

i'm writing a c++ program that reads in different configuration files and based on the contents of the files, my program will generate a c++ source file to be compiled.

basically, i'm writing a c++ program to generate c++ code based on config files and this is part of a big project so a makefile is being used.

let's call the c++ program that generates the c++ code "Code A" and the c++ program that is generated "Code B."

now my question is: is it possible to have the build process first, compile Code A, and then run it, then that will in turn cause the generation of Code B, and then the build process will just continue on? can this be done through options in the Makefile or something like that or am i going to have to manually compile Code A and then run it everytime i want to build?

thanks. your help is appreciated.
 
you could write a c++ program to build another peice of source code based on input. to run it and then compile the new code, you could use shell scripting. a shell script works very much like a c++ program. but, using main function return values, you can test to see that things went ok, and you could run make, or whatever, based on a makefile, if it's in a script and not too complext, just use the command to compile rather than a makefile.

so to answer your question. yes.
 
Hi,
This is fairly simple and straight foward make rules. LEX and YACC build C or CPP files as part of the make which then in turn become part of the make process. Your Program A isn't any different.



proga : filea.obj
link -o proga filea.obj

filea.obj: filea.cpp
cpp -o filea.obj filea.cpp


fileb.obj : fileb.cpp
cpp -o fileb.obj fileb.cpp

fileb.cpp : proga configfiles
proga > fileb.cpp


just remember to use TABS at the beggining of each command line as make frowns upon spaces.....

Also cpp and link have been simplified for the example. I assume you will have

-I's for include file search paths
-L's for library search paths
-D's for Defines
-l's for libraries to link with




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top