-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
42 lines (30 loc) · 1.45 KB
/
Makefile
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
topdir :=$(dir $(realpath $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))))
CC ?=cc
CFLAGS ?=-O2 -g
prefix ?=/usr/local
exec_prefix ?=$(prefix)
bindir ?=$(exec_prefix)/bin
includedir ?=$(exec_prefix)/include
datarootdir ?=$(prefix)/share
datadir ?=$(datarootdir)
docdir ?=$(datarootdir)/doc/musl-compat-$(VERSION)
mandir ?=$(datarootdir)/man
BINS := $(notdir $(basename $(wildcard $(topdir)/bin/*.c)))
BINS_SH := $(notdir $(basename $(basename $(wildcard $(topdir)/bin/*.sh.in))))
INCLUDES := $(shell find "$(topdir)/include" -type f -name '*.h')
INCLUDES := $(INCLUDES:$(topdir)/include/%=%)
VERSION =5
build: $(foreach b,$(BINS),$(topdir)/bin/$(b).o) $(foreach b,$(BINS_SH),$(topdir)/bin/$(b).sh)
$(topdir)/bin/%.sh: $(topdir)/bin/%.sh.in
cp "$<" "$@"
chmod +x "$@"
$(topdir)/bin/%.o: $(topdir)/bin/%.c
$(CC) -I"$(topdir)/include" $(CFLAGS) $(LDFLAGS) "$<" -o "$@"
$(DESTDIR)$(bindir)/%: $(topdir)/bin/$(notdir %)
install -D -m 755 "$<" "$(basename $@)"
$(DESTDIR)$(includedir)/%: $(topdir)/include/$(notdir %)
install -D -m 644 "$<" "$@"
install: $(foreach b,$(BINS),$(DESTDIR)$(bindir)/$(b).o) $(foreach b,$(BINS_SH),$(DESTDIR)$(bindir)/$(b).sh) $(foreach i,$(INCLUDES),$(DESTDIR)$(includedir)/$(i))
clean:
rm -rf $(foreach b,$(BINS),$(topdir)/bin/$(b).o) $(foreach b,$(BINS_SH),$(topdir)/bin/$(b).sh)
.PHONY: all build clean install