auto_build
is a C++ utility that monitors.cpp
files in a specified directory for changes. When a change is detected, it automatically runs themake
command to rebuild the project. This tool is useful for developers who want to automate the build process during development, ensuring that their project is always up-to-date with the latest changes.- There are two options when using the tool you can either use the General version that works on all machines including, UNIX, Linux, Mac, and Windows or you can use the Windows specific version that works only on Windows machines. That are running at least
Windows 2000 Professional
or in technical terms at least supportWin32 API
. Although for now there are not many differences in this version for now but provides you with a Windows style MessageBox that alerts you when your build fails.
- File Scanning: The program scans the specified directory and its subdirectories for
.cpp
files. - Record Modification Times: It records the last modification times of these files.
- Monitoring Loop: It enters a loop where it periodically checks the modification times of the files.
- Detect Changes: If a change is detected in any of the
.cpp
files, it prints the file path to the console and runs themake
command to rebuild the project.
- Clone the Repository: Clone the repository containing the
auto_build
utility to your local machine.git clone https://github.com/Halleys123/CPP_Auto_Build cd auto_build
- Compile the Program: Compile
main.cpp
using using g++ compiler, by using the given make file:make build
- You can use above command if you want to build general version of the program.
- As for Windows users you can use to build the Windows specific version of the program:
make build BUILD=WIN
- Run the Program: Execute the compiled binary, specifying the directory to monitor. By default, it monitors the current directory (
./
):./build.exe
- Modify Files: Make changes to any
.cpp
files in the monitored directory. The program will detect the changes and automatically run themake
command.
You can set various flags when running the program:
- Interval: Set the monitoring interval in milliseconds.
./auto_build --interval 200
- Enable Logging: Enable or disable logging.
./auto_build --log true
- Log File: Set the log file path.
./auto_build --log_file log.txt
- Default Interval: Set the default interval used by the program if the user interval is invalid.
./auto_build --default_interval 100
- Help: Display the help message.
./auto_build --help
- C++17 or later: Ensure your compiler supports C++17 or later.
- Make Utility: A
make
utility must be installed on your system to build the project.
- Make Configuration: Ensure that the
make
command is properly configured to build your project. This typically involves having aMakefile
in the root of your project directory. - Monitoring Interval: The monitoring interval is set to 100 miliseconds. You can adjust this interval by using the
-df <interval>
flag, where<interval>
is the desired interval in miliseconds. - Logging: By default, logging is disabled. You can enable logging by using the
-log true
flag.
Here is an example of how to use auto_build
:
- Create your Project Folder: In the given command block, a file called
main.cpp
is generated.mkdir sample_project cd sample_project echo -e '#include <iostream>\nint main() { std::cout << "Hello, World!"; return 0; }' > main.cpp echo -e 'all:\n\tg++ -o main main.cpp' > Makefile
- Compile and Run
auto_build
: Now you build theauto_build.cpp
orauto_build_windows.cpp
depending on your operating system.g++ -std=c++17 -o auto_build ../auto_build.cpp ./auto_build
- Modify
main.cpp
:Theecho -e '#include <iostream>\nint main() { std::cout << "Hello, Auto Update!"; return 0; }' > main.cpp
auto_build
program will detect the change and automatically run themake
command to rebuild the project.
This project is licensed under the MIT License.
Dated: 27:01:2025::02:34:56
- Now you can make run specific commands for a change in specific files. For example, if you want to run
make dll_test
command if your files saydll_test.cpp
changes you can do that by adding aconfig.cfg
file in the same directory as theauto_build
executable. Theconfig.cfg
file should be in the following format:This will run thedll_test.cpp="make dll_test"
make dll_test
command ifdll_test.cpp
changes.
- If using this feature you should try to keep all files names unique wether they are in different directories or not. As the program will only check the file name and not the path.
Dated: 27:01:2025::02:52:32
- Config.cfg will not invalidate on reading comments starting with hash '#'.
- The
config.cfg
file will no longer be invalidated when reading lines with special commands such astest.cpp,test1/cpp="make test"
ortest.cpp="make t"
, which previously caused invalidation.
Dated: 27:01:2025::03:01:45
- Overhauled the entire codebase to make it more modular and easier to maintain.