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.c findpkg.c quote.c dbquery.c script_hash.c \
23 parse.c integ.c seterror.c notes.c
25 LIBZPMOBJ=$(addprefix lib/, $(LIBZPMSRC:%.c=%.o))
29 ZPKGBIN=zpm-addfile zpm-extract zpm-init zpm-vercmp zpm-stat zpm-hash \
30 zpm-findpkg zpm-shell zpm-soneed zpm-foreach-path zpm-parse \
31 zpm-script zpm-soname zpm-syncfs zpm-packagehash zpm-verify \
32 zpm-elftype zpm-quote zpm-note zpm-search
34 SCRIPTS=zpm zpm-install zpm-merge zpm-list zpm-preserve zpm-test zpm-log \
35 zpm-contents zpm-uninstall zpm-pathmod zpm-rmpackage zpm-newpackage \
36 zpm-pkg zpm-add zpm-pkgfile zpm-gc
38 PROGRAMS=$(SCRIPTS) $(COMPILED)
44 printf '%s\n' $(LZMAOBJ)
47 libzpm.a: $(LIBZPMOBJ) sqlite/sqlite3.o \
52 package: zpm-$(ZPMVER)-1.zpm
55 find xz/src/liblzma -type d -name .deps -prune \
56 -o -type f -printf '%P\n' \
57 | xargs -IZ echo Z Z Z \
58 | xargs printf 'test -e lzma/%s && cp xz/src/liblzma/%s lzma/%s\n' \
61 #lzma/lz/lz_decoder.o: lzma/lz/lz_decoder.c
62 #lzma/lz/lz_encoder.o: lzma/lz/lz_encoder.c
65 $(CC) $(CFLAGS) $(LZMAFLAGS) -c -o $@ $<
67 lib/liblzma.a: $(LZMAOBJ)
70 lib/libjsw.a: $(JSWOBJ)
75 zpm-$(ZPMVER)-1.zpm: programs
77 $(ZPM) newpackage -C zpm-$(ZPMVER)-1
78 $(ZPM) add -v -u root -g root -f $@ -P /sbin zpm-$(ZPMVER)-1 $(sort $(PROGRAMS))
80 tarball: zpm-$(ZPMVER)-1.tar.xz
82 zpm-$(ZPMVER)-1.tar.xz: programs
84 tar -cJf $@ --transform='s|^|sbin/|' \
91 gcc -std=c99 -Wall -c -o $@ $<
94 PATH=$(curdir)/t:$(curdir):$(PATH) t/$(T).t
96 t/ctap/prove: t/ctap/prove.o
97 $(CC) $(CFLAGS) -o $@ $+
99 test: $(ZPKGBIN) t/ctap/prove
100 @PATH=$(curdir)/t:$(curdir):$(PATH) t/ctap/prove t/*.t
104 uncompress: uncompress.o
105 $(CC) $(CFLAGS) -o $@ $+ -llzma
107 zpm-elftype: elf/elftype.c
108 $(CC) -Ielf $(CFLAGS) -o $@ $+
110 zpm-soname: elf/soname.c
111 $(CC) -Ielf $(CFLAGS) -o $@ $+
113 zpm-soneed: elf/needed.c
114 $(CC) -Ielf $(CFLAGS) -o $@ $+
116 zpm-addfile: zpm-addfile.o libzpm.a libelf.a
117 $(CC) -Ielf $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
119 zpm-hash: zpm-hash.o libzpm.a
120 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
122 zpm-verify: zpm-verify.o t/ctap/ctap.o libzpm.a
123 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< t/ctap/ctap.o -lzpm -lelf
125 zpm-init: zpm-init.o libzpm.a
126 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
128 zpm-extract: zpm-extract.o libzpm.a
129 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
131 zpm-script: zpm-script.o libzpm.a
132 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
134 zpm-packagehash: zpm-packagehash.o libzpm.a
135 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
137 zpm-foreach-path.o: CFLAGS+=-Wno-unused-parameter
138 zpm-script.o: CFLAGS+=-Wno-unused-parameter
140 zpm-foreach-path: zpm-foreach-path.o libzpm.a sqlite/sqlite3.h
141 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
143 zpm-findpkg: zpm-findpkg.o libzpm.a
144 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
146 zpm-search: zpm-search.o libzpm.a
147 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
149 zpm-note: zpm-note.o libzpm.a
150 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
152 zpm-syncfs: zpm-syncfs.o libzpm.a libelf.a
153 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf -lm
155 zpm-parse: zpm-parse.o lib/parse.o
156 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
158 zpm-quote: zpm-quote.o
159 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
162 echo "char createdb[] = {" > $@
166 sqlite/sqlite3.o: sqlite/sqlite3.c sqlite/config.h
167 $(CC) -O3 -Wall -std=c99 -Ilib -D_HAVE_SQLITE_CONFIG_H=1 -c -o $@ $<
169 sqlite/extensions.o: sqlite/extensions.c
170 $(CC) -O3 -Wall -std=c99 -I. -DSQLITE_CORE=1 -c -o $@ $<
172 sqlite/shell.o: sqlite/shell.c sqlite/config.h Makefile
173 $(CC) -Wall -std=c99 -Ilib \
174 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
175 '-DSQLITE_SHELL_INIT_PROC(x)=zpm_setup_extensions(x)' \
176 -D_POSIX_C_SOURCE=200112L -c -o $@ $<
180 zpm-vercmp: zpm-vercmp.o lib/vercmp.o
181 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
183 zpm-shell: sqlite/sqlite3.o sqlite/shell.o sqlite/extensions.o lib/vercmp.o
184 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
186 libelf.a: elf/libelf.o
190 test -d $(DESTDIR)/sbin || install -d $(DESTDIR)/sbin
191 install $(PROGRAMS) $(DESTDIR)/sbin
193 scan-prep: clean sqlite/sqlite3.o sqlite/shell.o lib/liblzma.a
194 @echo scan-build -v -o report make -j10
197 rm -f *.o sqlite/*.o lib/*.o $(LZMAOBJ) liblzma.a \
198 libelf.a libzpm.a zpm-addfile soname \
200 local.db t/ctap/prove.o $(ZPKGBIN)