Author Topic: How to write custom make command for compiling single file?  (Read 5869 times)

Offline moyamu

  • Single posting newcomer
  • *
  • Posts: 2
How to write custom make command for compiling single file?
« on: October 21, 2011, 12:10:15 pm »
I would like to define a custom make command to compile a single file.
The command looks like this:

/my/build/tool my_output_directory/$file.o

I used $file because it is mentioned at the bottom of the "Make commands"
dialog, but $file always yields an empty string.

Is it possible to insert the current file name into the command?

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: How to write custom make command for compiling single file?
« Reply #1 on: October 21, 2011, 11:03:20 pm »
Custom make commands are probably not what you are looking for (as it does not seem you are using a makefile).

See if these instructions are applicable to your problem.  (I think this page may be slightly out of date as my version of Code::Blocks does not report the use of underscores in any of its variables.)

Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: How to write custom make command for compiling single file?
« Reply #2 on: October 23, 2011, 03:39:16 pm »
I'm not really sure about what you want to do but, if you want to compile a program made from only one C/C++ source file with the GUI of codeblocks, you can with those simple steps:
_ open the concerned file in C::B
_ go to "Build" menu and then "Compile current file"
Your .exe will appear in the same directory as your source file, without the need of a project file. (I have used it yesterday with the last nightly build on linux, and I can see no reason it does not work with the official release on windows, but I can not test myself to be sure.)

Offline moyamu

  • Single posting newcomer
  • *
  • Posts: 2
Re: How to write custom make command for compiling single file?
« Reply #3 on: October 25, 2011, 12:22:58 pm »
I am not using a makefile because I have to interface with an existing build system which
provides its own commands for everything. This can be done by entering the commands in
"Customize/Custom build". Everything works fine for build, rebuild and clean.

My "Compile Single File" command looks like this:
   mybuildtool --compile-only $(CurrentFileName)

This works well when editing a source file and pressing Ctrl-F7.

It does not work, however, when I select "Compile" in the context menu of the workspace view.
$(CurrentFileName) is replaced by the file beeing edited, and not by the file selected in the
workspace view.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: How to write custom make command for compiling single file?
« Reply #4 on: November 01, 2011, 03:26:36 am »
(Sorry, I think this thread got lost.)

Is the $(CurrentFileName) macro something you defined?

It does not work, however, when I select "Compile" in the context menu of the workspace view.
$(CurrentFileName) is replaced by the file beeing edited, and not by the file selected in the
workspace view.
Are you saying that you right click on a file in the Projects tab of the Management panel and click Compile/Build, it substitutes the wrong filename into the custom build command you setup?

By the way, what version of Code::Blocks are you using?