Create simple c and c++ projecs using make
I made this program while reading learncpp.com because i wanted to be able to quicly create simple c++ projects. It is not meant for making "production" makefiles so keep that in mind.
If you are an a linux system use "make install" to install the program. Then use "dtep -h" to see available options
Testing is done using the robot framework library for python and are found in the folder named "test". To run tests use the following command to run the tests:
robot TestSuite.robot
You have to have the robot framework installed. The tests also expect there to be a python virtual environment folder named venv. This is because the tests call the python program located in venv/bin/python.
A default project generated by dtep using
dtep new project-name c
would look something like this:
project-name
| - makefile
| - src
| | - main.c
| | - headers
# file: project-name/makefile
# made with dtep version 0.8
FLAGS += -Wall -Wextra -Werror -Wshadow -Wconversion -Wsign-conversion -pedantic-errors -std=c99
LDFLAGS +=
OBJ_DIR = obj
SRC_DIR = src
OUT_DIR = out
EXTENSION = .c
SRCS = $(wildcard $(SRC_DIR)/*$(EXTENSION))
OBJS = $(patsubst $(SRC_DIR)/%$(EXTENSION), $(OBJ_DIR)/%.o, $(SRCS))
NAME = $(OUT_DIR)/jarkko
.PHONY: debug release
debug: FLAGS += -g
debug: $(OUT_DIR) $(OBJ_DIR) $(NAME)
release: FLAGS += -march=native -O3 -DNDEBUG
release: $(OUT_DIR) $(OBJ_DIR) $(NAME)
$(NAME): $(OBJS)
$(CC) -o $(NAME) $(OBJS) $(LDFLAGS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%$(EXTENSION)
$(CC) -c $< -o $@ $(FLAGS)
clean:
rm -f $(OBJS) $(NAME)
$(OUT_DIR):
mkdir $(OUT_DIR)
$(OBJ_DIR):
mkdir $(OBJ_DIR)
/* file: project-name/src/main.c */
#include <stdio.h>
int main(void) {
printf("hello world\n");
return 0;
}
As you run make for the first time it will create folders named "obj" and "out" to house the object and executable files
The make file has two targets: "debug" and "release". Debug is meant for debuggin the program so it has the "-g" option. Release is meant to be the program to actually use it has optimisations turned to level 3 and the cpu optimisations set to native. Also the NDEBUG preprocessor macro is defined.
The bare minimum is "dtep mode(new, init) name(name for the project) language(cpp, c++, c)"
Some other options are:
- -h shows a help page
- -e allows you to set the file extension for source files (for c++ projects it is .cc by default)
- --std allows you to set the language standard for the project (example c99 or c++20)
- -g adds a .gitignore file if you plan on using git
- -s allows you tha change the name of the source directory
- --object-dir and --output-dir allow you to change the names of the directories where .obj files and executables are stored