From 0ed34577992f394b6928cf28d437ad1187c6a6f1 Mon Sep 17 00:00:00 2001 From: zawz Date: Fri, 23 Oct 2020 09:57:26 +0200 Subject: [PATCH] zcsf: fix makefiles --- zcsf/Makefile | 18 +++++++++++++++--- zcsf/Makefile_cpp | 28 +++++++++++++++++++++------- zcsf/zcsf | 22 +++++++++++----------- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/zcsf/Makefile b/zcsf/Makefile index 1e80964..a4deed0 100644 --- a/zcsf/Makefile +++ b/zcsf/Makefile @@ -1,37 +1,49 @@ +## CONFIG ## + IDIR=include SRCDIR=src ODIR=obj BINDIR=. -NAME = hello +# binary name, default name of dir +NAME = $(shell readlink -f . | xargs basename) +# global links LDFLAGS = +# compiler CC=gcc +# compiler flags CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c18 ifeq ($(DEBUG),true) + # debugging flags CXXFLAGS += -g else + # release flags CXXFLAGS += -O2 endif ifeq ($(STATIC),true) + # static links LDFLAGS += else + # dynamic links LDFLAGS += endif +## END CONFIG ## + $(shell mkdir -p $(ODIR)) $(shell mkdir -p $(BINDIR)) # automatically finds .h DEPS = $(shell find $(IDIR) -type f -regex '.*\.h') # automatically finds .c and makes the corresponding .o rule -OBJ = $(shell find $(SRCDIR) -type f -regex '.*\.c' | sed 's|\.c|.o|g;s|$(SRCDIR)/|$(ODIR)/|g') +OBJ = $(shell find $(SRCDIR) -type f -regex '.*\.c' | sed 's|\.c|.o|g;s|^$(SRCDIR)/|$(ODIR)/|g') $(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS) $(CC) $(CXXFLAGS) -c -o $@ $< -$(BINDIR)/$(NAME): $(OBJ) $(DEPS) +$(BINDIR)/$(NAME): $(OBJ) $(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) test: $(BINDIR)/$(NAME) diff --git a/zcsf/Makefile_cpp b/zcsf/Makefile_cpp index 3efd628..1355f06 100644 --- a/zcsf/Makefile_cpp +++ b/zcsf/Makefile_cpp @@ -1,32 +1,46 @@ +## CONFIG ## + IDIR=include SRCDIR=src ODIR=obj BINDIR=. -NAME = hello +# binary name, default name of dir +NAME = $(shell readlink -f . | xargs basename) +# global links LDFLAGS = +# compiler CC=g++ +# compiler flags CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17 -ifeq ($(DEBUG),true) +ifeq ($(DEBUG),true) + # debugging flags CXXFLAGS += -g else + # release flags CXXFLAGS += -O2 endif -ifeq ($(STATIC),true) +ifeq ($(STATIC),true) + # static links LDFLAGS += else + # dynamic links LDFLAGS += endif +## END CONFIG ## + + + $(shell mkdir -p $(ODIR)) $(shell mkdir -p $(BINDIR)) -# automatically finds .h and .hpp +# automatically find .h and .hpp DEPS = $(shell find $(IDIR) -type f -regex '.*\.hp?p?') -# automatically finds .c and .cpp and makes the corresponding .o rule -OBJ = $(shell find $(SRCDIR) -type f -regex '.*\.cp?p?' | sed 's|\.cpp|.o|g;s|\.c|.o|g;s|$(SRCDIR)/|$(ODIR)/|g') +# automatically find .c and .cpp and make the corresponding .o rule +OBJ = $(shell find $(SRCDIR) -type f -regex '.*\.cp?p?' | sed 's|\.cpp|.o|g;s|\.c|.o|g;s|^$(SRCDIR)/|$(ODIR)/|g') $(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS) $(CC) $(CXXFLAGS) -c -o $@ $< @@ -34,7 +48,7 @@ $(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS) $(ODIR)/%.o: $(SRCDIR)/%.cpp $(DEPS) $(CC) $(CXXFLAGS) -c -o $@ $< -$(BINDIR)/$(NAME): $(OBJ) $(DEPS) +$(BINDIR)/$(NAME): $(OBJ) $(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) test: $(BINDIR)/$(NAME) diff --git a/zcsf/zcsf b/zcsf/zcsf index 8b9fb54..adffdea 100755 --- a/zcsf/zcsf +++ b/zcsf/zcsf @@ -21,18 +21,18 @@ Operations: Operation "src" can be abbrieviated to "s"' } -if [ -n "$XDG_CONFIG_HOME" ] +if [ -n "$XDG_DATA_HOME" ] then - local_configpath="$XDG_CONFIG_HOME/zcsf" + local_datapath="$XDG_DATA_HOME/zcsf" else - local_configpath="$HOME/.config/zcsf" + local_datapath="$HOME/.local/share/zcsf" fi -usr_configpath="/usr/share/zcsf" +usr_datapath="/usr/share/zcsf" if [ -n "$CONFIGPATH" ] then - local_configpath="$CONFIGPATH" + local_datapath="$CONFIGPATH" fi header_ifndef() @@ -162,20 +162,20 @@ dir_gen() gen_make() { - if [ -f "$local_configpath/Makefile$1" ] ; then - mpath="$local_configpath/Makefile$1" + if [ -f "$local_datapath/Makefile$1" ] ; then + mpath="$local_datapath/Makefile$1" else - mpath="$usr_configpath/Makefile$1" + mpath="$usr_datapath/Makefile$1" fi cp "$mpath" Makefile 2>/dev/null || touch Makefile } gen_main() { - if [ -f "$local_configpath/main.c$1" ] ; then - mpath="$local_configpath/main.c$1" + if [ -f "$local_datapath/main.c$1" ] ; then + mpath="$local_datapath/main.c$1" else - mpath="$usr_configpath/main.c$1" + mpath="$usr_datapath/main.c$1" fi cp "$mpath" "$SRCDIR" 2>/dev/null || touch "$SRCDIR/main.c$1" }