@@ -42,6 +42,7 @@ output_file: std.Build.GeneratedFile,
42
42
style : Style ,
43
43
max_bytes : usize ,
44
44
include_path : []const u8 ,
45
+ include_guard_override : ? []const u8 ,
45
46
46
47
pub const base_id : Step.Id = .config_header ;
47
48
@@ -50,6 +51,7 @@ pub const Options = struct {
50
51
max_bytes : usize = 2 * 1024 * 1024 ,
51
52
include_path : ? []const u8 = null ,
52
53
first_ret_addr : ? usize = null ,
54
+ include_guard_override : ? []const u8 = null ,
53
55
};
54
56
55
57
pub fn create (owner : * std.Build , options : Options ) * ConfigHeader {
@@ -91,6 +93,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
91
93
92
94
.max_bytes = options .max_bytes ,
93
95
.include_path = include_path ,
96
+ .include_guard_override = options .include_guard_override ,
94
97
.output_file = .{ .step = & self .step },
95
98
};
96
99
@@ -201,7 +204,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
201
204
},
202
205
.blank = > {
203
206
try output .appendSlice (c_generated_line );
204
- try render_blank (& output , self .values , self .include_path );
207
+ try render_blank (& output , self .values , self .include_path , self . include_guard_override );
205
208
},
206
209
.nasm = > {
207
210
try output .appendSlice (asm_generated_line );
@@ -415,15 +418,19 @@ fn render_blank(
415
418
output : * std .ArrayList (u8 ),
416
419
defines : std .StringArrayHashMap (Value ),
417
420
include_path : []const u8 ,
421
+ include_guard_override : ? []const u8 ,
418
422
) ! void {
419
- const include_guard_name = try output .allocator .dupe (u8 , include_path );
420
- for (include_guard_name ) | * byte | {
421
- switch (byte .* ) {
422
- 'a' ... 'z' = > byte .* = byte .* - 'a' + 'A' ,
423
- 'A' ... 'Z' , '0' ... '9' = > continue ,
424
- else = > byte .* = '_' ,
423
+ const include_guard_name = include_guard_override orelse blk : {
424
+ const name = try output .allocator .dupe (u8 , include_path );
425
+ for (name ) | * byte | {
426
+ switch (byte .* ) {
427
+ 'a' ... 'z' = > byte .* = byte .* - 'a' + 'A' ,
428
+ 'A' ... 'Z' , '0' ... '9' = > continue ,
429
+ else = > byte .* = '_' ,
430
+ }
425
431
}
426
- }
432
+ break :blk name ;
433
+ };
427
434
428
435
try output .appendSlice ("#ifndef " );
429
436
try output .appendSlice (include_guard_name );
0 commit comments