-
-
Save zobayer1/7265c698d1b024bb7723bc624aeedeb3 to your computer and use it in GitHub Desktop.
| # Pre-compiler and Compiler flags | |
| CXX_FLAGS := -Wall -Wextra -std=c++17 -ggdb | |
| PRE_FLAGS := -MMD -MP | |
| # Project directory structure | |
| BIN := bin | |
| SRC := src | |
| LIB := lib | |
| INC := include | |
| MAINFILE := $(SRC)/main.cpp | |
| # Build directories and output | |
| TARGET := $(BIN)/main | |
| BUILD := build | |
| # Library search directories and flags | |
| EXT_LIB := | |
| LDFLAGS := | |
| LDPATHS := $(addprefix -L,$(LIB) $(EXT_LIB)) | |
| # Include directories | |
| INC_DIRS := $(INC) $(shell find $(SRC) -type d) | |
| INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | |
| # Construct build output and dependency filenames | |
| SRCS := $(shell find $(SRC) -name *.cpp) | |
| OBJS := $(subst $(SRC)/,$(BUILD)/,$(addsuffix .o,$(basename $(SRCS)))) | |
| DEPS := $(OBJS:.o=.d) | |
| # Run task | |
| run: build | |
| @echo "π Executing..." | |
| ./$(TARGET) $(ARGS) | |
| # Build task | |
| build: clean all | |
| # Main task | |
| all: $(TARGET) | |
| # Task producing target from built files | |
| $(TARGET): $(OBJS) | |
| @echo "π§ Building..." | |
| mkdir -p $(dir $@) | |
| $(CXX) $(OBJS) -o $@ $(LDPATHS) $(LDFLAGS) | |
| # Compile all cpp files | |
| $(BUILD)/%.o: $(SRC)/%.cpp | |
| mkdir -p $(dir $@) | |
| $(CXX) $(CXX_FLAGS) $(PRE_FLAGS) $(INC_FLAGS) -c -o $@ $< $(LDPATHS) $(LDFLAGS) | |
| # Clean task | |
| .PHONY: clean | |
| clean: | |
| @echo "π§Ή Clearing..." | |
| rm -rf build | |
| # Include all dependencies | |
| -include $(DEPS) |
Firstly, thank you for this, it is excellent!
For Apple framework inclusion I added: FWFLAGS := -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework CoreServices and appended it to # Task producing target from built files.
I had to remove $(LDPATHS) $(LDFLAGS) from the # Compile all cpp files stage as I got warnings about unused flags. Is this normal?
Firstly, thank you for this, it is excellent!
For Apple framework inclusion I added:
FWFLAGS := -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework CoreServicesand appended it to# Task producing target from built files.I had to remove
$(LDPATHS) $(LDFLAGS)from the# Compile all cpp filesstage as I got warnings about unused flags. Is this normal?
Did you need to remove both or may be just LDPATHS. Are they empty? They are set in the # Library search directories and flags section.
Firstly, thank you for this, it is excellent!
For Apple framework inclusion I added:FWFLAGS := -framework CoreFoundation -framework CoreGraphics -framework CoreText -framework CoreServicesand appended it to# Task producing target from built files.
I had to remove$(LDPATHS) $(LDFLAGS)from the# Compile all cpp filesstage as I got warnings about unused flags. Is this normal?Did you need to remove both or may be just LDPATHS. Are they empty? They are set in the
# Library search directories and flagssection.
I had to remove both from the # Compile all cpp files section. I do have them set to something. But it seems those flags were only used in # Task producing target from built files.
OS: Linux, GNU Make 4.2.1
Project Structure
Assuming standard C++ project structure,
. βββ bin β βββ main βββ data β βββ problem.in βββ include βββ lib βββ Makefile βββ src βββ main.cpp βββ nonogram βββ nonogram.cpp βββ nonogram.hMakefile
Makefile will compile all cpp sources, and generate dependency files. So there is no need to worry about including header files. All output and dependency files will be generated into
builddirectory before making target inbindirectory.Makefile declares common tasks such as
all,build,runandclean. Command line parameters can be passed with$ARGSvariable whichruntask can make use of when executing the maintarget.Tree After Make
. βββ bin β βββ main βββ build β βββ main.d β βββ main.o β βββ nonogram β βββ nonogram.d β βββ nonogram.o βββ data β βββ problem.in βββ include βββ lib βββ Makefile βββ src βββ main.cpp βββ nonogram βββ nonogram.cpp βββ nonogram.hNote
When copying, make sure indentations are actually TAB characters, otherwise
makewon't be happy.