2 #CC=/usr/musl/bin/musl-gcc
3 CFLAGS=-Wall -W -Wextra -Werror -Wno-implicit-fallthrough -std=c99 -Ilib -Isqlite -Ielf -I. -Ilzma/api
5 ZPMVER:=$(shell git describe --tags --match 'v[0-9]*' | sed -e 's/^v//' | sed -e 's/-g.\+//' | sed -e 's/-/./g')
7 LZMAFLAGS=-Ilzma/api -Ilzma/tuklib -Ilzma/lzma -Ilzma/common -Ilzma/check -Ilzma/lz -Ilzma/rangecoder -Ilzma/simple -Ilzma/delta -DHAVE_CHECK_CRC64 -DHAVE_CHECK_CRC32 -DHAVE_ENCODER_LZMA2 -DHAVE_DECODER_LZMA2 -DHAVE_MF_BT4
11 LZMACHECKSRC=lzma/check/check.c lzma/check/crc32_fast.c lzma/check/crc64_fast.c lzma/check/crc32_table.c lzma/check/crc64_table.c
12 LZMASRC=$(shell ls lzma/lzma/*.c lzma/common/*.c lzma/lz/*.c) $(LZMACHECKSRC) lzma/rangecoder/price_table.c
13 LZMAOBJ=$(filter-out lzma/common/stream_encoder_mt.o, $(LZMASRC:%.c=%.o))
15 JSWSRC=lib/jsw/jsw_avltree.c \
20 JSWOBJ=$(JSWSRC:%.c=%.o)
21 LIBZPMSRC=sha256.c db.c compress.c uncompress.c zpm.c zpm_hash.c \
22 foreach_path.c vercmp.o findpkg.c quote.c dbquery.c script_hash.c
24 LIBZPMOBJ=$(addprefix lib/, $(LIBZPMSRC:%.c=%.o))
28 ZPKGBIN=zpm-addfile zpm-extract zpm-init zpm-vercmp zpm-stat zpm-hash \
29 zpm-findpkg zpm-shell zpm-soneed zpm-foreach-path zpm-parse \
30 zpm-runscript zpm-soname zpm-syncfs
32 SCRIPTS=zpm zpm-install zpm-merge zpm-list zpm-preserve zpm-test zpm-log \
33 zpm-contents zpm-uninstall
35 PROGRAMS=$(SCRIPTS) $(COMPILED)
41 printf '%s\n' $(LZMAOBJ)
44 libzpm.a: $(LIBZPMOBJ) sqlite/sqlite3.o \
49 package: zpm-$(ZPMVER)-1.zpm
52 find xz/src/liblzma -type d -name .deps -prune \
53 -o -type f -printf '%P\n' \
54 | xargs -IZ echo Z Z Z \
55 | xargs printf 'test -e lzma/%s && cp xz/src/liblzma/%s lzma/%s\n' \
58 #lzma/lz/lz_decoder.o: lzma/lz/lz_decoder.c
59 #lzma/lz/lz_encoder.o: lzma/lz/lz_encoder.c
62 $(CC) $(CFLAGS) $(LZMAFLAGS) -c -o $@ $<
64 lib/liblzma.a: $(LZMAOBJ)
67 lib/libjsw.a: $(JSWOBJ)
72 zpm-$(ZPMVER)-1.zpm: programs
74 $(ZPM) newpackage -C zpm-$(ZPMVER)-1
75 $(ZPM) add -u root -g root -f $@ -P /sbin zpm-$(ZPMVER)-1 $(sort $(PROGRAMS))
77 tarball: zpm-$(ZPMVER)-1.tar.xz
79 zpm-$(ZPMVER)-1.tar.xz: programs
81 tar -cJf $@ --transform='s|^|bin/|' \
88 gcc -std=c99 -Wall -c -o $@ $<
91 PATH=$(curdir)/t:$(curdir):$(PATH) t/$(T).t
93 t/ctap/prove: t/ctap/prove.o
94 $(CC) $(CFLAGS) -o $@ $+
96 test: $(ZPKGBIN) t/ctap/prove
97 @PATH=$(curdir)/t:$(curdir):$(PATH) t/ctap/prove t/*.t
101 uncompress: uncompress.o
102 $(CC) $(CFLAGS) -o $@ $+ -llzma
104 elftype: elf/elftype.c
105 $(CC) $(CFLAGS) -o $@ $+
107 zpm-soname: elf/soname.c
108 $(CC) -Ielf $(CFLAGS) -o $@ $+
110 zpm-soneed: elf/needed.c
111 $(CC) -Ielf $(CFLAGS) -o $@ $+
113 zpm-addfile: zpm-addfile.o libzpm.a libelf.a
114 $(CC) -Ielf $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
116 zpm-hash: zpm-hash.o libzpm.a
117 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
119 zpm-init: zpm-init.o libzpm.a
120 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
122 zpm-extract: zpm-extract.o libzpm.a
123 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
125 zpm-runscript: zpm-runscript.o libzpm.a
126 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
128 zpm-foreach-path.o: CFLAGS+=-Wno-unused-parameter
130 zpm-foreach-path: zpm-foreach-path.o libzpm.a sqlite/sqlite3.h
131 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
133 zpm-findpkg: zpm-findpkg.o libzpm.a
134 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
136 zpm-syncfs: zpm-syncfs.o libzpm.a libelf.a
137 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf -lm -ldl
139 zpm-parse: zpm-parse.o libzpm.a
140 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
142 zpm-quote: zpm-quote.o
143 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
146 echo "char createdb[] = {" > $@
150 sqlite/sqlite3.o: sqlite/sqlite3.c sqlite/config.h
151 $(CC) -Wall -std=c99 -Ilib -D_HAVE_SQLITE_CONFIG_H=1 -c -o $@ $<
153 sqlite/shell.o: sqlite/shell.c sqlite/config.h
154 $(CC) -Wall -std=c99 -Ilib \
155 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
156 -D_POSIX_C_SOURCE=200112L -c -o $@ $<
160 zpm-vercmp: zpm-vercmp.o lib/vercmp.o
161 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
163 zpm-shell: sqlite/sqlite3.o sqlite/shell.o
164 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
167 libelf.a: elf/libelf.o
171 test -d $(DESTDIR)/bin || install -d $(DESTDIR)/bin
172 install -D $(PROGRAMS) $(DESTDIR)/bin
175 rm -f *.o sqlite/*.o lib/*.o $(LZMAOBJ) liblzma.a \
176 libelf.a libzpm.a zpm-addfile soname \
178 local.db t/ctap/prove.o