File: Makefile

package info (click to toggle)
lmod 8.7.60-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 63,008 kB
  • sloc: sh: 6,266; makefile: 2,837; ansic: 1,513; tcl: 1,382; python: 1,050; csh: 112
file content (83 lines) | stat: -rw-r--r-- 1,828 bytes parent folder | download | duplicates (7)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
########################################################################
#  Use TARG_COMPILER_FAMILY to set the C compiler name

ifeq ($(TARG_COMPILER_FAMILY),gcc)
   CC := gcc
endif

ifeq ($(TARG_COMPILER_FAMILY),intel)
   CC := icc
endif


########################################################################
#  Use O_DIR as equal to $(TARG)/ so that if TARG is empty then O_DIR
#  will be empty.  But if $(TARG) as a value then O_DIR will have a
#  trailing slash.

ifneq ($(TARG),)
  override O_DIR := $(TARG)/
endif

########################################################################
#  Use TARG_BUILD_SCENARIO to set the compiler options for either
#  debug or optimize.

ifeq ($(TARG_BUILD_SCENARIO),dbg)
  CF := -g -O0
endif

ifeq ($(TARG_BUILD_SCENARIO),opt)
  CF := -O3
endif




DEPENDENCY_FLAG   := -MM
EXEC 		  := $(O_DIR)hello
SRC  		  := main.c hello.c
OBJS 		  := $(patsubst %.c, $(O_DIR)%.o, $(SRC))
override CFLAGS   := $(CFLAGS) $(CF)

all: $(O_DIR)
	$(MAKE) _all

_all:  $(EXEC)

$(O_DIR):
	mkdir -p $(O_DIR)

$(EXEC): $(OBJS)
	$(LINK.c) -o $@ $^

neat:
	$(RM) *~

clean: neat
	$(RM) $(OBJS)
clobber: clean
	$(RM) $(EXEC)
	$(RM) -r $(TARG) $(TARGET_PREFIX)





######################## compilation rules ###############################

$(O_DIR)%.o : %.c
	$(COMPILE.c) -o $@ -c $<

$(O_DIR)%.d: %.c
	$(SHELL) -c '$(CC) $(CFLAGS) -I $(O_DIR) $(DEPENDENCY_FLAG) $<             \
        | sed -e '\''s;\($*\)\.o[ :]*;$$(O_DIR)\1.o $$(O_DIR)$(notdir $@) : ;g'\'' \
              -e '\''s;$(O_DIR);$$(O_DIR);'\''                		           \
                                                         > $@;           	   \
	[ -s $@ ] || rm -f $@'

######################## Dependancies ####################################

ifneq (0,$(MAKELEVEL))
  include $(patsubst %.c,   $(O_DIR)%.d, $(SRC))
endif