summaryrefslogtreecommitdiff
path: root/Makefile.c-common
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-23 15:22:53 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-08-23 15:22:53 (GMT)
commit35d6f7be958518d04fd8b085c5945b703a7f1afa (patch)
treebca57b866e7fda24afe4ad71f91a1e65565c40ab /Makefile.c-common
parentf35da4b7bc5e31cb0b629399b5db9e24d423b362 (diff)
downloadeeshow-35d6f7be958518d04fd8b085c5945b703a7f1afa.zip
eeshow-35d6f7be958518d04fd8b085c5945b703a7f1afa.tar.gz
eeshow-35d6f7be958518d04fd8b085c5945b703a7f1afa.tar.bz2
Makefile.c-common: copy over from eda-tools/common/
Diffstat (limited to 'Makefile.c-common')
-rwxr-xr-xMakefile.c-common80
1 files changed, 80 insertions, 0 deletions
diff --git a/Makefile.c-common b/Makefile.c-common
new file mode 100755
index 0000000..487c3ff
--- /dev/null
+++ b/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 -o $@ $<
+ $(MKDEP)
+
+# ----- Cleanup ---------------------------------------------------------------
+
+clean::
+ rm -f $(OBJS) $(OBJS:$(OBJ_SUFFIX)=.d)