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