Makefile (3983B)
1 CC?=clang 2 3 FIND=$(shell which gfind find | head -1) 4 5 UNAME_S:=$(shell uname -s) 6 UNAME_M:=$(shell uname -m) 7 8 SRC:= 9 INCLUDES:= 10 CFLAGS:= 11 LDFLAGS:= 12 DESTDIR?=/usr/local 13 14 ifeq ($(UNAME_S),Darwin) 15 OBJCOPY:=$(shell echo "echo 'Not using objcopy'") 16 LD:=$(shell which ld) 17 LICENSE_OBJ:=license.c 18 LDFLAGS+=-lobjc 19 else 20 OBJCOPY?=objcopy 21 OBJCOPY:=$(shell which objcopy) 22 LICENSE_OBJ:=license.o 23 endif 24 25 ARCH_TARGET?=$(shell echo $(UNAME_M) | sed -e 's/x86_64/elf64-x86-64/' -e 's/arm64/elf64-littleaarch64/' -e 's/aarch64/elf64-littleaarch64/') 26 ARCH_BIN?=$(shell echo $(UNAME_M) | sed -e 's/x86_64/i386/' -e 's/arm64/aarch64/' -e 's/aarch64/aarch64/') 27 28 SRC+=$(shell $(FIND) src/ -type f -name '*.c') 29 INCLUDES+=-Isrc 30 INCLUDES+=-Ilib/.dep/include 31 32 LIBS:= 33 34 LIBS+=lib/cofyc/argparse 35 SRC+=lib/cofyc/argparse/argparse.c 36 37 LIBS+=lib/cozis/tinytemplate 38 SRC+=lib/cozis/tinytemplate/src/tinytemplate.c 39 40 LIBS+=lib/emmanuel-marty/em_inflate 41 SRC+=lib/emmanuel-marty/em_inflate/lib/em_inflate.c 42 43 LIBS+=lib/erkkah/naett 44 SRC+=lib/erkkah/naett/naett.c 45 LDFLAGS+=-lcurl -lpthread 46 47 LIBS+=lib/rxi/microtar 48 SRC+=lib/rxi/microtar/src/microtar.c 49 50 LIBS+=lib/tidwall/json.c 51 SRC+=lib/tidwall/json.c/json.c 52 53 OBJ:=$(SRC:.c=.o) 54 OBJ:=$(OBJ:.cc=.o) 55 OBJ+=$(LICENSE_OBJ) 56 57 CFLAGS+=${INCLUDES} 58 59 .PHONY: default 60 default: dep 61 62 license.o: LICENSE.md 63 $(OBJCOPY) --input binary --output $(ARCH_TARGET) --binary-architecture $(ARCH_BIN) $< $@ 64 65 license.c: LICENSE.md 66 (echo "static const unsigned char _license_md_data[] = {"; xxd -i < LICENSE.md; echo "};") > license.c 67 (echo "static const unsigned char * const _license_md_end = _license_md_data + sizeof(_license_md_data);" >> license.c) 68 (echo "const unsigned char * const _binary_LICENSE_md_start = _license_md_data;" >> license.c) 69 (echo "const unsigned char * const _binary_LICENSE_md_end = _license_md_end;" >> license.c) 70 71 lib/cofyc/argparse: 72 mkdir -p lib/cofyc/argparse 73 curl -sL https://github.com/cofyc/argparse/archive/refs/heads/master.tar.gz | tar xzv --strip-components=1 -C lib/cofyc/argparse 74 mkdir -p lib/.dep/include/cofyc 75 ln -s ../../../cofyc/argparse/argparse.h lib/.dep/include/cofyc/argparse.h 76 77 lib/cozis/tinytemplate: 78 mkdir -p lib/cozis/tinytemplate 79 curl -sL https://github.com/cozis/tinytemplate/archive/refs/heads/main.tar.gz | tar xzv --strip-components=1 -C lib/cozis/tinytemplate 80 mkdir -p lib/.dep/include/cozis 81 ln -s ../../../cozis/tinytemplate/src/tinytemplate.h lib/.dep/include/cozis/tinytemplate.h 82 83 lib/emmanuel-marty/em_inflate: 84 mkdir -p lib/emmanuel-marty/em_inflate 85 curl -sL https://github.com/emmanuel-marty/em_inflate/archive/refs/heads/master.tar.gz | tar xzv --strip-components=1 -C lib/emmanuel-marty/em_inflate 86 mkdir -p lib/.dep/include/emmanuel-marty 87 ln -s ../../../emmanuel-marty/em_inflate/lib/em_inflate.h lib/.dep/include/emmanuel-marty/em_inflate.h 88 89 lib/erkkah/naett: 90 mkdir -p lib/erkkah/naett 91 curl -sL https://github.com/erkkah/naett/archive/refs/heads/main.tar.gz | tar xzv --strip-components=1 -C lib/erkkah/naett 92 mkdir -p lib/.dep/include/erkkah 93 ln -s ../../../erkkah/naett/naett.h lib/.dep/include/erkkah/naett.h 94 95 lib/rxi/microtar: 96 mkdir -p lib/rxi/microtar 97 curl -sL https://github.com/rxi/microtar/archive/refs/heads/master.tar.gz | tar xzv --strip-components=1 -C lib/rxi/microtar 98 mkdir -p lib/.dep/include/rxi 99 ln -s ../../../rxi/microtar/src/microtar.h lib/.dep/include/rxi/microtar.h 100 101 lib/tidwall/json.c: 102 mkdir -p lib/tidwall/json.c 103 curl -sL https://github.com/tidwall/json.c/archive/refs/heads/main.tar.gz | tar xzv --strip-components=1 -C lib/tidwall/json.c 104 mkdir -p lib/.dep/include/tidwall 105 ln -s ../../../tidwall/json.c/json.h lib/.dep/include/tidwall/json.h 106 107 .c.o: 108 ${CC} $< ${CFLAGS} -c -o $@ 109 110 dep: $(LIBS) $(OBJ) 111 ${CC} ${OBJ} ${CFLAGS} ${LDFLAGS} -o dep 112 strip -u -r dep 2>/dev/null || true 113 114 .PHONY: install 115 install: dep 116 install dep ${DESTDIR}/bin 117 118 .PHONY: clean 119 clean: 120 rm -f $(OBJ) 121 122 .PHONY: format 123 format: 124 $(FIND) src/ -type f \( -name '*.c' -o -name '*.h' \) -exec clang-format -i {} +