Skip to content

Commit e94df59

Browse files
committed
[acquire/CMakeLists.txt] Improve C code parsing and generating ; [*.h] Try and get build working and tests running on macOS
1 parent a4ae7cc commit e94df59

File tree

9 files changed

+549
-201
lines changed

9 files changed

+549
-201
lines changed

acquire/CMakeLists.txt

Lines changed: 505 additions & 194 deletions
Large diffs are not rendered by default.

acquire/acquire_checksums.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ extern "C" {
2020
#endif
2121
#include "acquire_config.h"
2222
#include "acquire_string_extras.h"
23+
#ifdef USE_LIBRHASH
24+
#include "acquire_librhash.h"
25+
#endif /* USE_LIBRHASH */
2326

2427
extern LIBACQUIRE_LIB_EXPORT bool crc32c(const char *, const char *);
2528

acquire/acquire_libfetch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,10 @@ static int fetch(char *URL, const char *path) {
789789
}
790790

791791
/* CUSTOM libacquire stuff */
792-
792+
#ifndef DOWNLOAD_DIR_IMPL
793+
#define DOWNLOAD_DIR_IMPL
793794
const char *get_download_dir() { return ".downloads"; }
795+
#endif /* !DOWNLOAD_DIR_IMPL */
794796

795797
int download(const char *url, enum Checksum checksum, const char *hash,
796798
const char target_location[NAME_MAX], bool follow, size_t retry,

acquire/acquire_librhash.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ bool sha512(const char *filename, const char *gold_hash) {
6767
/* X(sha512, RHASH_SHA512, comma) \ */
6868
#define comma ,
6969
#define blank /* nothing */
70+
#ifndef HASHES
7071
#define HASHES \
7172
X(crc32, RHASH_CRC32, comma) \
73+
X(crc32c, RHASH_CRC32C, comma) \
7274
X(md4, RHASH_MD4, comma) \
7375
X(md5, RHASH_MD5, comma) \
7476
X(tiger, RHASH_TIGER, comma) \
@@ -91,10 +93,10 @@ bool sha512(const char *filename, const char *gold_hash) {
9193
X(sha3_256, RHASH_SHA3_256, comma) \
9294
X(sha3_384, RHASH_SHA3_384, comma) \
9395
X(sha3_512, RHASH_SHA3_512, comma) \
94-
X(crc32c, RHASH_CRC32C, comma) \
9596
X(snefru128, RHASH_SNEFRU128, comma) \
9697
X(snefru256, RHASH_SNEFRU256, blank)
97-
98+
#endif /* !HASHES */
99+
#ifndef X
98100
#define X(name, hash, unused) \
99101
bool name(const char *filename, const char *gold_hash) { \
100102
char gen_hash[130], digest[64]; \
@@ -103,6 +105,7 @@ bool sha512(const char *filename, const char *gold_hash) {
103105
: strcmp(gen_hash, gold_hash) == 0; \
104106
}
105107
HASHES
108+
#endif /* !X */
106109
#undef X
107110

108111
#ifdef __cplusplus

acquire/acquire_net_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ extern "C" {
1212

1313
#include "acquire_download.h"
1414
#include "acquire_string_extras.h"
15+
#include "acquire_common_defs.h"
1516

1617
bool LIBACQUIRE_LIB_EXPORT is_downloaded(const char *url,
1718
enum Checksum checksum,
1819
const char *hash,
1920
const char *target_location);
2021

2122
#ifdef LIBACQUIRE_IMPLEMENTATION
23+
24+
#ifndef DOWNLOAD_DIR_IMPL
25+
#define DOWNLOAD_DIR_IMPL
26+
const char *get_download_dir() { return ".downloads"; }
27+
#endif /* !DOWNLOAD_DIR_IMPL */
28+
2229
bool is_downloaded(const char *url, enum Checksum checksum, const char *hash,
2330
const char *target_location) {
2431
char full_local_fname[NAME_MAX + 1];

acquire/acquire_openbsd_ftp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ extern "C" {
1313

1414
#include "openbsd.ftp/extern.h"
1515

16+
#ifndef DOWNLOAD_DIR_IMPL
17+
#define DOWNLOAD_DIR_IMPL
1618
const char *get_download_dir() { return ".downloads"; }
19+
#endif /* !DOWNLOAD_DIR_IMPL */
1720

1821
int download(const char *url, enum Checksum checksum, const char *hash,
1922
const char target_location[NAME_MAX], bool follow, size_t retry,

acquire/acquire_string_extras.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212

1313
#include <stdarg.h>
1414
#include <stdio.h>
15+
#include <ctype.h>
1516
#ifdef HAVE_LIBBSD
1617
#include <bsd/string.h>
1718
#else
@@ -57,7 +58,7 @@ extern "C" {
5758

5859
#if defined(__APPLE__) && defined(__MACH__)
5960
#define HAVE_SNPRINTF_H
60-
#define HAVE_STRNCASECMP_H
61+
#define HAVE_STRNCASECMP
6162
#endif /* defined(__APPLE__) && defined(__MACH__) */
6263

6364
#if defined(BSD) && (BSD >= 199306) && !defined(__linux__) && \
@@ -89,7 +90,7 @@ typedef int errno_t;
8990

9091
#ifndef _MSC_VER
9192
#define HAVE_STRINGS_H
92-
#define HAVE_STRNCASECMP_H
93+
#define HAVE_STRNCASECMP
9394
#endif
9495

9596
#if defined(ANY_BSD) || defined(__APPLE__) && defined(__MACH__) || \
@@ -146,7 +147,7 @@ inline double wtf_vsnprintf(char *buffer, size_t count, const char *format,
146147

147148
#endif /* !defined(HAVE_SNPRINTF_H) && defined(LIBACQUIRE_IMPLEMENTATION) */
148149

149-
#ifndef HAVE_STRNCASECMP_H
150+
#ifndef HAVE_STRNCASECMP
150151

151152
extern LIBACQUIRE_LIB_EXPORT int strncasecmp(const char *, const char *,
152153
size_t);
@@ -155,13 +156,24 @@ extern LIBACQUIRE_LIB_EXPORT int strcasecmp(const char *, const char *);
155156

156157
#ifdef LIBACQUIRE_IMPLEMENTATION
157158

159+
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
158160
#define strncasecmp _strnicmp
159161

160162
#define strcasecmp _stricmp
163+
#else
164+
/* from MIT licensed musl @ e0ef93c20de1a9e0a6b8f4a4a951a8e61a1a2973 */
165+
int strncasecmp(const char *_l, const char *_r, size_t n)
166+
{
167+
const unsigned char *l=(void *)_l, *r=(void *)_r;
168+
if (!n--) return 0;
169+
for (; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--);
170+
return tolower(*l) - tolower(*r);
171+
}
172+
#endif /* defined(_MSC_VER) && !defined(__INTEL_COMPILER) */
161173

162174
#endif /* LIBACQUIRE_IMPLEMENTATION */
163175

164-
#endif /* !HAVE_STRNCASECMP_H */
176+
#endif /* !HAVE_STRNCASECMP */
165177

166178
#ifndef HAVE_STRNSTR
167179

acquire/acquire_wininet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ extern "C" {
3333

3434
#define BUFFER_SIZE 4096
3535

36+
#ifndef DOWNLOAD_DIR_IMPL
37+
#define DOWNLOAD_DIR_IMPL
3638
const char *get_download_dir() { return TMPDIR "//.downloads"; }
39+
#endif /* !DOWNLOAD_DIR_IMPL */
3740

3841
int download(const char *url, enum Checksum checksum, const char *hash,
3942
const char target_location[NAME_MAX], bool follow, size_t retry,

acquire/cli/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ source_group("${LIBRARY_NAME} Source Files" FILES "${Source_Files}")
1515
add_library("${LIBRARY_NAME}" "${Header_Files}" "${Source_Files}")
1616

1717
target_link_libraries("${LIBRARY_NAME}" PRIVATE "${PROJECT_NAME}_compiler_flags")
18+
#foreach (lib ${LIBACQUIRE_LIBRARIES})
19+
# message(STATUS "${LIBRARY_NAME} being linked with ${lib}")
20+
# target_link_libraries("${LIBRARY_NAME}" PUBLIC "${lib}")
21+
#endforeach ()
1822

1923
include(GNUInstallDirs)
2024

0 commit comments

Comments
 (0)