Ãzcsf: fix makefiles

This commit is contained in:
zawz 2021-06-08 16:38:25 +02:00
parent 98a7976c94
commit 07533554e6
3 changed files with 27 additions and 21 deletions

View file

@ -15,12 +15,14 @@ LDFLAGS =
CC=gcc CC=gcc
# compiler flags # compiler flags
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c18 CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c18
ifeq ($(DEBUG),true) ifeq ($(DEBUG),true)
# debugging flags # debugging flags
CXXFLAGS += -g CXXFLAGS += -g
RODIR = $(ODIR)/debug
else else
# release flags # release flags
CXXFLAGS += -O2 CXXFLAGS += -O2
RODIR = $(ODIR)/release
endif endif
ifeq ($(STATIC),true) ifeq ($(STATIC),true)
# static links # static links
@ -32,15 +34,17 @@ endif
## END CONFIG ## ## END CONFIG ##
$(shell mkdir -p $(ODIR)) $(shell mkdir -p $(RODIR))
$(shell mkdir -p $(BINDIR)) $(shell mkdir -p $(BINDIR))
# automatically finds .h # automatically find .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 find .c and make 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)/|$(RODIR)/|g')
$(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS) build: $(BINDIR)/$(NAME)
$(RODIR)/%.o: $(SRCDIR)/%.c $(DEPS)
$(CC) $(CXXFLAGS) -c -o $@ $< $(CC) $(CXXFLAGS) -c -o $@ $<
$(BINDIR)/$(NAME): $(OBJ) $(BINDIR)/$(NAME): $(OBJ)
@ -50,7 +54,7 @@ test: $(BINDIR)/$(NAME)
$(BINDIR)/$(NAME) $(BINDIR)/$(NAME)
clean: clean:
rm $(ODIR)/*.o rm $(ODIR)/*/*.o
clear: clear:
rm $(BINDIR)/$(NAME) rm $(BINDIR)/$(NAME)

View file

@ -14,15 +14,17 @@ LDFLAGS =
# compiler # compiler
CC=g++ CC=g++
# compiler flags # compiler flags
CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++17 CXXFLAGS= -I$(IDIR) -Wall -pedantic -std=c++20
ifeq ($(DEBUG),true) ifeq ($(DEBUG),true)
# debugging flags # debugging flags
CXXFLAGS += -g CXXFLAGS += -g
RODIR = $(ODIR)/debug
else else
# release flags # release flags
CXXFLAGS += -O2 CXXFLAGS += -O2
RODIR = $(ODIR)/release
endif endif
ifeq ($(STATIC),true) ifeq ($(STATIC),true)
# static links # static links
LDFLAGS += LDFLAGS +=
else else
@ -32,20 +34,20 @@ endif
## END CONFIG ## ## END CONFIG ##
$(shell mkdir -p $(RODIR))
$(shell mkdir -p $(ODIR))
$(shell mkdir -p $(BINDIR)) $(shell mkdir -p $(BINDIR))
# automatically find .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 find .c and .cpp and make 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)/|$(RODIR)/|g')
$(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS) build: $(BINDIR)/$(NAME)
$(RODIR)/%.o: $(SRCDIR)/%.c $(DEPS)
$(CC) $(CXXFLAGS) -c -o $@ $< $(CC) $(CXXFLAGS) -c -o $@ $<
$(ODIR)/%.o: $(SRCDIR)/%.cpp $(DEPS) $(RODIR)/%.o: $(SRCDIR)/%.cpp $(DEPS)
$(CC) $(CXXFLAGS) -c -o $@ $< $(CC) $(CXXFLAGS) -c -o $@ $<
$(BINDIR)/$(NAME): $(OBJ) $(BINDIR)/$(NAME): $(OBJ)
@ -55,7 +57,7 @@ test: $(BINDIR)/$(NAME)
$(BINDIR)/$(NAME) $(BINDIR)/$(NAME)
clean: clean:
rm $(ODIR)/*.o rm $(ODIR)/*/*.o
clear: clear:
rm $(BINDIR)/$(NAME) rm $(BINDIR)/$(NAME)

View file

@ -246,19 +246,19 @@ Types:
clear) clear)
make clean >/dev/null 2>&1 ; make clear >/dev/null 2>&1 make clean >/dev/null 2>&1 ; make clear >/dev/null 2>&1
# bin # bin
[ "$BINDIR" != "." ] && rm -rd "$BINDIR" 2> /dev/null [ "$BINDIR" != "." ] && rm -r "$BINDIR" 2> /dev/null
# src # src
if [ "$SRCDIR" != "." ] if [ "$SRCDIR" != "." ]
then rm -rd "$SRCDIR" 2> /dev/null then rm -r "$SRCDIR" 2> /dev/null
else rm ./*.c ./*.cpp 2> /dev/null else rm ./*.c ./*.cpp 2> /dev/null
fi fi
# include # include
if [ "$IDIR" != "." ] if [ "$IDIR" != "." ]
then rm -rd "$IDIR" 2> /dev/null then rm -r "$IDIR" 2> /dev/null
else rm ./*.h ./*.hpp 2> /dev/null else rm ./*.h ./*.hpp 2> /dev/null
fi fi
# obj # obj
[ "$ODIR" != "." ] && rm -rd "$ODIR" 2> /dev/null [ "$ODIR" != "." ] && rm -r "$ODIR" 2> /dev/null
;; ;;
src|s) src|s)