From 50b3caa2625b4377b03fe8ca6967f769cdd6ee95 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 17 Dec 2018 17:13:35 -0500 Subject: Makefile: Link with -lrt on Linux Fixes #29. --- Makefile | 16 ++++++++++++++-- 1 file 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 -- cgit v1.2.3