Skip to content

Commit

Permalink
Small changes needed to compile on MacOS/Linux using libarchive, libc…
Browse files Browse the repository at this point in the history
…url and openssl from pkg-config .
  • Loading branch information
Keve committed Nov 11, 2024
1 parent 7f6d928 commit c2c0559
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*.log
*.gz
*.pc
*.dylib
jimsh0
tags
TAGS
Expand Down
9 changes: 9 additions & 0 deletions auto.def
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ if {[pkg-config-init 0]} {
if {![pkg-config libcurl]} {
user-error "Unable to find libcurl"
}
user-notice LIBCURL_CFLAGS=[get-define PKG_LIBCURL_CFLAGS]
user-notice LIBCURL_LDLAGS=[get-define PKG_LIBCURL_LDFLAGS]
user-notice LIBCURL_LIBS=[get-define PKG_LIBCURL_LIBS]
}
if {[opt-bool with-libarchive.pc]} {
if {![pkg-config libarchive]} {
Expand All @@ -346,12 +349,18 @@ if {[pkg-config-init 0]} {
cc-check-functions archive_write_add_filter_zstd
}
}
user-notice LIBARCHIVE_CFLAGS=[get-define PKG_LIBARCHIVE_CFLAGS]
user-notice LIBARCHIVE_LDLAGS=[get-define PKG_LIBARCHIVE_LDFLAGS]
user-notice LIBARCHIVE_LIBS=[get-define PKG_LIBARCHIVE_LIBS]
}

if {[opt-bool with-openssl.pc]} {
if {![pkg-config openssl]} {
user-error "Unable to find openssl"
}
user-notice OPENSSL_CFLAGS=[get-define PKG_OPENSSL_CFLAGS]
user-notice OPENSSL_LDLAGS=[get-define PKG_OPENSSL_LDFLAGS]
user-notice OPENSSL_LIBS=[get-define PKG_OPENSSL_LIBS]
}
}

Expand Down
4 changes: 3 additions & 1 deletion libpkg/Makefile.autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ LOCAL_LDFLAGS+= -L$(top_builddir)/external/libmachista -lmachista_pic \
SRCS+= pkg_macho.c
@else
SRCS+= pkg_elf.c
LOCAL_LDFLAGS+= -Wl,--version-script=$(top_srcdir)/libpkg/libpkg.ver,--undefined-version \
# --undefined-version is a FreeBSD ld option
LOCAL_LDFLAGS+= -Wl,--version-script=$(top_srcdir)/libpkg/libpkg.ver
#LOCAL_LDFLAGS+= -Wl,--version-script=$(top_srcdir)/libpkg/libpkg.ver,--undefined-version
@endif

@if libelf-internal
Expand Down
5 changes: 3 additions & 2 deletions libpkg/pkg_macho.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ analyse_macho(struct pkg *pkg, const char *fpath,
xasprintf(&libname, "%s.%s", march->mat_install_name, ai->name);
pkg_addshlib_provided(pkg, libname);
is_shlib = true;
}


/* Now find all dependencies */
for (macho_loadcmd_t *cmd = march->mat_loadcmds; cmd != NULL; cmd = cmd->next) {
Expand Down Expand Up @@ -140,6 +140,7 @@ analyse_macho(struct pkg *pkg, const char *fpath,

action(actdata, pkg, fpath, libname, is_shlib);
}
}
}

return EPKG_OK;
Expand Down Expand Up @@ -331,7 +332,7 @@ pkg_arch_to_legacy(const char *arch, char *dest, size_t sz)
/* Map the architecture name to its CPU type */
ai = NXGetArchInfoFromName(arch + i);
if (ai == NULL) {
pkg_emit_error("could not find architecture info for %s", arch + i);
// pkg_emit_error("could not find architecture info for %s", arch + i);
return EPKG_FATAL;
}

Expand Down
6 changes: 5 additions & 1 deletion libpkg/pkg_repo_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ pkg_create_repo_thread(void *arg)
ucl_object_emit_streamline_add_object(te->ctx, o);
ucl_object_emit_fd(o, UCL_EMIT_JSON_COMPACT, te->mfd);
dprintf(te->mfd, "\n");
#if defined(_DARWIN_C_SOURCE) || defined(__APPLE__)
fcntl(te->mfd, F_FULLFSYNC);
#else
fdatasync(te->mfd);
#endif
ucl_object_unref(o);

pthread_mutex_unlock(&te->flock);
Expand Down Expand Up @@ -397,7 +401,7 @@ pkg_create_repo_thread(void *arg)
return (NULL);
}

#ifdef __linux__
#if defined (__linux__) || defined(_DARWIN_C_SOURCE) || defined (__APPLE__)
typedef const FTSENT *FTSENTP;
#else
typedef const FTSENT *const FTSENTP;
Expand Down
11 changes: 8 additions & 3 deletions src/Makefile.autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LIBPKGFLAT= -L$(top_builddir)/libpkg -lpkg_flat
OTHER_LIBS= @EXTRA_LIBS@ -lm -pthread

@if HAVE_PKG_LIBARCHIVE
OTHER_LIBS+= @PKG_LIBARCHIVE_LDFLAGS@ @PKG_LIBARCHIVE_LIBS_STATIC@
OTHER_LIBS+= @PKG_LIBARCHIVE_LDFLAGS@ @PKG_LIBARCHIVE_LIBS@
LOCAL_CFLAGS+= @PKG_LIBARCHIVE_CFLAGS@
@else
OTHER_LIBS+= -larchive -lbz2 -lz -llzma @ZSTDLIB@
Expand Down Expand Up @@ -78,12 +78,17 @@ OTHER_LIBS+= -lmd

@if PKG_OPENSSL_LIBS
LOCAL_CFLAGS+= @PKG_OPENSSL_CFLAGS@
LOCAL_LDFLAGS+= @PKG_OPENSSL_LDFLAGS@
OTHER_LIBS+= @PKG_OPENSSL_LIBS@
OTHER_LIBS+= @PKG_OPENSSL_LDFLAGS@ @PKG_OPENSSL_LIBS@
@else
OTHER_LIBS+= -lssl -lcrypto
@endif

@if PKG_LIBCURL_LIBS
LOCAL_CFLAGS+= @PKG_LIBCURL_CFLAGS@
LOCAL_LDFLAGS+= @PKG_LIBCURL_LDFLAGS@
OTHER_LIBS+= @PKG_LIBCURL_LIBS@
@endif

@if libmachista
LOCAL_LDFLAGS= $(LIBPKGFLAT) $(LIBS) $(OTHER_LIBS) -lresolv
STATIC_LDFLAGS= $(LIBPKGFLAT) $(LIBS) $(OTHER_LIBS) -lresolv
Expand Down
12 changes: 11 additions & 1 deletion tests/Makefile.autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ LIBS= \
@EXTRA_LIBS@

@if HAVE_PKG_LIBARCHIVE
LIBS+= @PKG_LIBARCHIVE_LDFLAGS@ @PKG_LIBARCHIVE_LIBS_STATIC@
CFLAGS+= @PKG_LIBARCHIVE_CFLAGS@
LIBS+= @PKG_LIBARCHIVE_LDFLAGS@ @PKG_LIBARCHIVE_LIBS@
@else
LIBS+= -L/usr/lib -larchive -lbz2 -lz -llzma
@endif
Expand All @@ -136,6 +137,15 @@ OTHER_LIBS+= -ldl
@if HAVE_LIBRESOLV
OTHER_LIBS+= -lresolv
@endif
@if PKG_LIBCURL_LIBS
CFLAGS+= @PKG_LIBCURL_CFLAGS@
LIBS+= @PKG_LIBCURL_LDFLAGS@ @PKG_LIBCURL_LIBS@
@endif
@if PKG_OPENSSL_LIBS
CFLAGS+= @PKG_OPENSSL_CFLAGS@
LIBS+= @PKG_OPENSSL_LDFLAGS@ @PKG_OPENSSL_LIBS@
@endif


# Hack to determine we are on osx
@if libmachista
Expand Down

0 comments on commit c2c0559

Please sign in to comment.