]> Sergey Matveev's repositories - nnn.git/commitdiff
do build configuration with variables instead of targets
authorJan Chren (rindeal) <dev.rindeal@gmail.com>
Tue, 8 Oct 2019 14:24:40 +0000 (16:24 +0200)
committerJan Chren (rindeal) <dev.rindeal@gmail.com>
Wed, 9 Oct 2019 15:05:56 +0000 (17:05 +0200)
Makefile
README.md

index 89355df6c38d8f2c29e341b7b1caf802c47e837f..9b96345713dd91699736d14ff18994974f978c59 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,38 @@ CP ?= cp
 
 CFLAGS_OPTIMIZATION ?= -O3
 
+O_DEBUG := 0
+O_NORL := 0  # no readline support
+O_NOLOC := 0  # no locale support
+
+# convert targets to flags for backwards compatibility
+ifeq ($(MAKECMDGOALS),debug)
+       O_DEBUG := 1
+endif
+ifeq ($(MAKECMDGOALS),norl)
+       O_NORL := 1
+endif
+ifeq ($(MAKECMDGOALS),noloc)
+       O_NORL := 1
+       O_NOLOC := 1
+endif
+
+ifeq ($(O_DEBUG),1)
+       CPPFLAGS += -DDBGMODE
+       CFLAGS += -g
+       LDLIBS += -lrt
+endif
+
+ifeq ($(O_NORL),1)
+       CPPFLAGS += -DNORL
+else
+       LDLIBS += -lreadline
+endif
+
+ifeq ($(O_NOLOC),1)
+       CPPFLAGS += -DNOLOCALE
+endif
+
 ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
        CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw)
        LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs   ncursesw)
@@ -34,16 +66,12 @@ all: $(BIN)
 $(SRC): src/nnn.h
 
 $(BIN): $(SRC)
-       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS) -lreadline
-
-debug: $(SRC)
-       $(CC) -DDBGMODE -g $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $(BIN) $^ $(LDLIBS) -lreadline -lrt
-
-norl: $(SRC)
-       $(CC) -DNORL $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $(BIN) $^ $(LDLIBS)
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-noloc: $(SRC)
-       $(CC) -DNORL -DNOLOCALE $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $(BIN) $^ $(LDLIBS)
+# targets for backwards compatibility
+debug: $(BIN)
+norl: $(BIN)
+noloc: $(BIN)
 
 install: all
        $(INSTALL) -m 0755 -d $(DESTDIR)$(PREFIX)/bin
index 9fa39fd1c75562955c18a5adc08fef657537ae36..5dbd644afe5e1e680bbd90d12fc7a4bdbf5c019e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -81,7 +81,7 @@ Notes:
 
 #### Library dependencies
 
-A curses library with wide char support (e.g. ncursesw), libreadline (`make norl` to drop) and standard libc.
+A curses library with wide char support (e.g. ncursesw), libreadline (`make O_NORL=1` to drop) and standard libc.
 
 #### Utility dependencies