From 81f51e909a6aca2d94efd602c36a8c23f444b2fc Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 22 Jul 2016 00:04:08 -0300 Subject: [PATCH] common/Makefile.c-common: common Makefile items for C Snatched from Anelok. --- common/Makefile.c-common | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 common/Makefile.c-common diff --git a/common/Makefile.c-common b/common/Makefile.c-common new file mode 100755 index 0000000..6c9fe68 --- /dev/null +++ b/common/Makefile.c-common @@ -0,0 +1,80 @@ +# +# common/Makefile.c-common - Common Makefile items for C +# +# Written 2013-2016 by Werner Almesberger +# Copyright 2013-2016 by Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + +SHELL = /bin/bash + + +OBJ_SUFFIX ?= .o + +# Make sure "all" comes first + +all:: + +# ----- YACC settings --------------------------------------------------------- + +YACC = bison -y +YYFLAGS = -v + +# ----- Verbosity control ----------------------------------------------------- + +CC_normal := $(CC) +AS_normal := $(AS) +CPP_normal := $(CPP) +LEX_normal := $(LEX) +YACC_normal := $(YACC) +DEPEND_normal = $(CPP_normal) $(CFLAGS) -MM -MG + +ifeq ($(V),1) + CC = $(CC_normal) + AS = $(AS_normal) + LEX = $(LEX_normal) + YACC = $(YACC_normal) + BUILD = + DEPEND = $(DEPEND_normal) +else + CC = @echo " CC " $@ && $(CC_normal) + AS = @echo " AS " $@ && $(AS_normal) + LEX = @echo " LEX " $@ && $(LEX_normal) + YACC = @echo " YACC " $@ && $(YACC_normal) + BUILD = @echo " BUILD " $@ && + DEPEND = @$(DEPEND_normal) +endif + +# ----- Dependencies ---------------------------------------------------------- + +-include $(OBJS:$(OBJ_SUFFIX)=.d) + +MKDEP = \ + $(DEPEND) $< | \ + sed \ + -e 's|^$(basename $(notdir $<))\$(OBJ_SUFFIX):|$@:|' \ + -e '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \ + -e '$${g;p;}' \ + -e d >$(basename $@).d; \ + [ "$${PIPESTATUS[*]}" = "0 0" ] || \ + { rm -f $(basename $@).d; exit 1; } + +# +# See +# http://stackoverflow.com/questions/5229561/gnu-make-generating-automatic-dependencies-with-generated-header-files +# + +.PHONY: generated_headers + +%$(OBJ_SUFFIX): %.c | generated_headers + $(CC) $(CFLAGS) -c $< + $(MKDEP) + +# ----- Cleanup --------------------------------------------------------------- + +clean:: + rm -f $(OBJS) $(OBJS:$(OBJ_SUFFIX)=.d)