Chapter 7. Conditional compilation

One of the basic features of stirmake is conditional compilation. Both rules and additional dependencies can be put inside top-level @if statements. Also if you use pattern rules, they need to be instantiated by an array of filenames, and obviously that array can be modified inside @if statements.

An example of conditional compilation with pattern rules:

@toplevel
@strict
$IS_ARM=@false
$MACHINE `= ["cc", "-dumpmachine"]
$MACHINE = @chomp($MACHINE)
@if(@strcmp(@substr($MACHINE, 0, 4), "arm-") == 0)
$IS_ARM=@true
@endif

$OBJS = ["file1.o", "platformindependent.o"]
@if($IS_ARM)
$OBJS += ["armneonimpl.o"]
@endif

@phonyrule: 'all': 'libcommon.a'

@patrule: $OBJS: '%.o': '%.c'
@	["cc", "-c", "-o", $@, $<]

'libcommon.a': $(OBJS)
@	["rm", "-f", $@]
@	["ar", "rvs", $@, @@suffilter($^, ".o")]

In this case, if the "cc -dumpmachine" command prints arm-linux-gnueabihf, or something else that begins with arm-, the file armneonimpl.o is compiled in.

Also, entire rules and additional dependencies specified with @deponly can be inside top-level @if statements:

@toplevel
@strict
$IS_ARM=@false
$MACHINE `= ["cc", "-dumpmachine"]
$MACHINE = @chomp($MACHINE)
@if(@strcmp(@substr($MACHINE, 0, 4), "arm-") == 0)
$IS_ARM=@true
@endif

@phonyrule: 'all': 'libcommon.a'

$OBJS = ["file1.o", "platformindependent.o"]
@patrule: $OBJS: '%.o': '%.c'
@	["cc", "-c", "-o", $@, $<]

@if($IS_ARM)
'armneonimpl.o': 'armneonimpl.c'
@	["cc", "-c", "-o", $@, $<]
@deponly: 'libcommon.a': 'armneonimpl.o'
@endif


'libcommon.a': $(OBJS)
@	["rm", "-f", $@]
@	["ar", "rvs", $@, @@suffilter($^, ".o")]