1# This file is part of the Astrometry.net suite.
2# Licensed under a 3-clause BSD style license - see LICENSE
3
4INCLUDE_BASE_DIR := $(BASEDIR)/include
5INCLUDE_DIR := $(INCLUDE_BASE_DIR)/astrometry
6
7PYTHON ?= python3
8INSTALL_DIR ?= /usr/local/astrometry
9# Put INSTALL_DIR in the environment of commands run by Make.
10export INSTALL_DIR
11
12# don't change this one -- it must match what is in the bin/* scripts.
13PYTHON_SCRIPT_DEFAULT := /usr/bin/env python3
14
15# change this if you want to set exactly which python program gets run to
16# execute the python scripts in bin/ (image2pnm and friends).
17# Note that this must be a full path (this is a bash requirement).
18PYTHON_SCRIPT ?= $(PYTHON_SCRIPT_DEFAULT)
19# eg,
20#PYTHON_SCRIPT ?= /usr/bin/python3.5
21
22# Installation subdirs
23
24PY_BASE_INSTALL_DIR ?= $(INSTALL_DIR)/lib/python/astrometry
25INCLUDE_INSTALL_DIR := $(INSTALL_DIR)/include/astrometry
26LIB_INSTALL_DIR := $(INSTALL_DIR)/lib
27BIN_INSTALL_DIR := $(INSTALL_DIR)/bin
28DATA_INSTALL_DIR := $(INSTALL_DIR)/data
29PY_BASE_LINK_DIR ?= ../lib/python/astrometry
30ETC_INSTALL_DIR ?= $(INSTALL_DIR)/etc
31MAN1_INSTALL_DIR ?= $(INSTALL_DIR)/share/man/man1
32DOC_INSTALL_DIR ?= $(INSTALL_DIR)/doc
33EXAMPLE_INSTALL_DIR ?= $(INSTALL_DIR)/examples
34
35# If your build system stages an install in one place (say, a temp
36# dir) and then copies everything to the final install place, (eg,
37# debian), set *_INSTALL_DIR to the staging place and *_FINAL_DIR to
38# the final destination directory.
39
40# This should rarely be used, since hardly anything should care that
41# it's going to be moved after being staged.
42# (ie, the only place it's used at the moment is in solver/Makefile when
43#  putting the final data directory in the config file etc/astrometry.cfg)
44
45FINAL_DIR ?= $(INSTALL_DIR)
46DATA_FINAL_DIR ?= $(FINAL_DIR)/data
47
48
49# only set CC if it hasn't already been set
50# (this allows the user to override it)
51## can't use "CC ?= gcc" because CC gets a default value
52ifeq ($(origin CC), default)
53  CC := gcc
54endif
55
56# no default rules
57.SUFFIXES :=
58
59# These are files
60%.py: ;
61%.i: ;
62%.c: ;
63%.h: ;
64%.awk: ;
65%.inc: ;
66%.ph: ;
67makefile.%: ;
68Makefile: ;
69
70# Cancel stupid implicit rules.
71%: %,v
72%: RCS/%,v
73%: RCS/%
74%: s.%
75%: SCCS/s.%
76
77# sh shell
78AN_SHELL ?= /bin/sh
79
80RANLIB ?= ranlib
81
82AWK ?= LC_ALL=C LC_NUMERIC=EN_US awk
83
84SED ?= sed
85
86MV ?= mv
87
88CP ?= cp
89
90CHMOD_EXECUTABLE ?= chmod 755
91
92MKDIR ?= mkdir -p
93
94FLAGS_DEF := -g -Wall
95
96TMPFILE := cc-out.tmp
97
98# Test whether $(CC) accepts a particular argument; set ARG before running.
99
100#CCTEST = $(CC) -x c -c -o $(TMPFILE) $(ARG) - < /dev/null > /dev/null 2> /dev/null && echo $(ARG)
101
102# On MacOS, unrecognized gcc args don't cause it to return 1... look for error messages on stderr.
103# Intel icc/13 says: icc: command line warning #10006: ignoring unknown option '-fno-signaling-nans'
104CCTEST = $(CC) -x c -c -o $(TMPFILE) $(ARG) - 2>&1 > /dev/null < /dev/null | grep "unrecognized\|invalid\|error:\|warning" > /dev/null || echo $(ARG)
105
106LINKTEST = $(CC) -x c -o $(TMPFILE) $(ARG) - 2>&1 > /dev/null < /dev/null | grep "unrecognized\|invalid\|error:\|warning:" > /dev/null || echo $(ARG)
107
108#PROGLINKTEST = echo "int main() { return 0; }" | $(CC) -x c -o $(TMPFILE).o - && $(CC) -o $(TMPFILE) $(TMPFILE).o $(ARG) 2>&1 > /dev/null | grep "unrecognized\|invalid\|error:\|warning:" > /dev/null || echo $(ARG)
109
110#CCTEST = $(CC) -x c -c -o $(TMPFILE) $(ARG) - 2>&1 < /dev/null | tee "CCTEST-$(ARG)" | grep "unrecognized\|invalid\|error:" > /dev/null || echo $(ARG)
111# Test whether a particular string appears in the compiler's default environment;
112# set STR before running.
113DEFTEST = $(CC) -dM -E - < /dev/null 2> /dev/null | grep "$(STR)" > /dev/null
114
115ARG := -shared
116SHAREDLIBFLAGS_DEF := $(shell $(LINKTEST))
117SHAREDLIB_SUFFIX = so
118
119# Cygwin peculiarities:
120# --.dll filename suffix for shared libraries (created by python distutils)
121# -- -fPIC produces warnings
122
123UNAME = $(shell uname -s)
124ifneq (CYGWIN,$(findstring CYGWIN,$(UNAME)))
125  SHAREDLIBFLAGS_DEF += -fPIC
126endif
127
128# Get the library suffix used by python distutils (.dll on cygwin, .so elsewhere for py2; .PLATFORM.so for py3)
129PYTHON_SO_EXT ?= $(shell $(PYTHON) -c "from distutils import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX') or sysconfig.get_config_var('SO'))")
130
131# Set a default, otherwise terrible things happen:
132#   in util/Makefile : clean: rm -f *$(PYTHON_SO_EXT)
133ifeq ($(PYTHON_SO_EXT)x,x)
134  PYTHON_SO_EXT := .so
135endif
136
137# gcc 5.1 changes inline semantics
138#ARG := -std=gnu89
139#FLAGS_DEF += $(shell $(CCTEST))
140# Handled in keywords.h instead
141
142#ARG := -Wno-error=unused-command-line-argument-hard-error-in-future
143#FLAGS_DEF += $(shell $(CCTEST))
144
145ARG := -ffinite-math-only
146FLAGS_DEF += $(shell $(CCTEST))
147
148# clang: warning: argument unused during compilation: '-fno-signaling-nans'
149ARG := -fno-signaling-nans
150FLAGS_DEF += $(shell $(CCTEST))
151
152# gcc non-IEEE faster math
153#ARG := -ffast-math
154#FLAGS_DEF += $(shell $(CCTEST))
155
156# gcc 3.3 on Mac doesn't support -pthread
157# clang 4.1: warns about including -pthread
158ARG := -pthread
159FLAGS_DEF += $(shell $(CCTEST))
160
161# Avoid "undefined reference to `isfinite'" on gcc 4.7.0 (carver)
162#ARG := -std=c99
163#FLAGS_DEF += $(shell $(CCTEST))
164
165## Below, we try to guess good compiler flags for this CPU / architecture.
166## If we make an incorrect choice -- ie, the code fails in some way on the
167## machine on which it was compiled, please let us know by posting at
168##    astrometry.net/group
169## If you want to override this setting, you can set the
170##      ARCH_FLAGS
171## environment variable in your shell.
172## With gcc 4.2 and later, gcc should be able to make the optimal choice on its own.
173## See the README section "I wanna go fast!" for more details.
174ifneq ($(origin ARCH_FLAGS),undefined)
175  FLAGS_DEF += $(ARCH_FLAGS)
176else
177  # Try to guess some good compiler flags for this CPU.
178
179  # Use -march=native if it's available (gcc 4.2 and above)
180  ARG := -march=native
181  X := $(shell $(CCTEST))
182  ifneq ($(X),)
183    FLAGS_DEF += $(X)
184  else
185    # Try to guess -march
186    MACHINE:=$(shell uname -m)
187    ifeq ($(MACHINE), i686)
188      # gcc before version 3.1 doesn't support "pentium4"; use "i686" instead.
189
190      ARG := -march=pentium4
191      X := $(shell $(CCTEST))
192      ifneq ($(X),)
193        STR := \#define __tune_pentium4__ 1
194        FLAGS_DEF += $(shell $(DEFTEST) && echo "-march=pentium4" \
195                                        || echo "-march=i686")
196      else
197        ARG := -march=i686
198        FLAGS_DEF += $(shell $(CCTEST))
199      endif
200
201    else
202      # make 3.79 doesn't allow multiple "else" statements, so nest 'em.
203      ifeq ($(MACHINE), x86_64)
204        STR := \#define __tune_k8__ 1
205        FLAGS_DEF += $(shell $(DEFTEST) && echo "-march=k8")
206          FLAGS_DEF += -m64
207      else # ppc, ...
208        FLAGS_DEF += -DNOT_686
209
210      endif
211
212    endif
213  endif
214
215endif
216
217STR := __APPLE__
218X := $(shell $(DEFTEST) && echo "-DNOBOOL")
219
220ifneq ($(X),)
221  # Darwin does dynamic libs differently
222  ARG := -dynamic
223  X := $(shell $(LINKTEST))
224  SHAREDLIBFLAGS_DEF += $(X)
225
226  # clang 3.1 wants...
227  ARG := -dynamic -dynamiclib
228  X :+ $(shell $(LINKTEST))
229  SHAREDLIBFLAGS_DEF += $(X)
230
231  # clang 4.1 doesn't support -dynamiclib
232  ARG := -dynamiclib
233  X := $(shell $(LINKTEST))
234  SHAREDLIBFLAGS_DEF += $(X)
235
236  # clang 4.1 seems to need this instead:
237  ARG := -Wl,-dylib
238  X := $(shell $(LINKTEST))
239  SHAREDLIBFLAGS_DEF += $(X)
240
241  ARG := -pthread
242  X := $(shell $(LINKTEST))
243  SHAREDLIBFLAGS_DEF += $(X)
244
245endif
246
247# delete temp files that may have been generated by the above tests.
248X := $(shell rm -f $(TMPFILE))
249
250# FLAGS_DEF are gcc flags that are shared between compiling and
251# linking.  CFLAGS_DEF are compile flags, LDFLAGS_DEF are link flags.
252
253# Turn optimization on by default; this statement only sets OPTIMIZE
254# if it hasn't been set already (eg, in ../Makefile)
255OPTIMIZE ?= yes
256PROFILE ?= no
257ASSERT ?= -DNDEBUG
258
259ifeq ($(PROFILE),yes)
260  FLAGS_DEF += -O2
261  FLAGS_DEF += -pg -g
262  FLAGS_DEF += $(ASSERT)
263else
264
265ifeq ($(OPTIMIZE),yes)
266  # speedy!
267  FLAGS_DEF += -O3
268  FLAGS_DEF += -fomit-frame-pointer
269  # turn off asserts:
270  FLAGS_DEF += $(ASSERT)
271
272else
273  ifeq ($(OPTIMIZE),no)
274    # debuggy!
275    FLAGS_DEF += -O0
276    FLAGS_DEF += -g
277  endif
278
279endif
280
281endif
282
283ifneq (CYGWIN,$(findstring CYGWIN,$(UNAME)))
284FLAGS_DEF += -fpic
285endif
286
287# profily!
288#FLAGS_DEF += -pg
289
290## FIXME DEBUG
291#FLAGS_DEF += -fstrict-aliasing -std=c99
292#FLAGS_DEF += -Wstrict-aliasing
293# More strict aliasing warnings; possible false positives.
294#FLAGS_DEF += -Wstrict-aliasing=2
295
296# Put inlined function definitions in .o files.
297# FLAGS_DEF += -fkeep-inline-functions
298
299FLAGS_DEF += -Winline
300
301
302# If user set FLAGS, use those rather than FLAGS_DEF.
303ifneq ($(origin FLAGS),undefined)
304  FLAGS_DEF := $(FLAGS)
305endif
306
307# fold in the user's CFLAGS, if set...
308CFLAGS_DEF := $(CFLAGS) $(FLAGS_DEF)
309CFLAGS_DEF += -I$(INCLUDE_BASE_DIR)
310CFLAGS_DEF += -I$(INCLUDE_DIR)
311CFLAGS_DEF += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
312CFLAGS_DEF += -D_GNU_SOURCE
313
314#ARG := -pthread
315#CFLAGS_DEF += $(shell $(CCTEST))
316
317
318#CFLAGS_DEF += -Wextra
319#CFLAGS_DEF += -Wpointer-arith
320#CFLAGS_DEF += -fmudflap
321#LDFLAGS_DEF += -lmudflap
322
323# What functions were and weren't inlined?
324#CFLAGS_DEF += -Winline
325
326# Print header files that are included
327#CFLAGS_DEF += -H
328
329# fold in the user's LDFLAGS, if set...
330LDFLAGS_DEF := $(LDFLAGS) $(FLAGS_DEF)
331
332#ARG := -pthread
333#LDFLAGS_DEF += $(shell $(PROGLINKTEST))
334
335LDLIBS_DEF := $(LDLIBS)
336
337# Make's default link recipe is:
338#    $(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)
339# and some linkers demand that libraries appear *after* the object files,
340# so if you want a lib always linked in, add it to LDLIBS.
341
342# Provide for executable programs and FITS headers
343# GIT fields: revision, date and url via CFLAGS.
344# These fields replace the deprecated SVN fields.
345AN_GIT_REVISION := 0.85
346AN_GIT_DATE := Mon_Mar_22_11:27:41_2021_-0400
347AN_GIT_URL := https://github.com/dstndstn/astrometry.net
348
349CFLAGS_DEF += -DAN_GIT_REVISION='"$(AN_GIT_REVISION)"'
350CFLAGS_DEF += -DAN_GIT_DATE='"$(AN_GIT_DATE)"'
351CFLAGS_DEF += -DAN_GIT_URL='"$(AN_GIT_URL)"'
352
353