re-arrange Makefile, and cleanup Emacs/ccls part

This commit is contained in:
2024-01-06 18:24:17 +01:00
parent 2c95124020
commit 3c7222954e

View File

@@ -42,12 +42,6 @@ TEST := $(wildcard $(TESTDIR)/*.c)
TEST_FN := $(notdir $(TEST)) TEST_FN := $(notdir $(TEST))
BIN := $(addprefix $(BINDIR)/,$(TEST_FN:.c=)) BIN := $(addprefix $(BINDIR)/,$(TEST_FN:.c=))
##################################### emacs projectile/ccls dirs & files
PRJROOT := .projectile
EMACSLSP := .dir-locals.el
CCLSROOT := .ccls-root
CCLSFILE := .ccls
CCLSCMDS := compile_commands.json CCLSCMDS := compile_commands.json
##################################### pre-processor flags ##################################### pre-processor flags
@@ -84,25 +78,31 @@ LIBS := -l$(LIB)
DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d
##################################### General targets ##################################### General targets
.PHONY: all compile test clean cleanall cleanallall ccls bear .PHONY: all libs compile test emacs ccls bear clean cleanall cleanallall
# default: build libraries
all: libs all: libs
compile: objs # default: build libraries
libs: $(DLIB) $(SLIB)
test: tests # build objects
compile: $(OBJ)
clean: cleandep cleanobj cleanlib cleanbin # build test binaries
test: $(BIN)
cleanall: clean cleandepdir cleanobjdir cleanlibdir cleanbindir
cleanallall: cleanall cleanemacs
# setup emacs projectile/ccls # setup emacs projectile/ccls
emacs: emacs-setup emacs: $(PRJROOT) $(EMACSLSP)
# update compile-commands.json # update compile-commands.json
ccls bear: $(CCLSCMDS) ccls bear: $(CCLSCMDS)
# cleanup - need to think about a better system :-)
clean: cleandep cleanobj cleanlib cleanbin
cleanall: clean cleandepdir cleanobjdir cleanlibdir cleanbindir
cleanallall: cleanall cleanemacs
##################################### cleaning functions ##################################### cleaning functions
# rmfiles - deletes a list of files in a directory if they exist. # rmfiles - deletes a list of files in a directory if they exist.
# $(1): the directory # $(1): the directory
@@ -170,9 +170,7 @@ cleandepdir:
@#[ -d $(DEPDIR) ] && echo cleaning depend files && $(RM) -f $(DEP) || true @#[ -d $(DEPDIR) ] && echo cleaning depend files && $(RM) -f $(DEP) || true
##################################### objects ##################################### objects
.PHONY: objs cleanobj cleanobjdir .PHONY: cleanobj cleanobjdir
objs: $(OBJ)
cleanobj: cleanobj:
$(call rmfiles,$(OBJ),brlib object) $(call rmfiles,$(OBJ),brlib object)
@@ -185,9 +183,7 @@ $(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR) $(DEPDIR)
$(CC) -c $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@ $(CC) -c $(DEPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@
##################################### brlib libraries ##################################### brlib libraries
.PHONY: libs cleanlib cleanlibdir .PHONY: cleanlib cleanlibdir
libs: $(DLIB) $(SLIB)
cleanlib: cleanlib:
$(call rmfiles,$(DLIB) $(SLIB),library) $(call rmfiles,$(DLIB) $(SLIB),library)
@@ -205,13 +201,11 @@ $(SLIB): $(OBJ) | $(LIBDIR)
@echo "building static library ($@)." @echo "building static library ($@)."
@$(AR) $(ARFLAGS) $@ $? > /dev/null @$(AR) $(ARFLAGS) $@ $? > /dev/null
##################################### tests ##################################### testing
.PHONY: tests cleanbin cleanbindir .PHONY: cleanbin cleanbindir
tests: $(BIN)
cleanbin: cleanbin:
$(call rmfiles,$(TARGET),binary) $(call rmfiles,$(BIN),binary)
cleanbindir: cleanbindir:
$(call rmdir,$(BINDIR),binaries) $(call rmdir,$(BINDIR),binaries)
@@ -228,32 +222,22 @@ $(BINDIR)/%: $(TESTDIR)/%.c libs | $(BINDIR)
@echo generating $@ @echo generating $@
@$(CC) -S -fverbose-asm $(CPPFLAGS) $(CFLAGS) $< -o $@ @$(CC) -S -fverbose-asm $(CPPFLAGS) $(CFLAGS) $< -o $@
##################################### Emacs ##################################### Emacs & LSP (ccls)
.PHONY: emacs-setup cleanemacs .PHONY: cleanemacs cleanccls
emacs-setup: $(PRJROOT) $(EMACSLSP) #EMACSLSP := .dir-locals.el
CCLSFILES := .projectile .ccls .ccls-root
CCLSCACHE := .ccls-cache
cleanemacs: cleanemacs:
$(call rmfiles, $(PRJROOT) $(EMACSLSP), Emacs); $(call rmfiles, $(PRJROOT) $(EMACSLSP), Emacs/ccls);
$(PRJROOT) $(EMACSLSP): $(CCLSFILES):
@if [[ $(@) = $(PRJROOT) ]] ; \ printf "creating Emacs dot-files.\n"
then \
echo "creating Emacs's projectile root file." ; \
else \
echo "creating Emacs's ccls root file." ; \
fi
@$(TOUCH) $@ @$(TOUCH) $@
##################################### LSP (ccls)
.PHONY: cleanccls
cleanccls: cleanccls:
$(call rmfiles, $(CCLSROOT), ccls); $(call rmfiles, $(CCLSFILES), ccls);
$(CCLSROOT):
echo "creating ccls root file."
@$(TOUCH) $@
# generate compile_commands.json. # generate compile_commands.json.
# TODO: add includes and Makefile dependencies. # TODO: add includes and Makefile dependencies.
@@ -262,11 +246,7 @@ $(CCLSROOT):
# maybe run cleanobj cleanlibobj in commands ? # maybe run cleanobj cleanlibobj in commands ?
$(CCLSCMDS): cleanobj $(SRC) | $(CCLSROOT) $(CCLSCMDS): cleanobj $(SRC) | $(CCLSROOT)
@echo "Generating ccls compile commands file ($@)." @echo "Generating ccls compile commands file ($@)."
@$(BEAR) -- make compile @$(BEAR) -- make test
#.PHONY: bear
#bear: cleanobj cleanlibobj Makefile | $(CCLSROOT)
# @$(BEAR) -- make compile
##################################### valgrind (mem check) ##################################### valgrind (mem check)
.PHONY: memcheck .PHONY: memcheck