Last active
April 28, 2020 23:02
-
-
Save ljmccarthy/4565046 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
TARGET = myprogram | |
SRCDIRS = src | |
INCDIRS = include | |
OBJDIR = /tmp/myprogram-build | |
LIBDIRS = | |
LIBS = | |
DEFINES = | |
PKGS = | |
CFLAGS = -std=c++98 -Wall -W -fvisibility=hidden -fvisibility-inlines-hidden | |
LINKFLAGS = | |
ifeq ($(strip $(DEBUG)),) | |
CFLAGS += -Os -fomit-frame-pointer | |
DEFINES += NDEBUG | |
else | |
CFLAGS += -ggdb | |
endif | |
PKG_CFLAGS = $(foreach pkg,$(PKGS),$(shell pkg-config --cflags $(pkg))) | |
PKG_LIBS = $(foreach pkg,$(PKGS),$(shell pkg-config --libs $(pkg))) | |
CFLAGS += $(PKG_CFLAGS) $(DEFINES:%=-D%) $(INCDIRS:%=-I%) | |
LIBFLAGS = $(PKG_LIBS) $(LIBDIRS:%=-L%) $(LIBS:%=-l%) | |
SRCFILES = $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c)) \ | |
$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cxx)) | |
DEPFILES = $(SRCFILES:%=$(OBJDIR)/%.d) | |
OBJFILES = $(SRCFILES:%=$(OBJDIR)/%.o) | |
.PHONY : all clean | |
all : $(TARGET) | |
$(TARGET) : $(OBJFILES) | |
@echo " EXE $@" | |
@g++ -pipe -o $@ $(OBJFILES) $(LINKFLAGS) $(LIBFLAGS) | |
ifeq ($(strip $(DEBUG)),) | |
@strip -s -R .comment $@ | |
endif | |
clean : | |
@rm -rf $(TARGET) $(OBJDIR) | |
$(OBJDIR)/%.c.o : %.c | |
@echo " GCC $<" | |
@gcc -c -pipe -fPIC $(CFLAGS) -o $@ $< | |
$(OBJDIR)/%.cxx.o : %.cxx | |
@echo " G++ $<" | |
@g++ -c -pipe -fPIC $(CFLAGS) -o $@ $< | |
$(OBJDIR)/%.c.d : %.c | |
@mkdir -p $(dir $@) | |
@gcc -MM -MP -MT "$(OBJDIR)/$<.o" $(CFLAGS) $< > $@ || (rm -f $@; exit 1) | |
$(OBJDIR)/%.cxx.d : %.cxx | |
@mkdir -p $(dir $@) | |
@g++ -MM -MP -MT "$(OBJDIR)/$<.o" $(CFLAGS) $< > $@ || (rm -f $@; exit 1) | |
ifneq ($(MAKECMDGOALS),clean) | |
-include $(DEPFILES) | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment