Hello again,
This might be a bit of a ramble but feel free to chip in with any advice if I forget to specifically ask. :0)
So back in January I said I was coming back to C and C++, relearning and refreshing
[1]. I have got my hands on a few books
[2] that I'm going to be using for C++ refresher/study. I prefer good books to online resources but I have bookmarked a lot of C++ conference videos on YouTube.
For a long time now I have been Windows only (apart from a bit of tinkering with Raspberry Pi, BeagleBone,and the like) but I have got a bit...irked by the heavy weight nature of Visual Studio enterprise that I normally use. I was after a quick and simple way to roll out, edit, compile and test code and I was fighting Windows every step of the way. Step in a rather knackered old laptop with an AMD E1-1500 APU and 8 GB of RAM. With a fresh install Ubuntu 20.04 LTS and a bit of fettling I have a serviceable dev box...at least for now. I'm still remembering my way round developing on a *nix box and want to stick with command line tooling. Still finding my feet with vi/nvim
So with that in mind, I have started to create a basic directory that I can easily clone to start new toy projects. For this I decided to use
make so I can keep things consistent and tidy.
.
├── build
│ ├── apps
│ │ └── program
│ └── objects
│ └── source
│ ├── main.d
│ └── main.o
├── .clang-format
├── .clang-tidy
├── include
│ └── main.hpp
├── Makefile
└── source
└── main.cpp
|
Here is the makefile:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
TARGET := program
CXX := -clang++
CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror
LDFLAGS := -L/usr/lib -lstdc++ -lm
BUILD_DIR := ./build
OBJ_DIR := $(BUILD_DIR)/objects
APP_DIR := $(BUILD_DIR)/apps
INCLUDE := -Iinclude/
SRC := $(wildcard source/*.cpp)
OBJECTS := $(SRC:%.cpp=$(OBJ_DIR)/%.o)
DEPENDENCIES := $(OBJECTS:.o=.d)
all: build $(APP_DIR)/$(TARGET)
$(OBJ_DIR)/%.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -MMD -o $@
$(APP_DIR)/$(TARGET): $(OBJECTS)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS)
-include $(DEPENDENCIES)
.PHONY: all build clean debug release info
build:
@mkdir -p $(APP_DIR)
@mkdir -p $(OBJ_DIR)
debug: CXXFLAGS += -DDEBUG -g
debug: all
release: CXXFLAGS += -O2
release: all
clean:
-@rm -rvf $(OBJ_DIR)/*
-@rm -rvf $(APP_DIR)/*
info:
@echo "[*] Application dir: ${APP_DIR}"
@echo "[*] Object dir: ${OBJ_DIR}"
@echo "[*] Sources: ${SOURCE}"
@echo "[*] Objects: ${OBJECTS}"
@echo "[*] Dependencies: ${DEPENDENCIES}"
*/
|
I think it's okay, any thoughts?
I want to add
clang-format and
clang-tidy to the mix and maybe a test framework. I'm also trying to figure out how best to get
git involved.
As I said this is for quick toy/practice projects,
cmake will be used for larger/cross-platform things.
_______________________________________________________________________
[1]https://www.cplusplus.com/forum/lounge/275158/#msg1187467
[2]
The C++ Programming Language by Stroustrup Bjarne
C++ Standard Library, The: A Tutorial and Reference by Nicolai Josuttis
C++ Templates: The Complete Guide by David Vandevoorde , Nicolai Josuttis, et al.
C++17 - The Complete Guide by Nicolai M. Josuttis