Writing and editing Makefiles manually can be a time-consuming and repetitive task. The aim of this project is to create a program which when given a relevant source code can itself generate a makefile, with sufficient power for user to select compilers, flags, etc.
To generate Makefile for any source code directory
This project is currently being built with CMakeLists, once it reaches a specific level of operational-ity, a makefile can be generated with the help of this program itself, and in a sense the whole project can be "bootstrapped".
-
For the purpose of this project, a makefile can be divided into three separate parts -
-
Macros
CC=g++ CFLAGS= -c -Wall
-
Object-code generation
main.o: main.cpp $(CC) $(CFLAGS) main.cpp factorial.o: factorial.cpp $(CC) $(CFLAGS) factorial.cpp hello.o: hello.cpp $(CC) $(CFLAGS) hello.cpp
-
Executable generation
prog: main.o factorial.o hello.o $(CC) main.o factorial.o hello.o -o prog
-
The original project is build using CMake, for this a CMakeLists.txt file is stored at /MakefileGenerator (/MakefileGenerator/CMakeLists.txt).
In order to build, ensure that the CMake utility is already installed (CMake 3.24 or higher is required).
- Change current directory to /MakefileGenerator and
- then call cmake /MakefileGenerator/CMakeLists.txt
For example:
$ cd /MakefileGenerator
$ cmake /MakefileGenerator/CMakeLists.txt
-
Once the building process is done, makefile for other projects can be generated by calling the executable(of MakefileGenerator)
-
It relies on several command line arguments to get addition information
Command Function Mandatory? -ccset For setting compiler No -S For setting source code directory for which makefile is to be generated Yes -f1 For setting compile flag number 1 No -f2 For setting compile flag number 2 No -exec_name For setting the name for the executable to be produced No -block_comment To set option of enabling or disabling block identifying comment in makefile (By default it is disabled) No
$ ./MakefileGenerator -S /home/Programs.... -ccset gcc -f1 Wall -f2 pipe -exec_name program