File: Makefile

package info (click to toggle)
erlang-cl 1.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 704 kB
  • sloc: ansic: 6,712; erlang: 3,637; lisp: 490; makefile: 191
file content (203 lines) | stat: -rw-r--r-- 4,601 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#
# Copyright (C) 2016, Rogvall Invest AB, <tony@rogvall.se>
#
# This software is licensed as described in the file COPYRIGHT, which
# you should have received as part of this distribution. The terms
# are also available at http://www.rogvall.se/docs/copyright.txt.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYRIGHT file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#

## us NOCL=true make to force build with gcc on windows

OSNAME := $(shell uname -s)
MACHINE := $(shell uname -m)
OUT_C = -o
OUT_L = -o
OBJ = o


MAC_OS_X  = No
WIN32_GCC = No
WIN32_CL  = No
GNU       = No


ERL       = erl
EXT       = so
PRIVDIR=../priv


ifneq (, $(findstring MINGW,$(OSNAME)))
MINGW = Yes
ERL   = erl.exe
endif

ifeq ($(WSLcross), true)
# cross building from Windows WSL linux to native windows
ERL   = erl.exe
endif

WORDSIZE = $(shell $(ERL) -noshell -eval "io:format([126,119,126,110],[erlang:system_info(wordsize)*8])" -s erlang halt)

ifeq ($(OSNAME)$(WSLcross), Linux)
GNU = Yes
endif
ifeq ($(OSNAME), GNU/kFreeBSD)
GNU = Yes
endif
ifeq ($(OSNAME), GNU/Hurd)
GNU = Yes
endif

ifeq ($(GNU), Yes)
CFLAGS += -I/usr/include/nvidia-current
CFLAGS += -I/opt/AMDAPP/include
ifeq ($(WORDSIZE), 32)
CFLAGS += -O3 -fPIC
endif
ifeq ($(WORDSIZE), 64)
CFLAGS += -O3 -fPIC
endif
LD_SHARED	:= $(CC) -shared
LDFLAGS	        += -lOpenCL
endif

ifeq ($(OSNAME), Darwin)
MAC_OS_X = Yes
ifeq ($(WORDSIZE), 32)
CFLAGS += -O3 -fPIC -m32 -DDARWIN -no-cpp-precomp
LD_SHARED	:= $(CC) -m32 -bundle -flat_namespace -undefined suppress
endif
ifeq ($(WORDSIZE), 64)
CFLAGS += -O3 -fPIC -m64 -DDARWIN -no-cpp-precomp
LD_SHARED	:= $(CC) -m64 -bundle -flat_namespace -undefined suppress
endif
LDFLAGS += -framework OpenCL
endif

ERLDIR := $(shell $(ERL) -noshell -eval "io:format([126,115,126,110],[code:root_dir()])" -s erlang halt)
ERL_C_INCLUDE_DIR := "$(ERLDIR)/usr/include"

ifeq ($(TYPE), debug)
CFLAGS += -Ddebug -DDEBUG -g -Wall -Wextra -Wswitch-default -Wswitch-enum -D_THREAD_SAFE
CFLAGS += -D_REENTRANT -fno-common -I$(ERL_C_INCLUDE_DIR)
WIN_DEBUG = -Ddebug -DDEBUG
endif

ifeq ($(TYPE), release)
CFLAGS += -Wall -Wextra -Wswitch-default -Wswitch-enum -D_THREAD_SAFE -D_REENTRANT -fno-common
CFLAGS += -Wno-deprecated-declarations -Wno-missing-field-initializers -I$(ERL_C_INCLUDE_DIR)
endif

############### WINDOWS

ifeq ($(MINGW), Yes)
  EXT = dll
  ifeq ($(NOCL), true)
    WIN32_GCC=Yes
  else
    ifneq ($(findstring Microsoft,$(shell cl.exe 2>&1)), )
      WIN32_CL=Yes
      MS2C = MSYS2_ARG_CONV_EXCL=*
    else
      WIN32_GCC=Yes
    endif
  endif
endif

ifeq ($(WSLcross), true)
  # Only support MCL for WSLcross for now
  WIN32_CL=Yes
  EXT = dll
endif

ifeq ($(WIN32_CL), Yes)
## Use Microsoft CL
  CC=cl.exe
  MS2C = MSYS2_ARG_CONV_EXCL=*
  OUT_C = /Fo
  ifeq ($(OPENCL_DIR), )
    OPENCL_DIR = c:/msys64/opt/local/
  endif
  CFLAGS = /FS /Zi /nologo /W1 -DWIN32 -D__WIN32__ $(WIN_DEBUG)
  CFLAGS += /I$(OPENCL_DIR)/include /I$(ERL_C_INCLUDE_DIR)
  LD_SHARED=link.exe /DLL
  OUT_L=/OUT:
  ifeq ($(WORDSIZE), 32)
    LDFLAGS += /NOLOGO $(OPENCL_DIR)/lib/x86/OpenCL.lib
  else
    CFLAGS  += -DWIN_X64
    LDFLAGS += /NOLOGO $(OPENCL_DIR)/lib/x64/OpenCL.lib
  endif
endif

ifeq ($(WIN32_GCC), Yes)
  #CC=gcc
  CFLAGS += -D__WIN32__ $(WIN_DEBUG)
  ifeq ($(OPENCL_DIR), )
    OPENCL_DIR = /opt/local/
  endif

  ifeq ($(WORDSIZE), 32)
    CFLAGS += -shared -I$(OPENCL_DIR)/include -m32 -DWIN32
    LDFLAGS += -L$(OPENCL_DIR)/lib/x86 -lOpenCL
  endif
  ifeq ($(WORDSIZE), 64)
    CFLAGS += -shared -I$(OPENCL_DIR)/include -m64 -DWIN32
    CFLAGS += -DWIN_X64
    LDFLAGS += -L$(OPENCL_DIR)/lib/x64 -lOpenCL
  endif

  LD_SHARED	:= $(CC) -shared
## Optimizations is broken on mingw 4.4.0 (it crashes with it on)
  GCC_VERSION = $(shell gcc -dumpversion)
  ifneq ($(GCC_VERSION), 4.4.0)
    CFLAGS += -O3
  endif
endif
############### WINDOWS end

CL_NIF = $(PRIVDIR)/cl_nif.$(EXT)

CL_NIF_OBJS = \
	cl_nif.$(OBJ) \
	cl_hash.$(OBJ)

CL_NIF_SRC = \
	cl_nif.c \
	cl_hash.c

all:
	$(MAKE) nif TYPE=release

debug:
	$(MAKE) nif TYPE=debug

clean:
	rm -f $(CL_NIF_OBJS)
	rm -f $(CL_NIF)

release:
	$(MAKE) nif TYPE=release

nif: $(CL_NIF)

cl_nif.$(OBJ): cl_hash.h

clean_internal:
	-rm -f *.$(OBJ)
	-rm -f $(PRIVDIR)/*.$(EXT)

%.$(OBJ): %.c
	$(MS2C) $(CC) -c $(OUT_C)$@ $(CFLAGS) $<

$(CL_NIF): $(OCL_LIB) $(CL_NIF_OBJS)
	@mkdir -p $(PRIVDIR)
	$(MS2C) $(LD_SHARED) $(OUT_L)$@ $(CL_NIF_OBJS) $(LDFLAGS)