Skip to content

Commit

Permalink
build: MSYS2 MinGW64
Browse files Browse the repository at this point in the history
  • Loading branch information
fleimgruber committed Oct 2, 2024
1 parent a053cd5 commit 8d79ad8
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 4 deletions.
38 changes: 34 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };

const t = target.result;

const protoc_program = switch (t.os.tag) {
.windows => "protoc",
else => "proto-c",
};

var flags = std.BoundedArray([]const u8, 16){};
flags.appendSliceAssumeCapacity(&EXE_FLAGS);

const protocc_run = b.addSystemCommand(&.{"protoc-c"});
const protocc_run = b.addSystemCommand(&.{protoc_program});
protocc_run.addArgs(&.{"--c_out=."});
protocc_run.addArgs(&PROTO_SOURCES);

Expand All @@ -30,9 +37,32 @@ pub fn build(b: *std.Build) void {
.files = &PROTO_GENERATED_SOURCES,
.flags = flags.constSlice(),
});
sigbak_exe.linkSystemLibrary("libcrypto");
sigbak_exe.linkSystemLibrary("libprotobuf-c");
sigbak_exe.linkSystemLibrary("sqlite3");

switch (t.os.tag) {
.windows => {
sigbak_exe.addLibraryPath(std.Build.LazyPath{
.cwd_relative = "C:/Users/LeimgruberF/opt/msys64/mingw64/lib"
});
sigbak_exe.addIncludePath(std.Build.LazyPath{
.cwd_relative = "C:/Users/LeimgruberF/opt/msys64/mingw64/include"
});
},
else => {},
}

switch (t.os.tag) {
.windows => {
sigbak_exe.linkSystemLibrary("ssl");
sigbak_exe.linkSystemLibrary("protobuf-c");
sigbak_exe.linkSystemLibrary("sqlite3");
},
else => {
sigbak_exe.linkSystemLibrary("libcrypto");
sigbak_exe.linkSystemLibrary("libprotobuf-c");
sigbak_exe.linkSystemLibrary("sqlite3");
},
}

sigbak_exe.linkLibC();

sigbak_exe.step.dependOn(&protocc_run.step);
Expand Down
7 changes: 7 additions & 0 deletions compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,11 @@ void *reallocarray(void *, size_t, size_t);
int unveil(const char *, const char *);
#endif

/* ensure mkdir(pathname, mode) exists */
#ifdef HAVE_MKDIR
# ifdef MKDIR_TAKES_ONE_ARG
# define mkdir(a, b) _mkdir(a)
# endif
#endif

#endif
19 changes: 19 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@

#endif

/*
* MSYS2/MinWG64
*/

#ifdef __MINGW64__

#define _GNU_SOURCE

#define HAVE_ASPRINTF
#define HAVE_BE32TOH
#define HAVE_MKDIR
#define MKDIR_TAKES_ONE_ARG
#define HAVE_READPASSPHRASE

#define UTIME_OMIT -1L
#define O_DIRECTORY 0L
#define O_CLOEXEC 0L
#endif

/*
* DragonFly BSD
*/
Expand Down
68 changes: 68 additions & 0 deletions mingw64.Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
PREFIX?= /usr/local
BINDIR?= ${PREFIX}/bin
MANDIR?= ${PREFIX}/man

CC?= cc
INSTALL?= install
PKG_CONFIG?= pkg-config
PROTOC?= protoc

LIBCRYPTO_PKG?= libcrypto
LIBPROTOBUF_C_PKG?= libprotobuf-c
SQLITE3_PKG?= sqlite3

PKGS?= ${LIBCRYPTO_PKG} ${LIBPROTOBUF_C_PKG} ${SQLITE3_PKG}

PKG_CFLAGS!= ${PKG_CONFIG} --cflags ${PKGS}
PKG_LDFLAGS!= ${PKG_CONFIG} --libs ${PKGS}

CFLAGS+= ${PKG_CFLAGS}
CFLAGS+= -I/mingw64/include
CFLAGS+= -Icompat
LDFLAGS+= ${PKG_LDFLAGS}

PROTOS= backup.proto database.proto
PROTO_HDRS= ${PROTOS:.proto=.pb-c.h}
PROTO_SRCS= ${PROTOS:.proto=.pb-c.c}
PROTO_OBJS= ${PROTO_SRCS:.c=.o}

COMPAT_OBJS= compat/asprintf.o compat/bs_cbb.o compat/err.o \
compat/explicit_bzero.o compat/fopen.o compat/getprogname.o \
compat/hkdf.o compat/hmac_ctx_new.o compat/pledge.o \
compat/readpassphrase.o compat/reallocarray.o compat/unveil.o

OBJS= cmd-check-backup.o cmd-dump-backup.o cmd-export-attachments.o \
cmd-export-avatars.o cmd-export-database.o \
cmd-export-messages.o mime.o sbk-attachment-tree.o \
sbk-attachment.o sbk-database.o sbk-edit.o sbk-file.o \
sbk-frame.o sbk-mention.o sbk-message.o sbk-open.o \
sbk-quote.o sbk-reaction.o sbk-read.o sbk-recipient-tree.o \
sbk-recipient.o sbk-sqlite.o sbk-thread.o sigbak.o \
${PROTO_OBJS} ${COMPAT_OBJS}

.PHONY: all clean install

.SUFFIXES:
.SUFFIXES: .c .pb-c.o .o .pb-c.c .pb-c.h .proto

.c.o .pb-c.c.pb-c.o:
${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ $<

.proto.pb-c.c .proto.pb-c.h:
${PROTOC} --c_out=. $<

all: sigbak

sigbak: ${OBJS}
${CC} -o $@ ${OBJS} ${LDFLAGS}

${OBJS}: config.h ${PROTO_HDRS}

clean:
rm -f sigbak sigbak.core core ${PROTO_SRCS} ${PROTO_HDRS} ${OBJS}

install: all
${INSTALL} -dm 755 ${DESTDIR}${BINDIR}
${INSTALL} -dm 755 ${DESTDIR}${MANDIR}/man1
${INSTALL} -m 555 sigbak ${DESTDIR}${BINDIR}
${INSTALL} -m 444 sigbak.1 ${DESTDIR}${MANDIR}/man1

0 comments on commit 8d79ad8

Please sign in to comment.