aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: d02cb43b9dc7451ac740d2d49298ae9d0a030f40 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
CC              ?=cc
CFLAGS          ?=-O2 -g

prefix          ?=/usr/local
exec_prefix     ?=$(prefix)
bindir          ?=$(exec_prefix)/bin
includedir      ?=$(exec_prefix)/include
libdir          ?=$(exec_prefix)/lib
datarootdir     ?=$(prefix)/share
datadir         ?=$(datarootdir)
docdir          ?=$(datarootdir)/doc/musl-compat-$(VERSION)
mandir          ?=$(datarootdir)/man

BINS            := $(notdir $(basename $(wildcard bin/*.c)))
BINS_SH         := $(notdir $(basename $(basename $(wildcard bin/*.sh.in))))
INCLUDES        := $(shell find include/ -type f -name '*.h')
INCLUDES        := $(INCLUDES:include/%=%)
LIBS            := $(notdir $(wildcard lib/*.a))

VERSION         =2

build:	$(foreach b,$(BINS),bin/$(b).o) $(foreach b,$(BINS_SH),bin/$(b).sh)

bin/%.sh: bin/%.sh.in
	cp $< $@
	chmod +x "$@"

bin/%.o: bin/%.c
	$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@

$(DESTDIR)$(bindir)/%: bin/$(notdir %)
	install -D -m 755 $< $(basename $@)

$(DESTDIR)$(includedir)/%: include/$(notdir %)
	install -D -m 644 $< $@

$(DESTDIR)$(libdir)/%: lib/$(notdir %)
	install -D -m 755 $< $@

install: build $(foreach b,$(BINS),$(DESTDIR)$(bindir)/$(b).o) $(foreach b,$(BINS_SH),$(DESTDIR)$(bindir)/$(b).sh) $(foreach i,$(INCLUDES),$(DESTDIR)$(includedir)/$(i)) $(foreach l,$(LIBS),$(DESTDIR)$(libdir)/$(l))

clean:
	rm -rf $(foreach b,$(BINS),bin/$(b).o) $(foreach b,$(BINS_SH),bin/$(b).sh)

.PHONY:	all build clean install