Root/common/Makefile.c-common

1#
2# common/Makefile.c-common - Common Makefile items for C
3#
4# Written 2013-2016 by Werner Almesberger
5# Copyright 2013-2016 by Werner Almesberger
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12
13SHELL = /bin/bash
14
15
16OBJ_SUFFIX ?= .o
17
18# Make sure "all" comes first
19
20all::
21
22# ----- YACC settings ---------------------------------------------------------
23
24YACC = bison -y
25YYFLAGS = -v
26
27# ----- Verbosity control -----------------------------------------------------
28
29CC_normal := $(CC)
30AS_normal := $(AS)
31CPP_normal := $(CPP)
32LEX_normal := $(LEX)
33YACC_normal := $(YACC)
34DEPEND_normal = $(CPP_normal) $(CFLAGS) -MM -MG
35
36ifeq ($(V),1)
37    CC = $(CC_normal)
38    AS = $(AS_normal)
39    LEX = $(LEX_normal)
40    YACC = $(YACC_normal)
41    BUILD =
42    DEPEND = $(DEPEND_normal)
43else
44    CC = @echo " CC " $@ && $(CC_normal)
45    AS = @echo " AS " $@ && $(AS_normal)
46    LEX = @echo " LEX " $@ && $(LEX_normal)
47    YACC = @echo " YACC " $@ && $(YACC_normal)
48    BUILD = @echo " BUILD " $@ &&
49    DEPEND = @$(DEPEND_normal)
50endif
51
52# ----- Dependencies ----------------------------------------------------------
53
54-include $(OBJS:$(OBJ_SUFFIX)=.d)
55
56MKDEP = \
57    $(DEPEND) $< | \
58      sed \
59        -e 's|^$(basename $(notdir $<))\$(OBJ_SUFFIX):|$@:|' \
60        -e '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
61        -e '$${g;p;}' \
62        -e d >$(basename $@).d; \
63      [ "$${PIPESTATUS[*]}" = "0 0" ] || \
64      { rm -f $(basename $@).d; exit 1; }
65
66#
67# See
68# http://stackoverflow.com/questions/5229561/gnu-make-generating-automatic-dependencies-with-generated-header-files
69#
70
71.PHONY: generated_headers
72
73%$(OBJ_SUFFIX): %.c | generated_headers
74        $(CC) $(CFLAGS) -c -o $@ $<
75        $(MKDEP)
76
77# ----- Cleanup ---------------------------------------------------------------
78
79clean::
80        rm -f $(OBJS) $(OBJS:$(OBJ_SUFFIX)=.d)
81

Archive Download this file

Branches:
master



interactive