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
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
22
zcsf/zcsf
22
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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue