Root/
| 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 | |
| 13 | SHELL = /bin/bash |
| 14 | |
| 15 | |
| 16 | OBJ_SUFFIX ?= .o |
| 17 | |
| 18 | # Make sure "all" comes first |
| 19 | |
| 20 | all:: |
| 21 | |
| 22 | # ----- YACC settings --------------------------------------------------------- |
| 23 | |
| 24 | YACC = bison -y |
| 25 | YYFLAGS = -v |
| 26 | |
| 27 | # ----- Verbosity control ----------------------------------------------------- |
| 28 | |
| 29 | CC_normal := $(CC) |
| 30 | AS_normal := $(AS) |
| 31 | CPP_normal := $(CPP) |
| 32 | LEX_normal := $(LEX) |
| 33 | YACC_normal := $(YACC) |
| 34 | DEPEND_normal = $(CPP_normal) $(CFLAGS) -MM -MG |
| 35 | |
| 36 | ifeq ($(V),1) |
| 37 | CC = $(CC_normal) |
| 38 | AS = $(AS_normal) |
| 39 | LEX = $(LEX_normal) |
| 40 | YACC = $(YACC_normal) |
| 41 | BUILD = |
| 42 | DEPEND = $(DEPEND_normal) |
| 43 | else |
| 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) |
| 50 | endif |
| 51 | |
| 52 | # ----- Dependencies ---------------------------------------------------------- |
| 53 | |
| 54 | -include $(OBJS:$(OBJ_SUFFIX)=.d) |
| 55 | |
| 56 | MKDEP = \ |
| 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 | |
| 79 | clean:: |
| 80 | rm -f $(OBJS) $(OBJS:$(OBJ_SUFFIX)=.d) |
| 81 |
Branches:
master
