Does anyone know of a tool that generates a makefile by scanning a directory for source files?
It may be naive:
Make - a tool that automatically determines which source files of a program need to be recompiled and/or linked. Make gets its knowledge of how to build your program from a file called the makefile (or Makefile).
To create a makefile project in Visual StudioFrom the Visual Studio main menu, choose File > New > Project and type "makefile" into the search box. If you see more than one project template, select from the options depending on your target platform.
Creating a Makefile A Makefile typically starts with some variable definitions which are then followed by a set of target entries for building specific targets (typically .o & executable files in C and C++, and . class files in Java) or executing a set of command associated with a target label.
The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.
You can write a Makefile
that does this for you:
SOURCES=$(shell find . -name "*.cpp")
OBJECTS=$(SOURCES:%.cpp=%.o)
TARGET=foo
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJECTS)
Just place this in root directory of your source hierarchy and run make
(you'll need GNU Make for this to work).
(Note that I'm not fluent in Makefile
ish so maybe this can be done easier.)
CMake does it and it even creates makefiles and Visual Studio projects. http://www.cmake.org/
All you need to do is creating a CMakeLists.txt file containing the follwing lines:
file(GLOB sources *.h *.c *.cxx *.cpp *.hxx)
add_executable(Foo ${sources})
Then go into a clean directory and type:
cmake /path/to/project/
That will create makefiles on that clean build directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With