Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaffolding/build system for throwaway projects [closed]

This is semi superuser question, but I think it'd fit SO better.

I'm working in the shell for the most of the time, so an IDE doesn't fit my workflow. Yet I prefer a neatly packed project over a trashy throwaway. I find myself spending WAY too much time writing makefiles (even cmakelists take too much imho, and sometimes feel unintuitive).

Now I've written a note to myself what would an ideal quick build/scaffold system work like, and I'll come around to writing something of the like, unless there is one already. I'd rather put some effort into it that starting my own.

The note:

Ideally a build system would have the ability to quicky scaffold a project.

build <project-name> <language>

This would simply make a makefile (or something else handy) with a target with specified name. It'd prepare it so it outputs an executable named project-name.

This would regulate source files to be compiled:

add source <source-file>

This would regulate any necessary libraries to be linked:

add library <library-name>

I'd prefer to call it from the shell ad-hoc, and let it create it's own scaffolding stuff, than to dish out my own makefile (or cmakelists). If nothing, then for the sake of autocompletion.

Keep in mind that this is in no way meant for anyhting other than for quick experiments or demonstrations - which is when I don't want to bore others (or myself) with the act of manually scaffolding a project.

To me this seems fairly intuitive and simple way of starting a quick C/C++ project. So is there such a thing or am I fantasizing a bit? (curse you webdevs and your too-simple-to-believe scaffolding tools!)

Please suggest an opinionated build/scaffolding system for quick C/C++ projects.

like image 495
Johnny Avatar asked Oct 31 '22 18:10

Johnny


1 Answers

Simple GNU Makefile that I use for single source to program mini projects that is fairly simple to turn all source files to single binary makefile.

CSRC = $(wildcard *.c)
CPPSRC = $(wildcard *.cpp)

CLEANF :=

all:

CFLAGS ?= -O2 -g -fomit-frame-pointer -Wall -Wextra

ifeq ($(V),)
CCS=@echo "   CC " $@ && $(CC)
CXXS=@echo "  CXX " $@ && $(CXX)
else
CCS=$(CC)
CXXS=$(CXX)
endif

CCMD = $$(CCS) $$(CFLAGS) $$< -o $$@
CPPCMD = $$(CXXS) $$(CFLAGS) $$< -o $$@

define MAKEPROG

$(basename $(1)): $(1)
    $(2) $$($(basename $(1))_CFLAGS)

all: $(basename $(1))

CLEANF += $(basename $(1))

endef

clean:
    @echo "  RM " $@ && $(RM) $(CLEANF)

$(foreach SRC,$(CSRC),\
    $(eval $(call MAKEPROG,$(SRC),$(CCMD))))

$(foreach SRC,$(CPPSRC),\
    $(eval $(call MAKEPROG,$(SRC),$(CPPCMD))))
like image 58
Pauli Nieminen Avatar answered Nov 15 '22 05:11

Pauli Nieminen