File: makefile.tmpl

package info (click to toggle)
nim 0.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 290,936 kB
  • ctags: 1,049,726
  • sloc: sh: 7,408; ansic: 1,464; makefile: 358; objc: 224; asm: 199; xml: 129; java: 56; pascal: 32; python: 20
file content (169 lines) | stat: -rw-r--r-- 3,108 bytes parent folder | download | duplicates (2)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#? stdtmpl(subsChar='?') | standard
#proc generateMakefile(c: ConfigData): string =
#  result = "# Generated from niminst\n" &
#           "# Template is in tools/niminst/makefile.tmpl\n" &
#           "# To regenerate run ``niminst csource`` or ``koch csource``\n"

CC = gcc
LINKER = gcc
COMP_FLAGS = $(CPPFLAGS) $(CFLAGS) ?{c.ccompiler.flags}
LINK_FLAGS = $(LDFLAGS) ?{c.linker.flags}
binDir = ?{firstBinPath(c).toUnix}

koch := $(shell sh -c 'test -s ../koch.nim && echo "yes"')
ifeq ($(koch),yes)
	binDir = ../bin
endif

ucpu := $(shell sh -c 'uname -m | tr "[:upper:]" "[:lower:]"')
uos := $(shell sh -c 'uname | tr "[:upper:]" "[:lower:]"')

ifeq ($(uos),linux)
	myos = linux
	LINK_FLAGS += -ldl -lm
endif
ifeq ($(uos),dragonfly)
	myos = freebsd
	LINK_FLAGS += -lm
endif
ifeq ($(uos),freebsd)
	myos= freebsd
	CC = clang
	LINKER = clang
	LINK_FLAGS += -lm
endif
ifeq ($(uos),openbsd)
	myos = openbsd
	LINK_FLAGS += -lm
endif
ifeq ($(uos),netbsd)
	myos = netbsd
	LINK_FLAGS += -lm
endif
ifeq ($(uos),darwin)
	myos = macosx
	CC = clang
	LINKER = clang
	LINK_FLAGS += -ldl -lm
	ifeq ($HOSTTYPE,x86_64)
		ucpu = amd64
	endif
endif
ifeq ($(uos),aix)
	myos = aix
	LINK_FLAGS += -dl -lm
endif
ifeq ($(uos),solaris)
	myos = solaris
	LINK_FLAGS += -ldl -lm -lsocket -lnsl
endif
ifeq ($(uos),sun)
	myos = solaris
	LINK_FLAGS += -ldl -lm -lsocket -lnsl
endif
ifeq ($(uos),haiku)
	myos = haiku
endif
ifndef uos
	@echo "Error: unknown operating system: $(uos)"
	@exit 1
endif

ifeq ($(ucpu),i386)
	mycpu = i386
endif
ifeq ($(ucpu),i486)
	mycpu = i386
endif
ifeq ($(ucpu),i586)
	mycpu = i386
endif
ifeq ($(ucpu),i686)
	mycpu = i386
endif
ifeq ($(ucpu),bepc)
	mycpu = i386
endif
ifeq ($(ucpu),i86pc)
	mycpu = i386
endif
ifeq ($(ucpu),amd64)
	mycpu = amd64
endif
ifeq ($(ucpu),x86-64)
	mycpu = amd64
endif
ifeq ($(ucpu),x86_64)
	mycpu = amd64
endif
ifeq ($(ucpu),sparc)
	mycpu = sparc
endif
ifeq ($(ucpu),sun)
	mycpu = sparc
endif
ifeq ($(ucpu),ppc64)
	mycpu = powerpc64
	ifeq ($(myos),linux)
		COMP_FLAGS += -m64
		LINK_FLAGS += -m64
	endif
endif
ifeq ($(ucpu),powerpc)
	mycpu = powerpc
endif
ifeq ($(ucpu),ppc)
	mycpu = ppc
endif
ifeq ($(ucpu),mips)
	mycpu = mips
endif
ifeq ($(ucpu),arm)
	mycpu = arm
endif
ifeq ($(ucpu),armeb)
	mycpu = arm
endif
ifeq ($(ucpu),armel)
	mycpu = arm
endif
ifeq ($(ucpu),armv6l)
	mycpu = arm
endif
ifndef ucpu
	@echo "Error: unknown processor : $(ucpu)"
	@exit 1
endif

# for osA in 1..c.oses.len:
ifeq ($(myos),?{c.oses[osA-1]})
#   for cpuA in 1..c.cpus.len:
	ifeq ($(mycpu),?{c.cpus[cpuA-1]})
#     var oFiles = ""
#     for ff in c.cfiles[osA][cpuA].items:
#       oFiles.add(" " & changeFileExt(ff.toUnix, "o"))
#     end for
		oFiles =?oFiles
	endif
#   end for
endif
# end for

.check-arch:
ifeq ($(strip $(oFiles)),)
	@echo "Error: no C code generated for: [$(myos): $(mycpu)]"
	@exit 1
endif

%.o: %.c
	$(CC) $(COMP_FLAGS) -Ic_code -c $< -o $@

?{"$(binDir)/" & toLowerAscii(c.name)}: .check-arch $(oFiles)
	@mkdir -p $(binDir)
	$(LINKER) -o $@ $(oFiles) $(LINK_FLAGS)
	@echo "SUCCESS"

.PHONY: clean .check-arch

clean:
	rm -f $(oFiles) ?{"$(binDir)/" & toLowerAscii(c.name)}