Author Topic: How to use a makefile with codeblocks?  (Read 21233 times)

Offline resander

  • Multiple posting newcomer
  • *
  • Posts: 49
How to use a makefile with codeblocks?
« on: January 30, 2012, 07:11:39 pm »
I need to explore open source software for softphones with video. There are ten or more such projects on the web and all of them come with makefiles. I have used GUI-based IDEs for many years including codeblocks for Linux and would not want to go back working from the command line and GDB.

The smallest project I could find is at www.sipsak.org. I created a Console project sipsaktry for this and manually copied sipsak c-source and header files into the project directory. After some editing it compiled and ran fine under codeblocks. The binary executable ended up in the codeblocks default bin/Debug directory. That was not difficult but a bit tedious, so it may be more convenient to use the makefile that came with the sipsak distribution, i.e. makefile.am. Exactly how do I do this? (assuming the same output files as I used for the sipsaktry project).

I read a wiki about using makefiles with codeblocks http://wiki.codeblocks.org/index.php?title=Code::Blocks_and_Makefiles. Towards the end of the wiki there is:

'One final remark. Once you have used a makefile, attempts to compile anything without a makefile result in a number of warnings. The only way I have found of solving this is to reinstall CB. If you need both perhaps it is possible to install 2 versions of CB.'

That sounds too bad to be true! Is it really true?

Ken
 

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: How to use a makefile with codeblocks?
« Reply #1 on: January 30, 2012, 07:35:40 pm »
No it's not true.

See:
http://forums.codeblocks.org/index.php/topic,13333.msg89706.html#msg89706
or
http://forums.codeblocks.org/index.php/topic,14662.msg98485.html#msg98485

and possibly others (search the forum for "custom makefile").

To use the exe from inside C::B (or debug it), you might need to fix the output filename and the execution directory in the projects properties (tab "Build targets").

Note that the compiler settings inside C::B can not be used (except for finding the correct make executable, because the compiler is driven by the makefile.

Offline resander

  • Multiple posting newcomer
  • *
  • Posts: 49
Re: How to use a makefile with codeblocks?
« Reply #2 on: January 31, 2012, 02:41:58 pm »
I tried some of the open source projects and found there was no worthwhile saving by using the makefiles because I had to define a codeblocks project, copy source and header files from open project distribution and add source files and library links to the project (expected the makefile to do this step but it didn't - parse of makefile failed with 'missing separator.stop' on the first statement '@SET_MAKE@').

All open source projects I have seen come with a src directory and usually an include directory with header files. Copying these to an empty codeblocks project is fast and simple. If the resulting source directory contains only source files the Add files function on the Project menu is also very fast (Ctrl-A to multiselect all files - takes a few seconds only). If there is an include directory I can specify the path of this in the build options.

The codeblocks project directory may contain header files and other files too if there is no include directory on the open source distribution. I can Add source files to the project by multiselect (click source file with Ctrl key down), but this is fragile and unforgiving. If I accidentally click without the ctrl key all previous selections will be lost and I have start all over again - disheartening if it happens for item 125 of 130!

Suggestion: allow wild cards in source file specification, e.g. *.c.

Ken

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: How to use a makefile with codeblocks?
« Reply #3 on: January 31, 2012, 02:59:46 pm »
Try to add a whole directory (possibly the projects root-folder) with "Add files recursively", then you have a wildcard select option.

Offline resander

  • Multiple posting newcomer
  • *
  • Posts: 49
Re: How to use a makefile with codeblocks?
« Reply #4 on: January 31, 2012, 07:13:57 pm »
Thanks Jens,

This is the content of the the distribution directory of the sipsak open source project:

acinclude.m4  config.h.in   exit_code.h  Makefile.am    NEWS       sipsak.c
aclocal.m4    config.sub    header_f.c   Makefile.in    README     sipsak.h
auth.c        configure     header_f.h   md5.c          request.c  TODO
auth.h        configure.ac  helper.c     md5global.h    request.h  transport.c
AUTHORS       COPYING       helper.h     md5.h          shoot.c    transport.h
ChangeLog     depcomp       INSTALL      missing        shoot.h
config.guess  exit_code.c   install-sh   mkinstalldirs  sipsak.1

which contains source files, header files and other files. Sipsak is very small and does not use src and include directories. I copied this 'as is' to the codeblocks sipsaktrymake project directory.

The Project Add files needs to add the source files *.c only. I don't know how to use 'Add files recursively' to do this.

Ken
P.S. I could use wild cards to split the files into source and header file directories when copying from the sip distribution to the codeblocks using the OS copy function, but to me it is much nicer to be able to copy project distribution directory or src and include directories mechanically and sort out the wild cards on the codeblocks side for all open source projects.