aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKylie McClain <somasis@exherbo.org>2016-05-18 23:26:31 -0400
committerKylie McClain <somasis@exherbo.org>2016-05-18 23:31:11 -0400
commit6597c12d4e43765b10edd67e9177d2b10948d5d0 (patch)
treedd05a26ed8405dc3bee4235ad5045d0b1c760609
parent4e7a02dff8fdbea40f890a08905585f0ef4fe4a5 (diff)
downloadmusl-compat-6597c12d4e43765b10edd67e9177d2b10948d5d0.tar.gz
musl-compat-6597c12d4e43765b10edd67e9177d2b10948d5d0.tar.xz
musl-compat-6597c12d4e43765b10edd67e9177d2b10948d5d0.zip
Allow out of source build, look in ./include/ when compiling binaries
-rw-r--r--Makefile38
1 files changed, 20 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index a598b6a..94b41e3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+topdir :=$(dir $(realpath $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))))
+
CC ?=cc
CFLAGS ?=-O2 -g
@@ -11,35 +13,35 @@ 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))
+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/%=%)
+LIBS := $(notdir $(wildcard $(topdir)/lib/*.a))
VERSION =4
-build: $(foreach b,$(BINS),bin/$(b).o) $(foreach b,$(BINS_SH),bin/$(b).sh)
+build: $(foreach b,$(BINS),$(topdir)/bin/$(b).o) $(foreach b,$(BINS_SH),$(topdir)/bin/$(b).sh)
-bin/%.sh: bin/%.sh.in
- cp $< $@
+$(topdir)/bin/%.sh: $(topdir)/bin/%.sh.in
+ cp "$<" "$@"
chmod +x "$@"
-bin/%.o: bin/%.c
- $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
+$(topdir)/bin/%.o: $(topdir)/bin/%.c
+ $(CC) -I"$(topdir)/include" $(CFLAGS) $(LDFLAGS) "$<" -o "$@"
-$(DESTDIR)$(bindir)/%: bin/$(notdir %)
- install -D -m 755 $< $(basename $@)
+$(DESTDIR)$(bindir)/%: $(topdir)/bin/$(notdir %)
+ install -D -m 755 "$<" "$(basename $@)"
-$(DESTDIR)$(includedir)/%: include/$(notdir %)
- install -D -m 644 $< $@
+$(DESTDIR)$(includedir)/%: $(topdir)/include/$(notdir %)
+ install -D -m 644 "$<" "$@"
-$(DESTDIR)$(libdir)/%: lib/$(notdir %)
- install -D -m 755 $< $@
+$(DESTDIR)$(libdir)/%: $(topdir)/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))
+install: $(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)
+ rm -rf $(foreach b,$(BINS),$(topdir)/bin/$(b).o) $(foreach b,$(BINS_SH),$(topdir)/bin/$(b).sh)
.PHONY: all build clean install