summaryrefslogtreecommitdiff
path: root/meme/Makefile.c-common
blob: 4d05ec2a5bb472d68d1b592fae1f56d1c170eb03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#
# common/Makefile.c-common - Common Makefile items for C
#
# Written 2013, 2014 by Werner Almesberger
# Copyright 2013, 2014 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


# Make sure "all" comes first

all::

# ----- Verbosity control -----------------------------------------------------

CC_normal	:= $(CC)
CPP_normal	:= $(CPP)
DEPEND_normal	= $(CPP_normal) $(CFLAGS) -MM -MG

ifeq ($(V),1)
    CC		= $(CC_normal)
    BUILD	=
    DEPEND	= $(DEPEND_normal)
else
    CC		= @echo "  CC       " $@ && $(CC_normal)
    BUILD	= @echo "  BUILD    " $@ &&
    DEPEND	= @$(DEPEND_normal)
endif

# ----- Dependencies ----------------------------------------------------------

-include $(OBJS:.o=.d)

MKDEP =									\
	$(DEPEND) $< |							\
	  sed 								\
	    -e 's|^$(basename $(notdir $<)).o:|$@:|'			\
	    -e '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/  */:\n/g;H;}'	\
	    -e '$${g;p;}'						\
	    -e d >$(basename $@).d;					\
	  [ "$${PIPESTATUS[*]}" = "0 0" ] ||				\
	  { rm -f $(basename $@).d; exit 1; }

%.o:		%.c
		$(CC) $(CFLAGS) -c $<
		$(MKDEP)

# ----- Cleanup ---------------------------------------------------------------

clean::
		rm -f $(OBJS) $(OBJS:.o=.d)