Created
April 24, 2023 17:38
-
-
Save knebekaizer/3cb76ab55cf3130de7a39b2f6b4593e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# output binary | |
BIN := x | |
# source files | |
SRCS := \ | |
x.c | |
# files included in the tarball generated by 'make dist' (e.g. add LICENSE file) | |
DISTFILES := $(BIN) | |
# filename of the tar archive generated by 'make dist' | |
DISTOUTPUT := $(BIN).tar.gz | |
# intermediate directory for generated object files | |
OBJDIR := _o | |
# intermediate directory for generated dependency files | |
DEPDIR := _d | |
# object files, auto generated from source files | |
OBJS := $(patsubst %,$(OBJDIR)/%.o,$(basename $(SRCS))) | |
# dependency files, auto generated from source files | |
DEPS := $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))) | |
# compilers (at least gcc and clang) don't create the subdirectories automatically | |
# $(shell mkdir -p $(dir $(OBJS)) >/dev/null) | |
# $(shell mkdir -p $(dir $(DEPS)) >/dev/null) | |
# C compiler | |
CC := clang | |
# C++ compiler | |
CXX := clang++ | |
# linker | |
LD := clang++ | |
# tar | |
TAR := tar | |
# C flags | |
CFLAGS := -Ih0 -std=c11 | |
# C++ flags | |
CXXFLAGS := -std=c++11 | |
# C/C++ flags | |
CPPFLAGS := -g -Wall -Wextra -pedantic | |
# linker flags | |
LDFLAGS := | |
# linker flags: libraries to link (e.g. -lfoo) | |
LDLIBS := | |
# flags required for dependency generation; passed to compilers | |
# DEPFLAGS = -MT $@ -MD -MP -MF $(DEPDIR)/$*.Td | |
DEPFLAGS = -MT $@ -MD -MP -MF $(DEPDIR)/$*.d | |
# DEPFLAGS = -MT $@ -MD -MF $(DEPDIR)/$*.d | |
# compile C source files | |
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -c -o $@ | |
# compile C++ source files | |
COMPILE.cc = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ | |
# link object files to binary | |
LINK.o = $(LD) $(LDFLAGS) $(LDLIBS) -o $@ | |
# precompile step | |
PRECOMPILE = | |
# postcompile step | |
POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d | |
all: $(BIN) | $(OBJDIR) $(DEPDIR) | |
$(OBJDIR): | |
mkdir -p $(OBJDIR) | |
$(DEPDIR): | |
mkdir -p $(DEPDIR) | |
dist: $(DISTFILES) | |
$(TAR) -cvzf $(DISTOUTPUT) $^ | |
.PHONY: clean | |
clean: | |
$(RM) -r $(OBJDIR) $(DEPDIR) | |
.PHONY: distclean | |
distclean: clean | |
$(RM) $(BIN) $(DISTOUTPUT) | |
.PHONY: install | |
install: | |
@echo no install tasks configured | |
.PHONY: uninstall | |
uninstall: | |
@echo no uninstall tasks configured | |
.PHONY: check | |
check: | |
@echo no tests configured | |
.PHONY: help | |
help: | |
@echo available targets: all dist clean distclean install uninstall check | |
$(BIN): $(OBJS) | |
@echo Run linker... | |
$(LINK.o) $^ | |
$(OBJDIR)/%.o: %.c | $(OBJDIR) $(DEPDIR) | |
$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d | $(OBJDIR) $(DEPDIR) | |
@echo 111 | |
$(PRECOMPILE) | |
[ -f _d/x.d ] && cat _d/x.d || true | |
@echo 112 | |
$(COMPILE.c) $< | |
[ -f _d/x.d ] && cat _d/x.d || true | |
@echo 113 | |
# $(POSTCOMPILE) | |
@echo 114 | |
$(OBJDIR)/%.o: %.cpp | |
$(OBJDIR)/%.o: %.cpp $(DEPDIR)/%.d | |
$(PRECOMPILE) | |
$(COMPILE.cc) $< | |
$(POSTCOMPILE) | |
$(OBJDIR)/%.o: %.cc | |
$(OBJDIR)/%.o: %.cc $(DEPDIR)/%.d | |
$(PRECOMPILE) | |
$(COMPILE.cc) $< | |
$(POSTCOMPILE) | |
$(OBJDIR)/%.o: %.cxx | |
$(OBJDIR)/%.o: %.cxx $(DEPDIR)/%.d | |
$(PRECOMPILE) | |
$(COMPILE.cc) $< | |
$(POSTCOMPILE) | |
.PRECIOUS: $(DEPDIR)/%.d | |
$(DEPDIR)/%.d: ; | |
-include $(DEPS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment