summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-12-17 17:13:35 -0500
committerTavian Barnes <tavianator@tavianator.com>2018-12-17 17:20:41 -0500
commit50b3caa2625b4377b03fe8ca6967f769cdd6ee95 (patch)
tree8e16032531188d7949c6b6785fae928c080e1a22 /Makefile
parent6b2494424fc8e6c49d6816294b5df5b1fe7f4c74 (diff)
downloadbfs-50b3caa2625b4377b03fe8ca6967f769cdd6ee95.tar.xz
Makefile: Link with -lrt on Linux
Fixes #29.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile16
1 files changed, 14 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 6863832..460337a 100644
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,10 @@ else
VERSION := $(shell git describe --always)
endif
+ifndef OS
+OS := $(shell uname)
+endif
+
CC ?= gcc
INSTALL ?= install
MKDIR ?= mkdir -p
@@ -44,15 +48,23 @@ LOCAL_CPPFLAGS := \
-DBFS_VERSION=\"$(VERSION)\"
LOCAL_CFLAGS := -std=c99
+LOCAL_LDFLAGS :=
+LOCAL_LDLIBS :=
+
+ifeq ($(OS),Linux)
+LOCAL_LDFLAGS += -Wl,--as-needed
+LOCAL_LDLIBS += -lrt
+endif
ALL_CPPFLAGS = $(LOCAL_CPPFLAGS) $(CPPFLAGS)
ALL_CFLAGS = $(ALL_CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) $(DEPFLAGS)
-ALL_LDFLAGS = $(ALL_CFLAGS) $(LDFLAGS)
+ALL_LDFLAGS = $(ALL_CFLAGS) $(LOCAL_LDFLAGS) $(LDFLAGS)
+ALL_LDLIBS = $(LOCAL_LDLIBS) $(LDLIBS)
all: bfs
bfs: bftw.o color.o dstring.o eval.o exec.o main.o mtab.o opt.o parse.o printf.o spawn.o stat.o typo.o util.o
- $(CC) $(ALL_LDFLAGS) $^ -o $@
+ $(CC) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@
sanitized: CFLAGS := -g $(WFLAGS) -fsanitize=address -fsanitize=undefined
sanitized: bfs