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 zpm-repo zpm-update zpm-confgit
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 doc/zpm.8
77 $(ZPM) newpackage -C zpm-$(ZPMVER)-1
78 $(ZPM) add -v -u root -g root -f $@ -P /sbin zpm-$(ZPMVER)-1 $(sort $(PROGRAMS))
79 $(ZPM) add -v -u root -g root -f $@ -P /usr/share/man/man8 -S doc doc/zpm.8
81 tarball: zpm-$(ZPMVER)-1.tar.xz
83 zpm-$(ZPMVER)-1.tar.xz: programs
85 tar -cJf $@ --transform='s|^|sbin/|' \
92 gcc -std=c99 -Wall -c -o $@ $<
95 PATH=$(curdir)/t:$(curdir):$(PATH) t/$(T).t
97 t/ctap/prove: t/ctap/prove.o
98 $(CC) $(CFLAGS) -o $@ $+
100 test: $(ZPKGBIN) t/ctap/prove
101 @PATH=$(curdir)/t:$(curdir):$(PATH) t/ctap/prove t/*.t
105 uncompress: uncompress.o
106 $(CC) $(CFLAGS) -o $@ $+ -llzma
108 zpm-elftype: elf/elftype.c
109 $(CC) -Ielf $(CFLAGS) -o $@ $+
111 zpm-soname: elf/soname.c
112 $(CC) -Ielf $(CFLAGS) -o $@ $+
114 zpm-soneed: elf/needed.c
115 $(CC) -Ielf $(CFLAGS) -o $@ $+
117 zpm-addfile: zpm-addfile.o libzpm.a libelf.a
118 $(CC) -Ielf $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
120 zpm-hash: zpm-hash.o libzpm.a
121 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
123 zpm-verify: zpm-verify.o t/ctap/ctap.o libzpm.a
124 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< t/ctap/ctap.o -lzpm -lelf
126 zpm-init: zpm-init.o libzpm.a
127 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
129 zpm-extract: zpm-extract.o libzpm.a
130 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
132 zpm-script: zpm-script.o libzpm.a
133 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
135 zpm-packagehash: zpm-packagehash.o libzpm.a
136 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
138 zpm-foreach-path.o: CFLAGS+=-Wno-unused-parameter
139 zpm-script.o: CFLAGS+=-Wno-unused-parameter
141 zpm-foreach-path: zpm-foreach-path.o libzpm.a sqlite/sqlite3.h
142 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
144 zpm-findpkg: zpm-findpkg.o libzpm.a
145 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
147 zpm-search: zpm-search.o libzpm.a
148 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
150 zpm-note: zpm-note.o libzpm.a
151 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
153 zpm-syncfs: zpm-syncfs.o libzpm.a libelf.a
154 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf -lm
156 zpm-parse: zpm-parse.o lib/parse.o
157 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
159 zpm-quote: zpm-quote.o
160 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
163 echo "char createdb[] = {" > $@
167 sqlite/sqlite3.o: sqlite/sqlite3.c sqlite/config.h
168 $(CC) -O3 -Wall -std=c99 -Ilib -D_HAVE_SQLITE_CONFIG_H=1 -c -o $@ $<
170 sqlite/extensions.o: sqlite/extensions.c
171 $(CC) -O3 -Wall -std=c99 -I. -DSQLITE_CORE=1 -c -o $@ $<
173 sqlite/shell.o: sqlite/shell.c sqlite/config.h Makefile
174 $(CC) -Wall -std=c99 -Ilib \
175 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
176 '-DSQLITE_SHELL_INIT_PROC(x)=zpm_setup_extensions(x)' \
177 -D_POSIX_C_SOURCE=200112L -c -o $@ $<
181 zpm-vercmp: zpm-vercmp.o lib/vercmp.o
182 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
184 zpm-shell: sqlite/sqlite3.o sqlite/shell.o sqlite/extensions.o lib/vercmp.o
185 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
187 libelf.a: elf/libelf.o
190 install: $(COMPILED) doc/zpm.8
191 test -d $(DESTDIR)/sbin || install -d $(DESTDIR)/sbin
192 install $(PROGRAMS) $(DESTDIR)/sbin
193 mkdir -p $(DESTDIR)/usr/share/man/man8
194 install -m644 doc/zpm.8 $(DESTDIR)/usr/share/man/man8
196 scan-prep: clean sqlite/sqlite3.o sqlite/shell.o lib/liblzma.a
197 @echo scan-build -v -o report make -j10
200 rm -f *.o sqlite/*.o lib/*.o $(LZMAOBJ) liblzma.a \
201 libelf.a libzpm.a zpm-addfile soname \
203 local.db t/ctap/prove.o $(ZPKGBIN)