xref: /relibc/openlibm/Make.inc (revision bf188aeb2345c994909f5652cb3ac37f0144e8fe)
1# -*- mode: makefile-gmake -*-
2
3# Default build rule for any Makefile in this project: all
4default: all
5
6OS := $(shell uname)
7# Do not forget to bump SOMINOR when changing VERSION,
8# and SOMAJOR when breaking ABI in a backward-incompatible way
9VERSION = 0.5.5
10SOMAJOR = 2
11SOMINOR = 4
12DESTDIR =
13prefix = /usr/local
14bindir = $(prefix)/bin
15libdir = $(prefix)/lib
16includedir = $(prefix)/include
17
18ifeq ($(OS), FreeBSD)
19pkgconfigdir = $(prefix)/libdata/pkgconfig
20else
21pkgconfigdir = $(libdir)/pkgconfig
22endif
23
24USEGCC = 1
25USECLANG = 0
26
27ifneq (,$(findstring $(OS),Darwin FreeBSD OpenBSD))
28USEGCC = 0
29USECLANG = 1
30endif
31
32AR = ar
33
34ifeq ($(USECLANG),1)
35USEGCC = 0
36CC = clang
37CFLAGS_add += -fno-builtin -fno-strict-aliasing
38endif
39
40ifeq ($(USEGCC),1)
41CC = gcc
42CFLAGS_add += -fno-gnu89-inline -fno-builtin
43endif
44
45ARCH ?= $(shell $(CC) -dumpmachine | sed "s/\([^-]*\).*$$/\1/")
46
47ifeq ($(ARCH),mingw32)
48$(error "the mingw32 compiler you are using fails the openblas testsuite. please see the Julia README.windows.md document for a replacement")
49endif
50
51# OS-specific stuff
52ifeq ($(findstring arm,$(ARCH)),arm)
53override ARCH := arm
54MARCH ?= armv7-a
55CFLAGS_add += -mhard-float
56endif
57ifeq ($(findstring powerpc,$(ARCH)),powerpc)
58override ARCH := powerpc
59endif
60ifeq ($(findstring ppc,$(ARCH)),ppc)
61override ARCH := powerpc
62endif
63ifneq ($(filter $(ARCH),i386 i486 i586 i686 i387 i487 i587 i687),)
64override ARCH := i387
65MARCH ?= i686
66endif
67ifeq ($(ARCH),x86_64)
68override ARCH := amd64
69endif
70
71# If CFLAGS does not contain a -O optimization flag, default to -O3
72ifeq ($(findstring -O,$(CFLAGS)),)
73CFLAGS_add += -O3
74endif
75
76ifneq (,$(findstring MINGW,$(OS)))
77override OS=WINNT
78endif
79
80#keep these if statements separate
81ifeq ($(OS), WINNT)
82SHLIB_EXT = dll
83SONAME_FLAG = -soname
84CFLAGS_add += -nodefaultlibs
85shlibdir = $(bindir)
86else
87ifeq ($(OS), Darwin)
88SHLIB_EXT = dylib
89SONAME_FLAG = -install_name
90else
91SHLIB_EXT = so
92SONAME_FLAG = -soname
93endif
94CFLAGS_add += -fPIC
95shlibdir = $(libdir)
96endif
97
98# Add `-march` to our CFLAGS if it's defined
99ifneq ($(MARCH),)
100CFLAGS_arch += -march=$(MARCH)
101endif
102
103ifeq ($(ARCH),i387)
104CFLAGS_arch  += -m32
105SFLAGS_arch  += -m32
106LDFLAGS_arch += -m32
107endif
108
109ifeq ($(ARCH),amd64)
110CFLAGS_arch  += -m64
111SFLAGS_arch  += -m64
112LDFLAGS_arch += -m64
113endif
114
115# Add our "arch"-related FLAGS in.  We separate arch-related flags out so that
116# we can conveniently get at them for targets that don't want the rest of
117# *FLAGS_add, such as the testing Makefile targets
118CFLAGS_add  += $(CFLAGS_arch)
119SFLAGS_add  += $(SFLAGS_arch)
120LDFLAGS_add += $(LDFLAGS_arch)
121
122CFLAGS_add += -std=c99 -Wall -I$(OPENLIBM_HOME) -I$(OPENLIBM_HOME)/include -I$(OPENLIBM_HOME)/$(ARCH) -I$(OPENLIBM_HOME)/src -DASSEMBLER -D__BSD_VISIBLE -Wno-implicit-function-declaration
123ifneq ($(filter $(ARCH),i387 amd64 powerpc),)
124CFLAGS_add += -I$(OPENLIBM_HOME)/ld80
125else
126ifneq ($(filter $(ARCH),aarch64),)
127CFLAGS_add += -I$(OPENLIBM_HOME)/ld128
128endif
129endif
130
131
132# *int / *intf need to be built with -O0
133src/%int.c.o: src/%int.c
134	$(CC) $(CPPFLAGS) -O0 $(CFLAGS_add) -c $< -o $@
135
136src/%intf.c.o: src/%intf.c
137	$(CC) $(CPPFLAGS) -O0 $(CFLAGS_add) -c $< -o $@
138
139%.c.o: %.c
140	$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add) -c $< -o $@
141
142%.S.o: %.S
143	$(CC) $(CPPFLAGS) $(SFLAGS) $(SFLAGS_add) $(filter -m% -B% -I% -D%,$(CFLAGS_add)) -c $< -o $@
144
145
146# Makefile debugging trick:
147# call print-VARIABLE to see the runtime value of any variable
148print-%:
149	@echo '$*=$($*)'
150