John Waugh | 1 Jun 21:09 2011
Picon

Re: A few queries about Jam

On Tue, May 31, 2011 at 5:02 AM, Chris Molozian <chris <at> cmoz.me> wrote:
>
> As suggested I've tried:
>
> MkDir build ;
> ALL_LOCATE_TARGET = build ;
>
> to relocate all build output to a dedicated build folder but it appears to do nothing. The object files are
still built alongside source files and the libraries and executable build in the same directory as the
Jamfile. I'm not sure what I'm doing wrong.

Hi Chris,

I haven't used ALL_LOCATE_TARGET that much myself, but looking at
Jambase, it seems to be used by the SubDir rule. Therefore, be sure to
set it before you call SubDir.

Or perhaps you are not using SubDir at all? That could explain it, too.

-John
_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

John Waugh | 1 Jun 23:11 2011
Picon

Re: A few queries about Jam

> On Tue, May 31, 2011 at 5:02 AM, Chris Molozian <chris <at> cmoz.me> wrote:
>
> As suggested I've tried:
>
> MkDir build ;
> ALL_LOCATE_TARGET = build ;
>
> to relocate all build output to a dedicated build folder but it appears to do nothing. The object files are
still built alongside source files and the libraries and executable build in the same directory as the
Jamfile. I'm not sure what I'm doing wrong.

I forgot to mention: you can always set LOCATE on targets yourself, of course.
In fact, if you look in Jambase at how ALL_LOCATE_TARGET is used (it's
just 2 lines), it just sets the default LOCATE path.

LOCATE itself is a jam 'special' variable, which is used to bind a
target to a physical path on the file system.
c.f. http://public.perforce.com/public/jam/src/Jam.html#search

(apologies if you already knew this)

-John
_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

Diane Holt | 1 Jun 23:46 2011
Picon

Re: A few queries about Jam

SubDir sets:

LOCATE_TARGET = $(ALL_LOCATE_TARGET) $(SUBDIR) ;

So if ALL_LOCATE_TARGET isn't set, it defaults to SUBDIR, which is guaranteed to be set (since SubDir sets it).

Then the Object rules uses MakeLocate (which is much nicer than "LOCATE on", since it not only sets the output location, it mkdir's it for you, if needed) to set the location to $(LOCATE_TARGET).

If you're not using SubDir, I'd suggest you do. If the default rules/actions in Jambase don't suit your needs, you can always override them with your own (of the same name) -- last one in, wins. But if you can use the defaults, it just makes things easier for you -- that much less to write and maintain.

Diane

On Wed, Jun 1, 2011 at 2:11 PM, John Waugh <john.waugh <at> gmail.com> wrote:
> On Tue, May 31, 2011 at 5:02 AM, Chris Molozian <chris <at> cmoz.me> wrote:
>
> As suggested I've tried:
>
> MkDir build ;
> ALL_LOCATE_TARGET = build ;
>
> to relocate all build output to a dedicated build folder but it appears to do nothing. The object files are still built alongside source files and the libraries and executable build in the same directory as the Jamfile. I'm not sure what I'm doing wrong.

I forgot to mention: you can always set LOCATE on targets yourself, of course.
In fact, if you look in Jambase at how ALL_LOCATE_TARGET is used (it's
just 2 lines), it just sets the default LOCATE path.

LOCATE itself is a jam 'special' variable, which is used to bind a
target to a physical path on the file system.
c.f. http://public.perforce.com/public/jam/src/Jam.html#search

(apologies if you already knew this)

-John
_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming
Chris Molozian | 3 Jun 18:57 2011

Re: A few queries about Jam

Dear John,

Thank you very much for your help so far, please no need to apologise for detailing anything about the inner workings of Jam. I'm still very much a novice with this tool but getting very close to the perfect build setup for my (soon to be) open source project. This setup would complete item 2 in the Joel Test ;-) .

I setup homebrew on my brother's Apple Mac OS X and used it to install the necessary LLVM, D Compiler and Jam tools to test the build environment. The Jam build tool in the homebrew repository sets up the Perforce version of Jam. I added the additional rules for building D files to my Jamfile and all is working perfectly. The build script so far is:

# auxiliary rules to support building D code with perforce Jam
rule UserObject {
    switch $(>:S) {
     case .d : Dc $(<) : $(>) ;
     case * :
        Exit "Unknown suffix on " $(>) " - see UserObject rule in Jambase." ;
    }
}

rule Dc {
    Depends $(<) : $(>) ;
    DCFLAGS on $(<) += $(DCFLAGS) $(SUBDIRDCFLAGS) ;
}

actions Dc {
    $(DC) -c -of$(<) $(DCFLAGS) $(DOPTIM) $(>)
}

# override the Link action to correct for the dmd compiler -o flag
actions Link bind NEEDLIBS {
    $(LINK) $(LINKFLAGS) -of$(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS)
}


DC = dmd ;
DCFLAGS = -fPIC -O -inline -release -w -wi -I./imports/llvm-2.9 -I./src/ ;
C++FLAGS =
    -I/usr/include
    -DNDEBUG
    -D_GNU_SOURCE
    -D__STDC_LIMIT_MACROS
    -D__STDC_CONSTANT_MACROS
    -O3
    -fomit-frame-pointer
    -fno-exceptions
    -fPIC
    -Woverloaded-virtual
    -Wcast-qual ;   # should be generated from `llvm-config --cxxflags`
LINK = $(DC) ;
DFILES = [ GLOB src/ob2c : *.d ] ;

MainFromObjects ob2c : $(DFILES:S=.o) ;
Objects $(DFILES) ;
LinkLibraries ob2c : llvm-c-ext ;
Library llvm-c-ext :
    imports/llvm-2.9/llvm/Ext.cpp
    imports/llvm-2.9/llvm/Target.cpp ;

The only remaining addition I'd like to make is to force all build output to a dedicated build folder as you've been helping me with. I don't understand where to apply the SubDir rule and the ALL_LOCATE_TARGET variable. My project directory structure is as follows:
   code/
      |-- src/
      |-- imports/
      |-- build/        <-- folder for all build output
      |-- Jamfile

Cheers,

Chris


On 01/06/11 22:11, John Waugh wrote:
On Tue, May 31, 2011 at 5:02 AM, Chris Molozian <chris <at> cmoz.me> wrote: As suggested I've tried: MkDir build ; ALL_LOCATE_TARGET = build ; to relocate all build output to a dedicated build folder but it appears to do nothing. The object files are still built alongside source files and the libraries and executable build in the same directory as the Jamfile. I'm not sure what I'm doing wrong.
I forgot to mention: you can always set LOCATE on targets yourself, of course. In fact, if you look in Jambase at how ALL_LOCATE_TARGET is used (it's just 2 lines), it just sets the default LOCATE path. LOCATE itself is a jam 'special' variable, which is used to bind a target to a physical path on the file system. c.f. http://public.perforce.com/public/jam/src/Jam.html#search (apologies if you already knew this) -John
_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming
John Waugh | 3 Jun 23:03 2011
Picon

Re: A few queries about Jam

On Fri, Jun 3, 2011 at 9:57 AM, Chris Molozian <chris <at> cmoz.me> wrote:
>
> The only remaining addition I'd like to make is to force all build output to
> a dedicated build folder as you've been helping me with. I don't understand
> where to apply the SubDir rule and the ALL_LOCATE_TARGET variable. My
> project directory structure is as follows:
>    code/
>       |-- src/
>       |-- imports/
>       |-- build/        <-- folder for all build output
>       |-- Jamfile
>

Here's a Jamfile I created as a demo - the source files referenced are
just for a 'hello world' program.

# --- BEGIN Jamfile ---
ALL_LOCATE_TARGET = build ;
SubDir TOP ;

# Compile will fail if the destionations for ALL_LOCATE_TARGET
# don't exist, so be sure to create them
MkDir build/src ;
Depends proggie : build/src ;

Main myprogram : src/main.c src/foo.c ;
# --- END Jamfile ---

As I mentioned, I haven't used ALL_LOCATE_TARGET much myself, so
perhaps the MkDir/Depends stuff could be handled more automatically,
but that worked for me.

Does it make sense?

-John

_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

matthew conte | 4 Jun 00:21 2011

Re: A few queries about Jam

You shouldn't need to explicitly make the build directories, there.


We use ALL_LOCATE_TARGET and it works great for us. Just make sure you have it set up in your Jamrules, then at the top of each Jamfile ensure that you use SubDir. e.g. for a top level directory that has a src1 and src2 subdirectory, you should have this:

[top-level Jamfile]
SubDir TOP ;

# Stuff here

SubInclude $(TOP) src1 ;
SubInclude $(TOP) src2 ;

[src1 Jamfile]
SubDir TOP src1 ;

# stuff here

[src2 Jamfile]
SubDir TOP src2 ;

# stuff


In fact, we go a step further. Because we build for many different platforms, we actually want our build products to go into subdirectories, e.g. "temp/windows-debug" and "temp/macos-release", etc. So our Jamrules looks like this:

ALL_LOCATE_TARGET = temp ;
# Make LocateObjects be called at the end of the SubDir rule.
SUBDIRRULES += LocateObjects ;
rule LocateObjects
{
    # Build flavor is windows-debug, etc.
    LOCATE_TOKENS = $(ALL_LOCATE_TARGET) $(BUILD_FLAVOR) $(SUBDIR_TOKENS) ;

    # See the setup of these in Jambase's SubDir rule for reference.
    LOCATE_TARGET = [ FSubDirPath TOP $(LOCATE_TOKENS) ] ;
    LOCATE_SOURCE = [ FSubDirPath TOP $(LOCATE_TOKENS) ] ;
}

Note that this assumes a TOP, but that's fine for us.

Cheers,
--matt

On Fri, Jun 3, 2011 at 2:03 PM, John Waugh <john.waugh <at> gmail.com> wrote:
On Fri, Jun 3, 2011 at 9:57 AM, Chris Molozian <chris <at> cmoz.me> wrote:
>
> The only remaining addition I'd like to make is to force all build output to
> a dedicated build folder as you've been helping me with. I don't understand
> where to apply the SubDir rule and the ALL_LOCATE_TARGET variable. My
> project directory structure is as follows:
>    code/
>       |-- src/
>       |-- imports/
>       |-- build/        <-- folder for all build output
>       |-- Jamfile
>

Here's a Jamfile I created as a demo - the source files referenced are
just for a 'hello world' program.

# --- BEGIN Jamfile ---
ALL_LOCATE_TARGET = build ;
SubDir TOP ;

# Compile will fail if the destionations for ALL_LOCATE_TARGET
# don't exist, so be sure to create them
MkDir build/src ;
Depends proggie : build/src ;

Main myprogram : src/main.c src/foo.c ;
# --- END Jamfile ---


As I mentioned, I haven't used ALL_LOCATE_TARGET much myself, so
perhaps the MkDir/Depends stuff could be handled more automatically,
but that worked for me.

Does it make sense?

-John

_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming
John Waugh | 4 Jun 01:47 2011
Picon

Re: A few queries about Jam

On Fri, Jun 3, 2011 at 3:21 PM, matthew conte <matt <at> baisoku.org> wrote:
> You shouldn't need to explicitly make the build directories, there.

I found that I had to create the destination directory at least once.
Creating the dirs manually upfront works - any subsequent 'jam clean'
will only kill the files and not the dirs.
But if you ever removed the 'build' directory, AFAIK you'd get errors
the next time you built.

At least that's how it's playing out in my test case I'm toying with -
see below for output from a terminal session.

> We use ALL_LOCATE_TARGET and it works great for us. Just make sure you have
> it set up in your Jamrules...

Good point about putting it in Jamrules, rather than at the top of the
Jamfile. Putting it ahead of SubDir in Jamfile *seemed* unnecessarily
ugly.

Here's the output of a session where I don't have 'build/src' created
beforehand:

$ ls -R
Jamfile  Jamrules build    src

./build:

./src:
foo.c  foo.h  main.c

$ cat Jamrules
# --- BEGIN Jamrules ---
ALL_LOCATE_TARGET = build ;
# --- END Jamrules ---

$ cat Jamfile
# --- BEGIN Jamfile ---
SubDir TOP ;

Main myprog : src/main.c src/foo.c ;
# --- END Jamfile ---

$ ftjam
...found 19 target(s)...
...updating 3 target(s)...
Cc build/src/main.o
Assembler messages:
FATAL: can't create build/src/main.o: No such file or directory

cc -c -o build/src/main.o  -O  -I. src/main.c

...failed Cc build/src/main.o ...
Cc build/src/foo.o
Assembler messages:
FATAL: can't create build/src/foo.o: No such file or directory

cc -c -o build/src/foo.o  -O  -I. src/foo.c

...failed Cc build/src/foo.o ...
...skipped myprog for lack of src/main.o...
...failed updating 2 target(s)...
...skipped 1 target(s)...

$ mkdir build/src

$ ftjam
...found 19 target(s)...
...updating 3 target(s)...
Cc build/src/main.o
Cc build/src/foo.o
Link build/myprog
Chmod1 build/myprog
...updated 3 target(s)...

-John
_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

Diane Holt | 4 Jun 01:48 2011
Picon

Re: A few queries about Jam

> SubInclude $(TOP) src1 ;

That should be TOP not $(TOP) -- SubDir adds the $( ) for you. Jam will give you an error if you include the $( ), because SubDir is expecting it to be the name of the var, so it will try to expand a variable that doesn't exist (since you've passed it the value not the name).

Diane

On Fri, Jun 3, 2011 at 3:21 PM, matthew conte <matt <at> baisoku.org> wrote:
You shouldn't need to explicitly make the build directories, there.

We use ALL_LOCATE_TARGET and it works great for us. Just make sure you have it set up in your Jamrules, then at the top of each Jamfile ensure that you use SubDir. e.g. for a top level directory that has a src1 and src2 subdirectory, you should have this:

[top-level Jamfile]
SubDir TOP ;

# Stuff here

SubInclude $(TOP) src1 ;
SubInclude $(TOP) src2 ;

[src1 Jamfile]
SubDir TOP src1 ;

# stuff here

[src2 Jamfile]
SubDir TOP src2 ;

# stuff


In fact, we go a step further. Because we build for many different platforms, we actually want our build products to go into subdirectories, e.g. "temp/windows-debug" and "temp/macos-release", etc. So our Jamrules looks like this:

ALL_LOCATE_TARGET = temp ;
# Make LocateObjects be called at the end of the SubDir rule.
SUBDIRRULES += LocateObjects ;
rule LocateObjects
{
    # Build flavor is windows-debug, etc.
    LOCATE_TOKENS = $(ALL_LOCATE_TARGET) $(BUILD_FLAVOR) $(SUBDIR_TOKENS) ;

    # See the setup of these in Jambase's SubDir rule for reference.
    LOCATE_TARGET = [ FSubDirPath TOP $(LOCATE_TOKENS) ] ;
    LOCATE_SOURCE = [ FSubDirPath TOP $(LOCATE_TOKENS) ] ;
}

Note that this assumes a TOP, but that's fine for us.

Cheers,
--matt

On Fri, Jun 3, 2011 at 2:03 PM, John Waugh <john.waugh <at> gmail.com> wrote:
On Fri, Jun 3, 2011 at 9:57 AM, Chris Molozian <chris <at> cmoz.me> wrote:
>
> The only remaining addition I'd like to make is to force all build output to
> a dedicated build folder as you've been helping me with. I don't understand
> where to apply the SubDir rule and the ALL_LOCATE_TARGET variable. My
> project directory structure is as follows:
>    code/
>       |-- src/
>       |-- imports/
>       |-- build/        <-- folder for all build output
>       |-- Jamfile
>

Here's a Jamfile I created as a demo - the source files referenced are
just for a 'hello world' program.

# --- BEGIN Jamfile ---
ALL_LOCATE_TARGET = build ;
SubDir TOP ;

# Compile will fail if the destionations for ALL_LOCATE_TARGET
# don't exist, so be sure to create them
MkDir build/src ;
Depends proggie : build/src ;

Main myprogram : src/main.c src/foo.c ;
# --- END Jamfile ---


As I mentioned, I haven't used ALL_LOCATE_TARGET much myself, so
perhaps the MkDir/Depends stuff could be handled more automatically,
but that worked for me.

Does it make sense?

-John

_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming


_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming


_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming
Diane Holt | 4 Jun 02:07 2011
Picon

Re: A few queries about Jam

This is where you went wrong:

> Main myprog : src/main.c src/foo.c ;

You should either have this Jamfile do a SubInclude for src, and put this Main target in src/Jamfile, or you can add $(TOP)/src to SEARCH_SOURCE. I prefer the first one, since then you can build from the src subdir instead of always have to build from $TOP (eg., if you're working down in src on foo.c, after you're done editing, you can just 'jam' from there).

But either of those will get Main to MkDir your build subdir for you, because the rule will do a MakeLocate, and MakeLocate does both the MkDir and the "LOCATE on".

Diane

On Fri, Jun 3, 2011 at 4:47 PM, John Waugh <john.waugh <at> gmail.com> wrote:
On Fri, Jun 3, 2011 at 3:21 PM, matthew conte <matt <at> baisoku.org> wrote:
> You shouldn't need to explicitly make the build directories, there.

I found that I had to create the destination directory at least once.
Creating the dirs manually upfront works - any subsequent 'jam clean'
will only kill the files and not the dirs.
But if you ever removed the 'build' directory, AFAIK you'd get errors
the next time you built.

At least that's how it's playing out in my test case I'm toying with -
see below for output from a terminal session.

> We use ALL_LOCATE_TARGET and it works great for us. Just make sure you have
> it set up in your Jamrules...

Good point about putting it in Jamrules, rather than at the top of the
Jamfile. Putting it ahead of SubDir in Jamfile *seemed* unnecessarily
ugly.

Here's the output of a session where I don't have 'build/src' created
beforehand:

$ ls -R
Jamfile  Jamrules build    src

./build:

./src:
foo.c  foo.h  main.c

$ cat Jamrules
# --- BEGIN Jamrules ---
ALL_LOCATE_TARGET = build ;
# --- END Jamrules ---

$ cat Jamfile
# --- BEGIN Jamfile ---
SubDir TOP ;

Main myprog : src/main.c src/foo.c ;
# --- END Jamfile ---

$ ftjam
...found 19 target(s)...
...updating 3 target(s)...
Cc build/src/main.o
Assembler messages:
FATAL: can't create build/src/main.o: No such file or directory

cc -c -o build/src/main.o  -O  -I. src/main.c

...failed Cc build/src/main.o ...
Cc build/src/foo.o
Assembler messages:
FATAL: can't create build/src/foo.o: No such file or directory

cc -c -o build/src/foo.o  -O  -I. src/foo.c

...failed Cc build/src/foo.o ...
...skipped myprog for lack of src/main.o...
...failed updating 2 target(s)...
...skipped 1 target(s)...

$ mkdir build/src

$ ftjam
...found 19 target(s)...
...updating 3 target(s)...
Cc build/src/main.o
Cc build/src/foo.o
Link build/myprog
Chmod1 build/myprog
...updated 3 target(s)...


-John
_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming
John Waugh | 4 Jun 07:20 2011
Picon

Re: A few queries about Jam

On Fri, Jun 3, 2011 at 5:07 PM, Diane Holt <holt.diane <at> gmail.com> wrote:
> This is where you went wrong:
>
>> Main myprog : src/main.c src/foo.c ;
>
> You should either have this Jamfile do a SubInclude for src, and put this
> Main target in src/Jamfile, or you can add $(TOP)/src to SEARCH_SOURCE.
> ...
> either of those will get Main to MkDir your build subdir for you
>

Good point.
However, after fiddling around with these methods, I will just point
out (correct me if I'm wrong) that neither of these lend themselves to
having duplicately-named source files in different subdirectories.

Not that that's usually an issue, but the purist in me cares on some level (:

-John
_______________________________________________
jamming mailing list  -  jamming <at> maillist.perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming


Gmane