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 \
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-runscript zpm-soname zpm-syncfs zpm-packagehash zpm-verify \
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-setscript
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 -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|^|bin/|' \
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-runscript: zpm-runscript.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
139 zpm-foreach-path: zpm-foreach-path.o libzpm.a sqlite/sqlite3.h
140 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
142 zpm-findpkg: zpm-findpkg.o libzpm.a
143 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
145 zpm-syncfs: zpm-syncfs.o libzpm.a libelf.a
146 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf -lm
148 zpm-parse: zpm-parse.o lib/parse.o
149 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
151 zpm-quote: zpm-quote.o
152 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
155 echo "char createdb[] = {" > $@
159 sqlite/sqlite3.o: sqlite/sqlite3.c sqlite/config.h
160 $(CC) -Wall -std=c99 -Ilib -D_HAVE_SQLITE_CONFIG_H=1 -c -o $@ $<
162 sqlite/shell.o: sqlite/shell.c sqlite/config.h
163 $(CC) -Wall -std=c99 -Ilib \
164 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
165 -D_POSIX_C_SOURCE=200112L -c -o $@ $<
169 zpm-vercmp: zpm-vercmp.o lib/vercmp.o
170 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
172 zpm-shell: sqlite/sqlite3.o sqlite/shell.o
173 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
176 libelf.a: elf/libelf.o
180 test -d $(DESTDIR)/bin || install -d $(DESTDIR)/bin
181 install -D $(PROGRAMS) $(DESTDIR)/bin
183 scan-prep: clean sqlite/sqlite3.o sqlite/shell.o lib/liblzma.a
184 @echo scan-build -v -o report make -j10
187 rm -f *.o sqlite/*.o lib/*.o $(LZMAOBJ) liblzma.a \
188 libelf.a libzpm.a zpm-addfile soname \
190 local.db t/ctap/prove.o $(ZPKGBIN)