diff --git a/build.zig b/build.zig new file mode 100644 index 00000000..2829ca3a --- /dev/null +++ b/build.zig @@ -0,0 +1,115 @@ +const std = @import("std"); + +const VERSION: std.SemanticVersion = .{ + .major = 0, + .minor = 4, + .patch = 8, +}; + +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + // On Windows, given there is no standard lib install dir etc., we rather + // by default build static lib. + const build_shared = b.option( + bool, + "md4c-shared", + "Build md4c as a shared library", + ) orelse !target.result.isMinGW(); + + // build options + var with_utf8 = b.option(bool, "utf8", "Use UTF8") orelse false; + const with_utf16 = b.option(bool, "utf16", "Use UTF16") orelse false; + const with_ascii = b.option(bool, "ascii", "Use UTF8") orelse false; + + // defaults to UTF8 if nothing else set + if (!with_utf8 and !with_utf16 and !with_ascii) { + with_utf8 = true; + } + + const lib = if (build_shared) + b.addSharedLibrary(.{ + .name = "md4c", + .target = target, + .optimize = optimize, + .version = VERSION, + }) + else + b.addStaticLibrary(.{ + .name = "md4c", + .target = target, + .optimize = optimize, + }); + + lib.addCSourceFiles(.{ + .files = &md4c_sources, + .flags = &md4c_flags, + }); + + setDefines(lib, with_utf8, with_utf16, with_ascii); + lib.linkLibC(); + lib.installHeader(b.path("src/md4c.h"), "md4c.h"); + b.installArtifact(lib); + + const exe = b.addExecutable(.{ + .name = "md2html", + .target = target, + .optimize = optimize, + }); + + setDefines(exe, with_utf8, with_utf16, with_ascii); + exe.addCSourceFiles(.{ + .files = &md2html_sources, + .flags = &md4c_flags, + }); + exe.linkLibC(); + + const install_exe = b.addInstallArtifact(exe, .{}); + const md2html_step = b.step("md2html", "Compile the md2html executable"); + md2html_step.dependOn(&install_exe.step); +} + +fn setDefines( + lib_or_exe: *std.Build.Step.Compile, + with_utf8: bool, + with_utf16: bool, + with_ascii: bool, +) void { + lib_or_exe.root_module.addCMacro( + "MD_VERSION_MAJOR", + std.fmt.comptimePrint("{d}", .{VERSION.major}), + ); + lib_or_exe.root_module.addCMacro( + "MD_VERSION_MINOR", + std.fmt.comptimePrint("{d}", .{VERSION.minor}), + ); + lib_or_exe.root_module.addCMacro( + "MD_VERSION_RELEASE", + std.fmt.comptimePrint("{d}", .{VERSION.patch}), + ); + + if (with_utf8) { + lib_or_exe.defineCMacro("MD4C_USE_UTF8", "1"); + } else if (with_ascii) { + lib_or_exe.defineCMacro("MD4C_USE_ASCII", "1"); + } else if (with_utf16) { + lib_or_exe.defineCMacro("MD4C_USE_UTF16", "1"); + } +} + +const md4c_flags = [_][]const u8{ + "-Wall", +}; + +const md4c_sources = [_][]const u8{ + "src/md4c.c", +}; + +const md2html_sources = [_][]const u8{ + "src/md4c.c", + "src/md4c-html.c", + "src/entity.c", + "md2html/cmdline.c", + "md2html/md2html.c", +}; diff --git a/src/md4c.h b/src/md4c.h index 8d6be1cb..e4a34746 100644 --- a/src/md4c.h +++ b/src/md4c.h @@ -164,7 +164,7 @@ typedef enum MD_TEXTTYPE { MD_TEXT_SOFTBR, /* '\n' in source text where it is not semantically meaningful (soft break) */ /* Entity. - * (a) Named entity, e.g.   + * (a) Named entity, e.g.   * (Note MD4C does not have a list of known entities. * Anything matching the regexp /&[A-Za-z][A-Za-z0-9]{1,47};/ is * treated as a named entity.)