lnsocket

A minimal C library for connecting to the lightning network
git clone git://jb55.com/lnsocket
Log | Files | Refs | Submodules | README | LICENSE

Makefile (6424B)


      1 
      2 CFLAGS=-Wall -Os -Ideps/secp256k1/include -Ideps/libsodium/src/libsodium/include -Ideps
      3 LDFLAGS=
      4 
      5 SUBMODULES=deps/secp256k1
      6 
      7 # Build for the simulator
      8 XCODEDIR=$(shell xcode-select -p)
      9 SIM_SDK=$(XCODEDIR)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
     10 IOS_SDK=$(XCODEDIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
     11 
     12 HEADERS=config.h deps/secp256k1/include/secp256k1.h deps/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h
     13 ARS=libsecp256k1.a libsodium.a lnsocket.a
     14 WASM_ARS=target/js/libsecp256k1.a target/js/libsodium.a target/js/lnsocket.a
     15 OBJS=sha256.o hkdf.o hmac.o sha512.o lnsocket.o error.o handshake.o crypto.o bigsize.o commando.o bech32.o
     16 ARM64_OBJS=$(OBJS:.o=-arm64.o)
     17 X86_64_OBJS=$(OBJS:.o=-x86_64.o)
     18 WASM_OBJS=$(OBJS:.o=-wasm.o) lnsocket_wasm-wasm.o
     19 BINS=ctest lnrpc
     20 
     21 DEPS=$(OBJS) $(ARS) $(HEADERS)
     22 
     23 all: $(BINS) $(ARS)
     24 
     25 ios: target/ios/lnsocket.a target/ios/libsodium.a target/ios/libsecp256k1.a
     26 
     27 js: target/js/lnsocket.js target/js/lnsocket.wasm
     28 	@mkdir -p dist/js
     29 	cp target/js/lnsocket.wasm target/js/lnsocket.js dist/js
     30 
     31 node: target/node/lnsocket.js target/node/lnsocket.wasm
     32 	@mkdir -p dist/node
     33 	cp target/node/lnsocket.wasm target/node/lnsocket.js dist/node
     34 
     35 liblnsocket.a: lnsocket.a
     36 	cp lnsocket.a liblnsocket.a
     37 
     38 rust: liblnsocket.a
     39 	cargo build --release
     40 
     41 target/node/lnsocket.js: target/tmp/node/lnsocket.js lnsocket_lib.js
     42 	@mkdir -p target/node
     43 	cat $^ > $@
     44 
     45 target/js/lnsocket.js: target/tmp/js/lnsocket.js lnsocket_lib.js
     46 	@mkdir -p target/js
     47 	cat $^ > $@
     48 
     49 libsodium-1.0.18-stable.tar.gz:
     50 	curl -O https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz
     51 
     52 deps/libsodium/configure: libsodium-1.0.18-stable.tar.gz
     53 	tar xvf $^; \
     54 	mkdir -p deps; \
     55 	mv libsodium-stable deps/libsodium
     56 
     57 deps/secp256k1/.git:
     58 	@tools/refresh-submodules.sh $(SUBMODULES)
     59 
     60 lnsocket.a: $(OBJS)
     61 	ar rcs $@ $(OBJS)
     62 
     63 target/arm64/lnsocket.a: $(ARM64_OBJS)
     64 	@mkdir -p target/arm64
     65 	ar rcs $@ $^
     66 
     67 target/x86_64/lnsocket.a: $(X86_64_OBJS)
     68 	@mkdir -p target/x86_64
     69 	ar rcs $@ $^
     70 
     71 target/js/lnsocket.a: $(WASM_OBJS)
     72 	@mkdir -p target/js
     73 	emar rcs $@ $^
     74 
     75 target/ios/lnsocket.a: target/x86_64/lnsocket.a target/arm64/lnsocket.a
     76 	@mkdir -p target/ios
     77 	lipo -create $^ -output $@
     78 
     79 %-arm64.o: %.c $(HEADERS)
     80 	@echo "cc $@"
     81 	@$(CC) $(CFLAGS) -c $< -o $@ -arch arm64 -isysroot $(IOS_SDK) -target arm64-apple-ios -fembed-bitcode
     82 
     83 %-wasm.o: %.c $(HEADERS)
     84 	@echo "emcc $@"
     85 	@emcc $(CFLAGS) -c $< -o $@
     86 
     87 %-x86_64.o: %.c $(HEADERS)
     88 	@echo "cc $@"
     89 	@$(CC) $(CFLAGS) -c $< -o $@ -arch x86_64 -isysroot $(SIM_SDK) -mios-simulator-version-min=6.0.0 -target x86_64-apple-ios-simulator
     90 
     91 # TODO cross compiled config??
     92 config.h: configurator
     93 	./configurator > $@
     94 
     95 configurator: configurator.c
     96 	$(CC) $< -o $@
     97 
     98 %.o: %.c $(HEADERS)
     99 	@echo "cc $@"
    100 	@$(CC) $(CFLAGS) -c $< -o $@
    101 
    102 deps/secp256k1/include/secp256k1.h: deps/secp256k1/.git
    103 
    104 deps/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h: deps/libsodium/configure
    105 
    106 deps/secp256k1/config.log: deps/secp256k1/configure
    107 	cd deps/secp256k1; \
    108 	./configure --disable-shared --enable-module-ecdh --enable-module-extrakeys --enable-module-schnorrsig
    109 
    110 deps/libsodium/config.status: deps/libsodium/configure
    111 	cd deps/libsodium; \
    112 	./configure --disable-shared --enable-minimal
    113 
    114 deps/secp256k1/configure: deps/secp256k1/.git
    115 	cd deps/secp256k1; \
    116 	patch -p1 < ../../tools/0001-configure-customizable-AR-and-RANLIB.patch; \
    117 	./autogen.sh
    118 
    119 deps/libsodium/config.log: deps/libsodium/configure
    120 	cd deps/libsodium; \
    121 	./configure
    122 
    123 deps/secp256k1/.libs/libsecp256k1.a: deps/secp256k1/config.log
    124 	cd deps/secp256k1; \
    125 	make -j libsecp256k1.la
    126 
    127 libsecp256k1.a: deps/secp256k1/.libs/libsecp256k1.a
    128 	cp $< $@
    129 
    130 libsodium.a: deps/libsodium/src/libsodium/.libs/libsodium.a
    131 	cp $< $@
    132 
    133 target/ios/libsodium.a: deps/libsodium/libsodium-ios/lib/libsodium.a
    134 	@mkdir -p target/ios
    135 	cp $< $@
    136 
    137 target/ios/libsecp256k1.a: deps/secp256k1/libsecp256k1-ios/lib/libsecp256k1.a
    138 	@mkdir -p target/ios
    139 	cp $< $@
    140 
    141 target/js/libsecp256k1.a: deps/secp256k1/libsecp256k1-wasm/lib/libsecp256k1.a
    142 	@mkdir -p target/js
    143 	cp $< $@
    144 
    145 target/js/libsodium.a: deps/libsodium/libsodium-js/lib/libsodium.a
    146 	@mkdir -p target/js
    147 	cp $< $@
    148 
    149 deps/libsodium/libsodium-ios/lib/libsodium.a: deps/libsodium/configure
    150 	cd deps/libsodium; \
    151 	./dist-build/ios.sh
    152 
    153 deps/secp256k1/libsecp256k1-ios/lib/libsecp256k1.a: deps/secp256k1/configure
    154 	./tools/secp-ios.sh
    155 
    156 deps/secp256k1/libsecp256k1-wasm/lib/libsecp256k1.a: deps/secp256k1/configure
    157 	./tools/secp-wasm.sh
    158 
    159 deps/libsodium/libsodium-js/lib/libsodium.a: deps/libsodium/configure
    160 	cd deps/libsodium; \
    161 	./dist-build/emscripten.sh --standard
    162 
    163 deps/libsodium/src/libsodium/.libs/libsodium.a: deps/libsodium/config.log
    164 	cd deps/libsodium/src/libsodium; \
    165 	make -j libsodium.la
    166 
    167 install: $(DEPS)
    168 	mkdir -p $(PREFIX)/lib $(PREFIX)/include
    169 	cp lnsocket.h $(PREFIX)/include
    170 	cp lnsocket.a libsecp256k1.a libsodium.a $(PREFIX)/lib
    171 
    172 install-js: js
    173 	mkdir -p $(PREFIX)/share/lnsocket
    174 	cp target/js/lnsocket.wasm target/js/lnsocket.js $(PREFIX)/share/lnsocket
    175 
    176 install-all: install install-js
    177 
    178 check: ctest
    179 	./ctest
    180 	npm test
    181 
    182 gocheck:
    183 	go test ./lnsocket.go
    184 
    185 ctest: test.o $(DEPS)
    186 	@echo "ld $@"
    187 	@$(CC) $(CFLAGS) test.o $(OBJS) $(ARS) $(LDFLAGS) -o $@
    188 
    189 lnrpc: lnrpc.o $(DEPS)
    190 	@echo "ld $@"
    191 	@$(CC) $(CFLAGS) lnrpc.o $(OBJS) $(ARS) $(LDFLAGS) -o $@
    192 
    193 target/js/lnsocket.wasm: target/tmp/js/lnsocket.js
    194 	cp target/tmp/js/lnsocket.wasm target/js/lnsocket.wasm
    195 
    196 target/node/lnsocket.wasm: target/tmp/node/lnsocket.js
    197 	cp target/tmp/node/lnsocket.wasm target/node/lnsocket.wasm
    198 
    199 target/tmp/node/lnsocket.js: $(WASM_ARS) lnsocket_pre.js
    200 	@mkdir -p target/tmp/node
    201 	emcc --pre-js lnsocket_pre.js -s MODULARIZE -flto -s 'EXPORTED_FUNCTIONS=["_malloc", "_free"]' -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap"]' $(CFLAGS) -Wl,-whole-archive $(WASM_ARS) -Wl,-no-whole-archive -o $@
    202 
    203 target/tmp/js/lnsocket.js: $(WASM_ARS) lnsocket_pre.js
    204 	@mkdir -p target/tmp/js
    205 	emcc --pre-js lnsocket_pre.js -s ENVIRONMENT=web -s MODULARIZE -flto -s 'EXPORTED_FUNCTIONS=["_malloc", "_free"]' -s 'EXPORTED_RUNTIME_METHODS=["ccall","cwrap"]' $(CFLAGS) -Wl,-whole-archive $(WASM_ARS) -Wl,-no-whole-archive -o $@
    206 
    207 tags: fake
    208 	find . -name '*.c' -or -name '*.h' | xargs ctags
    209 
    210 clean: fake
    211 	rm -rf $(BINS) config.h $(OBJS) $(ARM64_OBJS) $(X86_64_OBJS) $(WASM_OBJS) target
    212 
    213 distclean: clean
    214 	rm -rf $(ARS) liblnsocket.a deps target
    215 
    216 
    217 .PHONY: fake