Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial packaging #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
*.kate-swp
.deps
Makefile
Makefile.in
aclocal.m4
ar-lib
autom4te.cache
compile
config.*
configure
depcomp
install-sh
libbreadwallet-core.pc
libtool
ltmain.sh
missing
.libs

# Object files
*.o
*.ko
Expand Down Expand Up @@ -35,4 +53,4 @@
*.xcworkspace
*.xcodeproj

.idea/
.idea/
18 changes: 12 additions & 6 deletions BRInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,18 @@ union _u256 { uint8_t u8[256/8]; };
#define set_u32le(r, x) (*(union _u32 *)(r) =\
(union _u32) { (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, ((x) >> 24) & 0xff })

#define set_u64be(r, x) (*(union _u64 *)(r) =\
(union _u64) { ((x) >> 56) & 0xff, ((x) >> 48) & 0xff, ((x) >> 40) & 0xff, ((x) >> 32) & 0xff,\
((x) >> 24) & 0xff, ((x) >> 16) & 0xff, ((x) >> 8) & 0xff, (x) & 0xff })
#define set_u64le(r, x) (*(union _u64 *)(r) =\
(union _u64) { (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, ((x) >> 24) & 0xff,\
((x) >> 32) & 0xff, ((x) >> 40) & 0xff, ((x) >> 48) & 0xff, ((x) >> 56) & 0xff })
static inline void set_u64be(void * const r, const uint64_t x) {
*(union _u64 *)r = (union _u64) {
((x) >> 56) & 0xff, ((x) >> 48) & 0xff, ((x) >> 40) & 0xff, ((x) >> 32) & 0xff,
((x) >> 24) & 0xff, ((x) >> 16) & 0xff, ((x) >> 8) & 0xff, (x) & 0xff
};
}
static inline void set_u64le(void * const r, const uint64_t x) {
*(union _u64 *)r = (union _u64) {
(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, ((x) >> 24) & 0xff,
((x) >> 32) & 0xff, ((x) >> 40) & 0xff, ((x) >> 48) & 0xff, ((x) >> 56) & 0xff
};
}

#define set_u128(r, x) (*(union _u128 *)(r) =\
(union _u128) { (x).u8[0], (x).u8[1], (x).u8[2], (x).u8[3], (x).u8[4], (x).u8[5], (x).u8[6], (x).u8[7],\
Expand Down
4 changes: 2 additions & 2 deletions BRKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wconditional-uninitialized"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#include "secp256k1/src/basic-config.h"
#include "secp256k1/src/secp256k1.c"
#include <secp256k1.h>
#include <secp256k1_recovery.h>
#pragma clang diagnostic pop
#pragma GCC diagnostic pop

Expand Down
2 changes: 2 additions & 0 deletions BRKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef BRKey_h
#define BRKey_h

#include <stddef.h>

#include "BRInt.h"

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions BRWallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <limits.h>
#include <float.h>
#include <pthread.h>
#include <assert.H>
#include <assert.h>

struct BRWalletStruct {
uint64_t balance, totalSent, totalReceived, feePerKb, *balanceHist;
Expand Down Expand Up @@ -1159,7 +1159,7 @@ void BRWalletFree(BRWallet *wallet)
// price is local currency units per bitcoin
int64_t BRLocalAmount(int64_t amount, double price)
{
int64_t localAmount = llabs(amount)*(price/SATOSHIS);
int64_t localAmount = llabs(amount)*price/SATOSHIS;

// if amount is not 0, but is too small to be represented in local currency, return minimum non-zero localAmount
if (localAmount == 0 && amount != 0) localAmount = 1;
Expand Down
54 changes: 54 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2014-2016 Luke Dashjr
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the standard MIT license. See COPYING for more details.

lib_LTLIBRARIES = libbreadwallet-core.la
libbreadwallet_core_la_SOURCES = \
BRAddress.c \
BRBIP32Sequence.c \
BRBIP38Key.c \
BRBIP39Mnemonic.c \
BRBase58.c \
BRBloomFilter.c \
BRCrypto.c \
BRKey.c \
BRMerkleBlock.c \
BRPaymentProtocol.c \
BRPeer.c \
BRPeerManager.c \
BRSet.c \
BRTransaction.c \
BRWallet.c

libbreadwallet_core_la_CFLAGS = $(libsecp256k1_CFLAGS) $(PTHREAD_CFLAGS)
libbreadwallet_core_la_LDFLAGS = -version-info $(LIBBREADWALLET_CORE_SO_VERSION) -no-undefined
libbreadwallet_core_la_LIBADD = $(libsecp256k1_LIBS) $(PTHREAD_LIBS)

libbreadwallet_core_includedir = $(includedir)/breadwallet-core
libbreadwallet_core_include_HEADERS = \
BRAddress.h \
BRArray.h \
BRBIP32Sequence.h \
BRBIP38Key.h \
BRBIP39Mnemonic.h \
BRBIP39WordsEn.h \
BRBase58.h \
BRBloomFilter.h \
BRCrypto.h \
BRInt.h \
BRKey.h \
BRList.h \
BRMerkleBlock.h \
BRPaymentProtocol.h \
BRPeer.h \
BRPeerManager.h \
BRSet.h \
BRTransaction.h \
BRWallet.h

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libbreadwallet-core.pc

dist_noinst_SCRIPTS = autogen.sh
dist_doc_DATA = LICENSE README.md
11 changes: 11 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh -e
# Written by Luke Dashjr in 2012
# This program is released under the terms of the Creative Commons "CC0 1.0 Universal" license and/or copyright waiver.

if test -z "$srcdir"; then
srcdir=`dirname "$0"`
if test -z "$srcdir"; then
srcdir=.
fi
fi
autoreconf --force --install --verbose "$srcdir"
70 changes: 70 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
dnl * Copyright 2012-2016 Luke Dashjr
dnl *
dnl * This program is free software; you can redistribute it and/or modify it
dnl * under the terms of the standard MIT license. See COPYING for more details.

AC_INIT(
[libbreadwallet-core],
[0.1.0],
[https://github.com/breadwallet/breadwallet-core/issues],
[libbreadwallet-core])
AC_CONFIG_AUX_DIR([.])
AC_PREREQ([2.59])
AM_INIT_AUTOMAKE([1.11 -Wall dist-xz foreign])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

AC_PROG_CC_C99
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT([disable-static])

# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
AC_SUBST([LIBBREADWALLET_CORE_SO_VERSION], [0:0:0])

AC_CONFIG_FILES([Makefile
libbreadwallet-core.pc:libbreadwallet-core.pc.in
])

m4_define([BFG_PTHREAD_FLAG_CHECK],
AC_MSG_CHECKING([for $1])
save_CFLAGS="${CFLAGS}"
save_LIBS="${LIBS}"
found_pthread=false
for cflag in ' -pthread' ''; do
for lib in ' -lpthread' ' -lwinpthread' ''; do
CFLAGS="${save_CFLAGS}${cflag}"
LIBS="${save_LIBS}${lib}"
AC_LINK_IFELSE([
AC_LANG_PROGRAM([
#include <pthread.h>
], [
void *f = $1;
])
], [
found_pthread=true
PTHREAD_FLAGS="${cflag}"
PTHREAD_LIBS="${lib}"
if test "x${cflag}${lib}" = "x"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([with${cflag}${lib}])
fi
$2
break 2
])
done
done
CFLAGS="${save_CFLAGS}"
LIBS="${save_LIBS}"
if test "x${found_pthread}" = "xfalse"; then
AC_MSG_RESULT([no])
fi
AC_SUBST([PTHREAD_FLAGS])
AC_SUBST([PTHREAD_LIBS])
)
BFG_PTHREAD_FLAG_CHECK([pthread_create])

AC_SEARCH_LIBS([log],[m])

PKG_CHECK_MODULES([libsecp256k1],[libsecp256k1])

AC_OUTPUT
12 changes: 12 additions & 0 deletions libbreadwallet-core.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: @PACKAGE_NAME@
Description: Library for Bitcoin's base58 encoding.
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lbase58
Cflags: -I${includedir}/breadwallet-core
Requires.private: libsecp256k1
Libs.private: @LIBS@ @PTHREAD_LIBS@
2 changes: 1 addition & 1 deletion test.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "BRAddress.h"
#include "BRBase58.h"
#include "BRBIP39Mnemonic.h"
#include "BRBIP39WordsEn.H"
#include "BRBIP39WordsEn.h"
#include "BRPeer.h"
#include "BRPeerManager.h"
#include "BRPaymentProtocol.h"
Expand Down