1# ===========================================================================
2#
3#                            PUBLIC DOMAIN NOTICE
4#               National Center for Biotechnology Information
5#
6#  This software/database is a "United States Government Work" under the
7#  terms of the United States Copyright Act.  It was written as part of
8#  the author's official duties as a United States Government employee and
9#  thus cannot be copyrighted.  This software/database is freely available
10#  to the public for use. The National Library of Medicine and the U.S.
11#  Government have not placed any restriction on its use or reproduction.
12#
13#  Although all reasonable efforts have been taken to ensure the accuracy
14#  and reliability of the software and data, the NLM and the U.S.
15#  Government do not and cannot warrant the performance or results that
16#  may be obtained by using this software or data. The NLM and the U.S.
17#  Government disclaim all warranties, express or implied, including
18#  warranties of performance, merchantability or fitness for any particular
19#  purpose.
20#
21#  Please cite the author in any work or product based on this material.
22#
23# ===========================================================================
24
25CONFIG_FILE = $(TOP)/build/Makefile.config
26ifeq (no, $(shell test -f $(CONFIG_FILE) && echo yes || echo no))
27    $(error "*** File '$(CONFIG_FILE)' is missing. Please run $(TOP)/configure")
28endif
29
30# determine OS
31UNAME = $(shell uname -s)
32
33ifeq (Darwin, $(UNAME))
34	HOST_OS = mac
35endif
36ifeq (Linux, $(UNAME))
37	HOST_OS = linux
38	OS_DISTRIBUTOR = $(shell lsb_release -si)
39	EXECMDF = $(TOP)/build/ld.linux.exe_cmd.sh
40	ifeq (no, $(shell test -f $(EXECMDF) && echo yes || echo no))
41        	$(error "*** File '$(EXECMDF)' is missing. Please run $(TOP)/configure")
42	endif
43endif
44ifeq (SunOS, $(UNAME))
45	HOST_OS = sun
46	ARCHITECTURES = x86_64 i386
47endif
48ifeq (xCYGWIN, $(findstring xCYGWIN,x$(UNAME)))
49	HOST_OS = win
50endif
51ifeq (xMINGW, $(findstring xMINGW,x$(UNAME)))
52	HOST_OS = win
53endif
54
55# assume build OS is the same as host OS
56OS = $(HOST_OS)
57BUILD_OS = $(OS)
58
59# determine ARCH
60ARCHITECTURES = default
61ifeq (mac,$(HOST_OS))
62	HOST_ARCH = $(shell $(TOP)/build/mac.arch.sh)
63	OS_ARCH = $(shell perl $(TOP)/setup/os-arch.perl)
64	CONFIG_FILE_OA = $(TOP)/build/Makefile.config.$(OS_ARCH)
65	ifeq (no, $(shell test -f $(CONFIG_FILE_OA) && echo yes || echo no))
66    	$(error "*** File '$(CONFIG_FILE_OA)' is missing. Please run $(TOP)/configure")
67	endif
68	ifeq (no, $(shell grep CONFIGURE_FOUND_XML2 $(CONFIG_FILE_OA) && echo yes || echo no))
69    	$(error "*** 'CONFIGURE_FOUND_XML2' is missing in $(CONFIG_FILE_OA). Please run $(TOP)/configure")
70	endif
71else
72	MARCH = $(shell uname -m)
73
74	ifeq (i386, $(MARCH))
75		HOST_ARCH = i386
76	endif
77	ifeq (i486, $(MARCH))
78		HOST_ARCH = i386
79	endif
80	ifeq (i586, $(MARCH))
81		HOST_ARCH = i386
82	endif
83	ifeq (i686, $(MARCH))
84		ifeq (WOW64x, $(findstring WOW64x,$(UNAME)x))
85			# 64-bit capable Cygwin. Analyze the version of cl to set the corect architecture
86			CL = $(shell cl.exe 2>&1 >/dev/null)
87			ifeq (for x64, $(findstring for x64, $(CL)))
88				HOST_ARCH = x86_64
89			else
90				HOST_ARCH = i386
91			endif
92		else
93			HOST_ARCH = i386
94		endif
95	endif
96	ifeq (x86_64, $(MARCH))
97		HOST_ARCH = x86_64
98	endif
99	ifeq (i86pc, $(MARCH))
100		HOST_ARCH = x86_64
101		ARCHITECTURES = x86_64 i386
102	endif
103	ifeq (sun4v,$(MARCH))
104		HOST_ARCH = sparc64
105		ARCHITECTURES = sparc64 sparc32
106	endif
107endif
108
109ARCH = $(HOST_ARCH)
110REMOTE_ARCH = $(ARCH)
111
112# pick up dependencies from object directory
113ifdef SRCDIR
114	include $(wildcard *.d)
115endif
116
117# determine SRCDIR
118ifdef MODULE
119    override SRCDIR=$(TOP)/$(MODULE)
120else
121    SRCDIR=$(TOP)
122endif
123
124# set COMP, LNKG and BUILD
125COMP = $(shell test -f $(TOP)/build/COMP && mv $(TOP)/build/COMP $(TOP)/build/COMP.$(OS); test -f $(TOP)/build/COMP.$(OS) && cat $(TOP)/build/COMP.$(OS) || echo gcc)
126LNKG = $(shell test -f $(TOP)/build/STATIC && mv $(TOP)/build/STATIC $(TOP)/build/LNKG.$(OS) && echo stat > $(TOP)/build/LNKG.$(OS); test -f $(TOP)/build/LNKG.$(OS) && cat $(TOP)/build/LNKG.$(OS) || echo stat)
127BUILD = $(shell test -f $(TOP)/build/BUILD && mv $(TOP)/build/BUILD $(TOP)/build/BUILD.$(OS); test -f $(TOP)/build/BUILD.$(OS) && cat $(TOP)/build/BUILD.$(OS) || echo dbg)
128TOOLSET := $(COMP)
129
130ifdef USE_GCC_IF_ICC
131    ifeq (icc,$(COMP))
132        COMP = gcc
133    endif
134    ifeq (clang,$(COMP))
135        COMP = gcc
136    endif
137endif
138
139RHOSTS = $(shell (test -d $(TOP)/rhosts && test -n "$$(ls $(TOP)/rhosts/)") && \
140                  ls $(TOP)/rhosts/ | xargs -n1 basename | grep -v CVS | grep -v example | grep -v "~")
141
142# detect RHOST
143HAS_RHOST = $(shell test -f $(TOP)/build/RHOST.$(HOST_OS) && echo yes || echo no)
144ifeq (yes,$(HAS_RHOST))
145    include $(TOP)/build/RHOST.$(HOST_OS)
146	ifeq (,$(RPORT))
147		RPORT = 20000
148	endif
149	BUILD_OS = r$(OS)
150	REMOTE_ARCH = $(ARCH)
151	ifeq (,$(LHOME))
152	    LHOME=$(HOME)
153	endif
154endif
155
156# set OUTDIR
157ifndef OUTDIR
158	OUTDIR = $(shell test -f $(TOP)/build/OUTDIR && mv $(TOP)/build/OUTDIR $(TOP)/build/OUTDIR.$(BUILD_OS); test -f $(TOP)/build/OUTDIR.$(BUILD_OS) && cat $(TOP)/build/OUTDIR.$(BUILD_OS) || echo $(TOP))
159	ifeq (,$(OUTDIR))
160		OUTDIR = $(TOP)
161	endif
162endif
163ifeq (,$(ROUTDIR))
164	ROUTDIR = $(RHOME)
165endif
166
167ifeq (yes,$(HAS_RHOST))
168	# set remote flags for calling win-cc.sh and ld.sh)
169	RFLAGS=--rhome "$(RHOME)" --lhome "$(LHOME)" --rhost "$(RHOST)" --rport $(RPORT) --proxy_tool "$(PROXY_TOOL)" \
170 --loutdir "$(OUTDIR)" --routdir "$(ROUTDIR)"
171	# RWORKDIR can be redefined by individual makefiles as needed
172	RWORKDIR = .
173	RUN_REMOTELY = $(TOP)/build/run_remotely.sh $(PROXY_TOOL) $(RHOST) $(RPORT) $(RHOME) $(LHOME) $(RWORKDIR) $(ROUTDIR) $(OUTDIR)
174endif
175
176# determine BITS
177ifeq (x86_64, $(ARCH))
178	BITS = 64
179endif
180ifeq (sparc64, $(ARCH))
181	BITS = 64
182endif
183ifeq (i386, $(ARCH))
184	BITS = 32
185endif
186ifeq (sparc32, $(ARCH))
187	BITS = 32
188endif
189
190