| ... | @@ -244,6 +244,7 @@ const usage_build_generic = | ... | @@ -244,6 +244,7 @@ const usage_build_generic = |
| 244 | \\ -I[dir] Add directory to include search path | 244 | \\ -I[dir] Add directory to include search path |
| 245 | \\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted) | 245 | \\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted) |
| 246 | \\ --libc [file] Provide a file which specifies libc paths | 246 | \\ --libc [file] Provide a file which specifies libc paths |
| | 247 | \\ -cflags [flags] -- Set extra flags for the next positional C source files |
| 247 | \\ | 248 | \\ |
| 248 | \\Link Options: | 249 | \\Link Options: |
| 249 | \\ -l[lib], --library [lib] Link against system library | 250 | \\ -l[lib], --library [lib] Link against system library |
| ... | @@ -376,6 +377,9 @@ pub fn buildOutputType( | ... | @@ -376,6 +377,9 @@ pub fn buildOutputType( |
| 376 | var clang_argv = std.ArrayList([]const u8).init(gpa); | 377 | var clang_argv = std.ArrayList([]const u8).init(gpa); |
| 377 | defer clang_argv.deinit(); | 378 | defer clang_argv.deinit(); |
| 378 | | 379 | |
| | 380 | var extra_cflags = std.ArrayList([]const u8).init(gpa); |
| | 381 | defer extra_cflags.deinit(); |
| | 382 | |
| 379 | var lld_argv = std.ArrayList([]const u8).init(gpa); | 383 | var lld_argv = std.ArrayList([]const u8).init(gpa); |
| 380 | defer lld_argv.deinit(); | 384 | defer lld_argv.deinit(); |
| 381 | | 385 | |
| ... | @@ -469,6 +473,14 @@ pub fn buildOutputType( | ... | @@ -469,6 +473,14 @@ pub fn buildOutputType( |
| 469 | if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg}); | 473 | if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg}); |
| 470 | i += 1; | 474 | i += 1; |
| 471 | main_pkg_path = args[i]; | 475 | main_pkg_path = args[i]; |
| | 476 | } else if (mem.eql(u8, arg, "-cflags")) { |
| | 477 | extra_cflags.shrinkRetainingCapacity(0); |
| | 478 | while (true) { |
| | 479 | i += 1; |
| | 480 | if (i + 1 >= args.len) fatal("expected -- after -cflags", .{}); |
| | 481 | if (mem.eql(u8, args[i], "--")) break; |
| | 482 | try extra_cflags.append(args[i]); |
| | 483 | } |
| 472 | } else if (mem.eql(u8, arg, "--color")) { | 484 | } else if (mem.eql(u8, arg, "--color")) { |
| 473 | if (i + 1 >= args.len) { | 485 | if (i + 1 >= args.len) { |
| 474 | fatal("expected [auto|on|off] after --color", .{}); | 486 | fatal("expected [auto|on|off] after --color", .{}); |
| ... | @@ -713,8 +725,10 @@ pub fn buildOutputType( | ... | @@ -713,8 +725,10 @@ pub fn buildOutputType( |
| 713 | try link_objects.append(arg); | 725 | try link_objects.append(arg); |
| 714 | }, | 726 | }, |
| 715 | .assembly, .c, .cpp, .h, .ll, .bc => { | 727 | .assembly, .c, .cpp, .h, .ll, .bc => { |
| 716 | // TODO a way to pass extra flags on the CLI | 728 | try c_source_files.append(.{ |
| 717 | try c_source_files.append(.{ .src_path = arg }); | 729 | .src_path = arg, |
| | 730 | .extra_flags = try arena.dupe([]const u8, extra_cflags.items), |
| | 731 | }); |
| 718 | }, | 732 | }, |
| 719 | .shared_library => { | 733 | .shared_library => { |
| 720 | fatal("linking against dynamic libraries not yet supported", .{}); | 734 | fatal("linking against dynamic libraries not yet supported", .{}); |