zcsf: fix makefiles
This commit is contained in:
parent
d326d530f2
commit
0ed3457799
3 changed files with 47 additions and 21 deletions
|
|
@ -1,37 +1,49 @@
|
||||||
|
## CONFIG ##
|
||||||
|
|
||||||
IDIR=include
|
IDIR=include
|
||||||
SRCDIR=src
|
SRCDIR=src
|
||||||
ODIR=obj
|
ODIR=obj
|
||||||
BINDIR=.
|
BINDIR=.
|
||||||
|
|
||||||
NAME = hello
|
# binary name, default name of dir
|
||||||
|
NAME = $(shell readlink -f . | xargs basename)
|
||||||
|
|
||||||
|
# global links
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
|
# compiler
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
# compiler flags
|
||||||
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c18
|
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c18
|
||||||
ifeq ($(DEBUG),true)
|
ifeq ($(DEBUG),true)
|
||||||
|
# debugging flags
|
||||||
CXXFLAGS += -g
|
CXXFLAGS += -g
|
||||||
else
|
else
|
||||||
|
# release flags
|
||||||
CXXFLAGS += -O2
|
CXXFLAGS += -O2
|
||||||
endif
|
endif
|
||||||
ifeq ($(STATIC),true)
|
ifeq ($(STATIC),true)
|
||||||
|
# static links
|
||||||
LDFLAGS +=
|
LDFLAGS +=
|
||||||
else
|
else
|
||||||
|
# dynamic links
|
||||||
LDFLAGS +=
|
LDFLAGS +=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
## END CONFIG ##
|
||||||
|
|
||||||
$(shell mkdir -p $(ODIR))
|
$(shell mkdir -p $(ODIR))
|
||||||
$(shell mkdir -p $(BINDIR))
|
$(shell mkdir -p $(BINDIR))
|
||||||
|
|
||||||
# automatically finds .h
|
# automatically finds .h
|
||||||
DEPS = $(shell find $(IDIR) -type f -regex '.*\.h')
|
DEPS = $(shell find $(IDIR) -type f -regex '.*\.h')
|
||||||
# automatically finds .c and makes the corresponding .o rule
|
# 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)
|
$(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS)
|
||||||
$(CC) $(CXXFLAGS) -c -o $@ $<
|
$(CC) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(BINDIR)/$(NAME): $(OBJ) $(DEPS)
|
$(BINDIR)/$(NAME): $(OBJ)
|
||||||
$(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
|
$(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
test: $(BINDIR)/$(NAME)
|
test: $(BINDIR)/$(NAME)
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,46 @@
|
||||||
|
## CONFIG ##
|
||||||
|
|
||||||
IDIR=include
|
IDIR=include
|
||||||
SRCDIR=src
|
SRCDIR=src
|
||||||
ODIR=obj
|
ODIR=obj
|
||||||
BINDIR=.
|
BINDIR=.
|
||||||
|
|
||||||
NAME = hello
|
# binary name, default name of dir
|
||||||
|
NAME = $(shell readlink -f . | xargs basename)
|
||||||
|
|
||||||
|
# global links
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
|
# compiler
|
||||||
CC=g++
|
CC=g++
|
||||||
|
# compiler flags
|
||||||
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17
|
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17
|
||||||
ifeq ($(DEBUG),true)
|
ifeq ($(DEBUG),true)
|
||||||
|
# debugging flags
|
||||||
CXXFLAGS += -g
|
CXXFLAGS += -g
|
||||||
else
|
else
|
||||||
|
# release flags
|
||||||
CXXFLAGS += -O2
|
CXXFLAGS += -O2
|
||||||
endif
|
endif
|
||||||
ifeq ($(STATIC),true)
|
ifeq ($(STATIC),true)
|
||||||
|
# static links
|
||||||
LDFLAGS +=
|
LDFLAGS +=
|
||||||
else
|
else
|
||||||
|
# dynamic links
|
||||||
LDFLAGS +=
|
LDFLAGS +=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
## END CONFIG ##
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(shell mkdir -p $(ODIR))
|
$(shell mkdir -p $(ODIR))
|
||||||
$(shell mkdir -p $(BINDIR))
|
$(shell mkdir -p $(BINDIR))
|
||||||
|
|
||||||
# automatically finds .h and .hpp
|
# automatically find .h and .hpp
|
||||||
DEPS = $(shell find $(IDIR) -type f -regex '.*\.hp?p?')
|
DEPS = $(shell find $(IDIR) -type f -regex '.*\.hp?p?')
|
||||||
# automatically finds .c and .cpp and makes the corresponding .o rule
|
# 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')
|
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)
|
$(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS)
|
||||||
$(CC) $(CXXFLAGS) -c -o $@ $<
|
$(CC) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
@ -34,7 +48,7 @@ $(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS)
|
||||||
$(ODIR)/%.o: $(SRCDIR)/%.cpp $(DEPS)
|
$(ODIR)/%.o: $(SRCDIR)/%.cpp $(DEPS)
|
||||||
$(CC) $(CXXFLAGS) -c -o $@ $<
|
$(CC) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(BINDIR)/$(NAME): $(OBJ) $(DEPS)
|
$(BINDIR)/$(NAME): $(OBJ)
|
||||||
$(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
|
$(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
test: $(BINDIR)/$(NAME)
|
test: $(BINDIR)/$(NAME)
|
||||||
|
|
|
||||||
22
zcsf/zcsf
22
zcsf/zcsf
|
|
@ -21,18 +21,18 @@ Operations:
|
||||||
Operation "src" can be abbrieviated to "s"'
|
Operation "src" can be abbrieviated to "s"'
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -n "$XDG_CONFIG_HOME" ]
|
if [ -n "$XDG_DATA_HOME" ]
|
||||||
then
|
then
|
||||||
local_configpath="$XDG_CONFIG_HOME/zcsf"
|
local_datapath="$XDG_DATA_HOME/zcsf"
|
||||||
else
|
else
|
||||||
local_configpath="$HOME/.config/zcsf"
|
local_datapath="$HOME/.local/share/zcsf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
usr_configpath="/usr/share/zcsf"
|
usr_datapath="/usr/share/zcsf"
|
||||||
|
|
||||||
if [ -n "$CONFIGPATH" ]
|
if [ -n "$CONFIGPATH" ]
|
||||||
then
|
then
|
||||||
local_configpath="$CONFIGPATH"
|
local_datapath="$CONFIGPATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
header_ifndef()
|
header_ifndef()
|
||||||
|
|
@ -162,20 +162,20 @@ dir_gen()
|
||||||
|
|
||||||
gen_make()
|
gen_make()
|
||||||
{
|
{
|
||||||
if [ -f "$local_configpath/Makefile$1" ] ; then
|
if [ -f "$local_datapath/Makefile$1" ] ; then
|
||||||
mpath="$local_configpath/Makefile$1"
|
mpath="$local_datapath/Makefile$1"
|
||||||
else
|
else
|
||||||
mpath="$usr_configpath/Makefile$1"
|
mpath="$usr_datapath/Makefile$1"
|
||||||
fi
|
fi
|
||||||
cp "$mpath" Makefile 2>/dev/null || touch Makefile
|
cp "$mpath" Makefile 2>/dev/null || touch Makefile
|
||||||
}
|
}
|
||||||
|
|
||||||
gen_main()
|
gen_main()
|
||||||
{
|
{
|
||||||
if [ -f "$local_configpath/main.c$1" ] ; then
|
if [ -f "$local_datapath/main.c$1" ] ; then
|
||||||
mpath="$local_configpath/main.c$1"
|
mpath="$local_datapath/main.c$1"
|
||||||
else
|
else
|
||||||
mpath="$usr_configpath/main.c$1"
|
mpath="$usr_datapath/main.c$1"
|
||||||
fi
|
fi
|
||||||
cp "$mpath" "$SRCDIR" 2>/dev/null || touch "$SRCDIR/main.c$1"
|
cp "$mpath" "$SRCDIR" 2>/dev/null || touch "$SRCDIR/main.c$1"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue