@@ -16,6 +16,8 @@ pub fn build(b: *std.Build) !void {
1616 _ = copyFiles .addCopyFile (b .path ("src/config.h.generic" ), "config.h" );
1717 _ = copyFiles .addCopyFile (b .path ("src/pcre2.h.generic" ), "pcre2.h" );
1818
19+ // pcre2-8/16/32.so
20+
1921 const lib = std .Build .Step .Compile .create (b , .{
2022 .name = b .fmt ("pcre2-{s}" , .{@tagName (codeUnitWidth )}),
2123 .root_module = .{
@@ -27,22 +29,21 @@ pub fn build(b: *std.Build) !void {
2729 .linkage = linkage ,
2830 });
2931
32+ lib .defineCMacro ("HAVE_CONFIG_H" , null );
33+ lib .defineCMacro ("HAVE_MEMMOVE" , null );
34+ lib .defineCMacro ("PCRE2_CODE_UNIT_WIDTH" , @tagName (codeUnitWidth ));
35+ lib .defineCMacro ("SUPPORT_UNICODE" , null );
3036 if (linkage == .static ) {
31- try lib .root_module . c_macros . append ( b . allocator , "-DPCRE2_STATIC" );
37+ lib .defineCMacro ( "PCRE2_STATIC" , null );
3238 }
3339
34- lib .root_module .addCMacro ("PCRE2_CODE_UNIT_WIDTH" , @tagName (codeUnitWidth ));
40+ lib .addIncludePath (b .path ("src" ));
41+ lib .addIncludePath (copyFiles .getDirectory ());
3542
3643 lib .addCSourceFile (.{
3744 .file = copyFiles .addCopyFile (b .path ("src/pcre2_chartables.c.dist" ), "pcre2_chartables.c" ),
38- .flags = &.{
39- "-DHAVE_CONFIG_H" ,
40- },
4145 });
4246
43- lib .addIncludePath (b .path ("src" ));
44- lib .addIncludePath (copyFiles .getDirectory ());
45-
4647 lib .addCSourceFiles (.{
4748 .files = &.{
4849 "src/pcre2_auto_possess.c" ,
@@ -56,6 +57,7 @@ pub fn build(b: *std.Build) !void {
5657 "src/pcre2_error.c" ,
5758 "src/pcre2_extuni.c" ,
5859 "src/pcre2_find_bracket.c" ,
60+ "src/pcre2_jit_compile.c" ,
5961 "src/pcre2_maketables.c" ,
6062 "src/pcre2_match.c" ,
6163 "src/pcre2_match_data.c" ,
@@ -73,12 +75,79 @@ pub fn build(b: *std.Build) !void {
7375 "src/pcre2_valid_utf.c" ,
7476 "src/pcre2_xclass.c" ,
7577 },
76- .flags = &.{
77- "-DHAVE_CONFIG_H" ,
78- "-DPCRE2_STATIC" ,
79- },
8078 });
8179
8280 lib .installHeader (b .path ("src/pcre2.h.generic" ), "pcre2.h" );
8381 b .installArtifact (lib );
82+
83+
84+ // pcre2test
85+
86+ const pcre2test = b .addExecutable (.{
87+ .name = "pcre2test" ,
88+ .target = target ,
89+ .optimize = optimize ,
90+ });
91+
92+
93+ // pcre2-posix.so
94+
95+ if (codeUnitWidth == CodeUnitWidth .@"8" ) {
96+ const posixLib = std .Build .Step .Compile .create (b , .{
97+ .name = "pcre2-posix" ,
98+ .root_module = .{
99+ .target = target ,
100+ .optimize = optimize ,
101+ .link_libc = true ,
102+ },
103+ .kind = .lib ,
104+ .linkage = linkage ,
105+ });
106+
107+ posixLib .defineCMacro ("HAVE_CONFIG_H" , null );
108+ posixLib .defineCMacro ("HAVE_MEMMOVE" , null );
109+ posixLib .defineCMacro ("PCRE2_CODE_UNIT_WIDTH" , @tagName (codeUnitWidth ));
110+ posixLib .defineCMacro ("SUPPORT_UNICODE" , null );
111+ if (linkage == .static ) {
112+ posixLib .defineCMacro ("PCRE2_STATIC" , null );
113+ }
114+
115+ posixLib .addIncludePath (b .path ("src" ));
116+ posixLib .addIncludePath (copyFiles .getDirectory ());
117+
118+ posixLib .addCSourceFiles (.{
119+ .files = &.{
120+ "src/pcre2posix.c" ,
121+ },
122+ });
123+
124+ b .installArtifact (posixLib );
125+
126+ pcre2test .linkLibrary (posixLib );
127+ }
128+
129+
130+ // pcre2test (again)
131+
132+ pcre2test .defineCMacro ("HAVE_CONFIG_H" , null );
133+ pcre2test .defineCMacro ("HAVE_MEMMOVE" , null );
134+ pcre2test .defineCMacro ("HAVE_UNISTD_H" , null );
135+ pcre2test .defineCMacro ("HAVE_STRERROR" , null );
136+ pcre2test .defineCMacro ("SUPPORT_UNICODE" , null );
137+ pcre2test .defineCMacro (b .fmt ("SUPPORT_PCRE2_{s}" , .{@tagName (codeUnitWidth )}), null );
138+ if (linkage == .static ) {
139+ pcre2test .defineCMacro ("PCRE2_STATIC" , null );
140+ }
141+
142+ pcre2test .addIncludePath (b .path ("src" ));
143+ pcre2test .addIncludePath (copyFiles .getDirectory ());
144+
145+ pcre2test .addCSourceFile (.{
146+ .file = b .path ("src/pcre2test.c" ),
147+ });
148+
149+ pcre2test .linkLibC ();
150+ pcre2test .linkLibrary (lib );
151+
152+ b .installArtifact (pcre2test );
84153}
0 commit comments