Need your help with projecting the makefile. So, what I have and what I want to get. I need to build two executables. Source code is common. Preprocessor macros control differences for both exes, for example, in main.cpp:
#if PROJECT_TYPE==FTP
std::cout << "FTP" << std::endl;
#else
std::cout << "SFTP" << std::endl;
#endif
Differences aren’t only in source code but also in additional libraries that used for linking:
FTP_LDFLAGS= -static-libstdc++ -static-libgcc -s -L $(ROOT_DIR)/lib/Release -l:libboost_thread-mgw46-mt-1_49.a -l:libcommon.a \
-l:libfile.a -l:libfilesearcher.a -l:libftpclient.a -l:libftplib.a -l:libdbclient.a -l:libsqlite3.a -l:libscheduler.a -l:libws2_32.a
SFTP_LDFLAGS= -static-libstdc++ -static-libgcc -s -L $(ROOT_DIR)/lib/Release -l:libboost_thread-mgw46-mt-1_49.a -l:libcommon.a \
-l:libfile.a -l:libfilesearcher.a -l:libdbclient.a -l:libsqlite3.a -l:libscheduler.a -l:libsftpclient.a -l:libws2_32.a -l:libssh.dll
Also I want to create debug/release build targets with own CXXFLAGS and output directories, so in result to get following:
TARGETS= ftp_auto_backup sftp_auto_backup
I want use implicit rule for compiling, smth like this:
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $< -o $(O_DIR)/$@
But how can I specify separate O_DIR for each target int $(TARGETS) and for each build configuration? My main problem is in this step. I can paste all the makefile that I have at this moment, but it still won’t build anything. Just in case here it is: http://pastebin.com/jjB5Ld1s
Thanks in advance, guys!
There are many ways to do this. The simplest seems to be by means of recursive Make. (I am not among those who think that this is always a bad idea.)
Now to make the executables, given
VERSION. We could handle the two project types with another layer of recursion, but we can do without it (and I won’t go into detail about preprocessor macros and compiler/linker flags, since you seem to know about them already– I’ll spell them out if you like):