News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

How to write custom make command for compiling single file?

Started by moyamu, October 21, 2011, 12:10:15 PM

Previous topic - Next topic

moyamu

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?

Alpha

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.)

Freem

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.)

moyamu

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.

Alpha

(Sorry, I think this thread got lost.)

Is the $(CurrentFileName) macro something you defined?

Quote from: moyamu on October 25, 2011, 12:22:58 PM
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?