User forums > Using Code::Blocks
cbp2make - makefile generation tool
blinde:
Hi.
In my previous project, all the makefiles are home made.
And dependencies are fully managed.
The makefile can be called with clean / dep / all
dep, will automatically generates some <filename>.dep
it calls gcc with some special options and generate (e.g):
--- Code: ---obj/VLX_NoiseMgr.o : VLX_NoiseMgr.cpp ../../include/CSC_Utils/UTI_Error.h \
../../include/CSC_Utils/UTI_types.h \
/usr/local/include/wx-2.8/wx/wxprec.h \
/usr/local/include/wx-2.8/wx/defs.h \
/usr/local/include/wx-2.8/wx/platform.h \
--- End code ---
one part of the makefile :
--- Code: ---SrcSuf = .cpp
DepSuf = .dep
ObjSuf = .o
OBJDIR = obj
SRCS = $(SRC)
OBJF = $(patsubst %$(SrcSuf),$(OBJDIR)/%$(ObjSuf),$(SRCS))
DEPS = $(patsubst %$(SrcSuf),$(OBJDIR)/%$(DepSuf),$(SRCS))
DEBUGFLAGS = -Wall -g -O2 -D_NO_SHUTDOWN_
CFLAGS = -D_REENTRANT `$(WXCONFIG) --cxxflags`
INCFLAGS = \
-I../../include/CSC_Spectro \
all:: $(DEPS) $(OBJF)
ifeq ($(MAKECMDGOALS),all)
include $(DEPS)
endif
$(OBJDIR)/%$(DepSuf): %$(SrcSuf)
@echo
@echo '------------------'
@echo -en "\033[30;47;1m"
@echo 'Making $< dependencies...'
@echo -en "\033[30;47;0m\n"
@if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ;fi ;
@$(CC) $(DEBUGFLAGS) $(CFLAGS) $(INCFLAGS) $(PROJFLAGS) -MM $< | sed 's/\($*\)\.o[ :]*/$(@D)\/\1.o : /' > $@ ;
$(OBJDIR)/%$(ObjSuf): %$(SrcSuf)
@echo '------------------'
@echo -en "\033[30;47;1m"
@echo 'Building $< ...'
@$(CC) $(DEBUGFLAGS) $(CFLAGS) $(INCFLAGS) $(PROJFLAGS) -c $< -o $@ ;
@echo -en "\033[30;47;0m\n"
clean::
@rm -rf $(OBJDIR)
print::
@echo "Dependances"
@echo $(DEPS)
@echo "Fichiers"
@echo $(OBJF)
--- End code ---
oBFusCATed:
mirai: look at the .depends file; also in the sources you can find a lib that generates these files.
blinde: please use code tags in order to make your posts more readable
mirai:
--- Quote from: oBFusCATed on March 24, 2011, 06:28:06 pm ---mirai: look at the .depends file; also in the sources you can find a lib that generates these files.
--- End quote ---
Thanks. I found "depslib" and spent some time digging in its code. According to what I discovered, the only thing that I really need is search for include directives and some magic about file paths to find header files. I think I don't need all of depslib as-is, since half of it is string-related stuff which I already have. And using a full-blown regexp library is an overkill for me here, so I decided to go with a couple of FSA for a couple of languages to parse sources. However, I did not found a piece of code in depslib for processing conditional compilation directives (#define, #ifdef, #endif, #else, etc) and more diffucult to manage #if directive since it may contain expressions. Ignoring these directives will/may result in false includes, and hence, false dependencies. So, my next question/problem is how (or what is the better way) to partially preprocess sources.
oBFusCATed:
Search the forum, there are some discussion on the topic (and a very recent one in the Code Completion sub forum).
mirai:
--- Quote from: oBFusCATed on March 25, 2011, 03:07:43 pm ---Search the forum, there are some discussion on the topic (and a very recent one in the Code Completion sub forum).
--- End quote ---
Well, after reading the topic and code examples I gradually come to a conclusion that I should make some workaround or partial solution, but not the complete one needed for CC. Since the purpose is just to tell 'make' what files it should check for changes before turning a unit into an object file, the procedure of extracting dependencies could be simplified.
I suppose the following algorithm will do the job:
For every unit in a build target:
* 1) recursively scan for #include directives ignoring #ifdef-s and resolve paths of included files by searching these files in include path.
* 2) remove duplicate includes.
* 3) add all successfully found includes to dependencies of current unit's target.
* 4) forget includes that cannot be found or add them somewhere close to target as remarks.
This way missing dependencies won't trigger 'make' to complain about themselves, but all of existing dependencies will cause a rebuild of certain targets if necessary. There may be a small overhead caused by including false, but existing, dependencies, but this won't break anything.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version