Skip to content

Commit 5f98706

Browse files
davidchisnallquark17
authored andcommitted
Enable building on FreeBSD
Move the computation of the TCL_INC_FLAGS and TCL_LIB_FLAGS from two places in the build to one place, in the top-level platform script. Expand that computation to include more cases. The existing build system conflated 'has BSD tools' vs 'has GNU tools', 'is ELF' vs 'is Mach-O', and 'is Linux' vs 'is Darwin'. I have not tried to clean up that conflation, only to add the missing case. Includes reviewer feedback.
1 parent 07f9b66 commit 5f98706

File tree

15 files changed

+176
-69
lines changed

15 files changed

+176
-69
lines changed

Makefile renamed to GNUmakefile

File renamed without changes.

platform.mk

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ endif
2929
OSTYPE = $(shell $(TOP)/platform.sh ostype)
3030
export OSTYPE
3131

32-
ifneq ($(OSTYPE), $(findstring $(OSTYPE), Linux Darwin))
32+
ifneq ($(OSTYPE), $(findstring $(OSTYPE), Linux Darwin Freebsd))
3333
$(error OSTYPE environment not recognized: $(OSTYPE))
3434
endif
3535

@@ -56,3 +56,26 @@ export CFLAGS
5656
export CXXFLAGS
5757

5858
## --------------------
59+
## Set up the TCL shell and include paths
60+
61+
ifneq ($(WANT_TCL),)
62+
63+
TCLSH = $(shell $(TOP)/platform.sh tclsh)
64+
ifeq ($(TCLSH), )
65+
$(error Unable to find tclsh)
66+
endif
67+
$(info Using tclsh: $(TCLSH))
68+
69+
TCL_INC_FLAGS = $(shell $(TOP)/platform.sh tclinc 2> /dev/null || echo fail)
70+
ifeq ($(TCL_INC_FLAGS), fail)
71+
$(error Unable to find tcl include directory)
72+
endif
73+
$(info Using tcl include flags: $(TCL_INC_FLAGS))
74+
75+
TCL_LIB_FLAGS = $(shell $(TOP)/platform.sh tcllibs 2> /dev/null || echo fail)
76+
ifeq ($(TCL_LIB_FLAGS), fail)
77+
$(error Unable to find tcl library flags)
78+
endif
79+
$(info Using tcl library flags: $(TCL_LIB_FLAGS))
80+
81+
endif

platform.sh

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
set -u
4+
35
usage()
46
{
57
echo "Usage: $0 <option>"
@@ -8,6 +10,9 @@ usage()
810
echo "Valid options are:"
911
echo " ostype "
1012
echo " machtype "
13+
echo " tclsh "
14+
echo " tclinc "
15+
echo " tcllibs "
1116
echo " c++_shared_flags"
1217
}
1318

@@ -19,11 +24,8 @@ fi
1924
## =========================
2025
## OSTYPE
2126

22-
if [ -z "${OSTYPE}" ] ; then
23-
OSTYPE=`uname -s`
24-
fi
2527
## Account for values like "linux-gnu" by removing extra fields
26-
OSTYPE=$(echo ${OSTYPE} | cut -d'-' -f1)
28+
OSTYPE=$(echo ${OSTYPE:=$(uname -s)} | cut -d'-' -f1)
2729
## Account for values like "Darwin10.0" by removing the version number
2830
OSTYPE=$(echo ${OSTYPE} | egrep -o "^[A-Za-z]+")
2931
## Account for lowercase values like "linux" when we want "Linux"
@@ -37,12 +39,15 @@ fi
3739
## =========================
3840
## MACHTYPE
3941

40-
if [ -z "${MACHTYPE}" ] ; then
41-
MACHTYPE=`uname -m`
42-
fi
4342
## Account for values like "x86_64-pc-linux-gnu" when all we want is
4443
## "x86_64", "i386", etc
45-
MACHTYPE=$(echo ${MACHTYPE} | cut -d'-' -f1)
44+
MACHTYPE=$(echo ${MACHTYPE:=$(uname -m)} | cut -d'-' -f1)
45+
46+
# If we see a BSD-style amd64 instead of x86_64, rewrite it to the more generic
47+
# version.
48+
if [ ${MACHTYPE} = "amd64" ] ; then
49+
MACHTYPE=x86_64
50+
fi
4651

4752
if [ "$1" = "machtype" ] ; then
4853
echo ${MACHTYPE}
@@ -63,6 +68,105 @@ if [ "$1" = "c++_shared_flags" ] ; then
6368
fi
6469

6570
## =========================
71+
## Find the TCL shell command
72+
73+
if [ ${OSTYPE} = "Darwin" ] ; then
74+
# Have Makefile avoid Homebrew's install of tcl on Mac
75+
TCLSH=/usr/bin/tclsh
76+
else
77+
TCLSH=`which tclsh`
78+
fi
79+
80+
if [ "$1" = "tclsh" ] ; then
81+
echo ${TCLSH}
82+
exit 0
83+
fi
84+
85+
PKG_CONFIG=`which pkg-config`
86+
if [ -z "${PKG_CONFIG}" ] ; then
87+
PKG_CONFIG='false'
88+
fi
89+
90+
TCL_SUFFIX=$(echo 'catch { puts [info tclversion]; exit 0}; exit 1' | ${TCLSH})
91+
TCL_ALT_SUFFIX=$(echo ${TCL_SUFFIX} | sed 's/\.//')
92+
93+
if [ "$1" = "tclinc" ] ; then
94+
# Avoid Homebrew's install of Tcl on Mac
95+
if [ ${OSTYPE} = "Darwin" ] ; then
96+
# no flags needed
97+
exit 0
98+
fi
99+
100+
# Try pkg-config
101+
TCL_INC_FLAGS=$(${PKG_CONFIG} --silence-errors --cflags-only-I tcl${TCL_SUFFIX})
102+
# If pkg-config didn't work with the first prefix, try the alternative version.
103+
# For example, on FreeBSD, the tcl87 package installs tclsh8.7, but tcl87.pc
104+
if [ $? -ne 0 ] ; then
105+
TCL_INC_FLAGS=$(${PKG_CONFIG} --silence-errors --cflags-only-I tcl${TCL_ALT_SUFFIX})
106+
fi
107+
# If pkg-config doesn't work, try some well-known locations
108+
if [ $? -ne 0 ] ; then
109+
if [ -f "/usr/local/include/tcl${TCL_SUFFIX}/tcl.h" ] ; then
110+
TCL_INC_FLAGS="-I/usr/local/include/tcl${TCL_SUFFIX}"
111+
elif [ -f "/usr/include/tcl${TCL_SUFFIX}/tcl.h" ] ; then
112+
TCL_INC_FLAGS="-I/usr/include/tcl${TCL_SUFFIX}"
113+
else
114+
exit 1
115+
fi
116+
fi
117+
echo ${TCL_INC_FLAGS}
118+
exit 0
119+
fi
120+
121+
if [ "${OSTYPE}" = "Darwin" ] ; then
122+
LIB_SUFFIX=dylib
123+
else
124+
LIB_SUFFIX=so
125+
fi
126+
127+
if [ "$1" = "tcllibs" ] ; then
128+
TCL_VER=`echo 'catch { puts [info tclversion]; exit 0}; exit 1' | ${TCLSH}`
129+
130+
# Avoid Homebrew's install of Tcl on Mac
131+
if [ ${OSTYPE} = "Darwin" ] ; then
132+
echo -ltcl$(TCL_VER)
133+
exit 0
134+
fi
135+
136+
# Try pkg-config
137+
TCL_LIB_FLAGS=`${PKG_CONFIG} --silence-errors --libs tcl${TCL_SUFFIX}`
138+
# If pkg-config didn't work with the first prefix, try the alternative version.
139+
# For example, on FreeBSD, the tcl87 package installs tclsh8.7, but tcl87.pc
140+
if [ $? -ne 0 ] ; then
141+
TCL_LIB_FLAGS=`${PKG_CONFIG} --silence-errors --libs tcl${TCL_ALT_SUFFIX}`
142+
fi
143+
144+
if [ $? -eq 0 ] ; then
145+
echo ${TCL_LIB_FLAGS}
146+
exit 0
147+
fi
148+
149+
# If pkg-config doesn't work, try some well-known locations
150+
for L in /usr/lib /usr/local/lib ; do
151+
for V in ${TCL_VER} ${TCL_SUFFIX} ${TCL_ALT_SUFFIX} ; do
152+
if [ -f "${L}/libtcl${V}.${LIB_SUFFIX}" ] ; then
153+
echo -L${L} -ltcl${V}
154+
exit 0
155+
fi
156+
done
157+
done
158+
# If we're Linux, look for multiarch things
159+
if [ "${OSTYPE}" = "Linux" ] ; then
160+
for V in ${TCL_VER} ${TCL_SUFFIX} ${TCL_ALT_SUFFIX} ; do
161+
if [ -f "/usr/lib/${MACHTYPE}-linux-gnu/libtcl${V}.${LIB_SUFFIX}" ] ; then
162+
echo -ltcl${V}
163+
exit 0
164+
fi
165+
done
166+
fi
167+
exit 1
168+
fi
169+
66170

67171
usage
68172
exit 1

src/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ PREFIX?=$(TOP)/inst
88
ifndef NO_DEPS_CHECKS
99
CC_TOOLS=$(CC) $(CXX) $(LD)
1010
BSC_TOOLS=ghc ghc-pkg
11-
BLUETCL_TOOLS=tclsh
1211
YICES_TOOLS=gperf autoconf
1312
STP_TOOLS=flex bison
1413

1514
TOOLS=$(CC_TOOLS) \
1615
$(BSC_TOOLS) \
17-
$(BLUETCL_TOOLS) \
1816
$(YICES_TOOLS) \
1917
$(STP_TOOLS) \
2018

src/bluesim/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ HEADERS = bluesim_kernel_api.h \
3737
bs_model.h
3838

3939
# These ld export maps get copies to the inst/lib/Bluesim area
40-
LINKFILES = bs_linux_export_map.txt \
41-
bs_darwin_export_map.txt
40+
LINKFILES = bs_elf_export_map.txt \
41+
bs_mach-o_export_map.txt
4242

4343
# -------------------------
4444

src/bluetcl/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ TOP:=$(PWD)/../..
44
PREFIX?=$(TOP)/inst
55
INSTALLDIR = $(PREFIX)/lib/tcllib/bluespec
66

7+
TCLSH = $(shell $(TOP)/platform.sh tclsh)
8+
79
FILES = \
810
tclIndex \
911
pkgIndex.tcl \
@@ -26,10 +28,8 @@ EXEFILES = \
2628
.PHONY: all
2729
all: tclIndex
2830

29-
# pkg_mkIndex.tcl is produced here
30-
.PHONY: tclIndex
3131
tclIndex: *.tcl
32-
./tclIndex.sh "$(TCLFILES)" "$(PACKAGES)"
32+
${TCLSH} ./tclIndex.tcl "$(TCLFILES)" "$(PACKAGES)"
3333

3434
.PHONY: install
3535
install: tclIndex

src/bluetcl/tclIndex.sh renamed to src/bluetcl/tclIndex.tcl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#!/bin/sh
2-
3-
#\
4-
exec tclsh "$0" "$@"
5-
61
set tclFiles [lindex $argv 0]
72
set packFiles [lindex $argv 1]
83

src/comp/Makefile

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
PWD:=$(shell pwd)
2-
TOP:=$(PWD)/../..
1+
TOP:=$(shell pwd)/../..
2+
WANT_TCL=yes
33

44
include $(TOP)/platform.mk
55

@@ -60,27 +60,6 @@ HTCL_HS = ../vendor/htcl
6060
HTCL_INC_FLAGS = -L$(HTCL_HS)
6161
HTCL_LIB_FLAGS = -lhtcl
6262

63-
# TCL version
64-
ifeq ($(OSTYPE), Darwin)
65-
# Have Makefile avoid Homebrew's install of tcl on Mac
66-
TCLSH=/usr/bin/tclsh
67-
else
68-
TCLSH=tclsh
69-
endif
70-
TCL_VER = $(shell echo 'catch { puts [info tclversion]; exit 0}; exit 1' | $(TCLSH) || echo fail)
71-
ifeq ($(TCL_VER),fail)
72-
$(error TCL version check failed)
73-
endif
74-
75-
# TCL include flags
76-
# Have Makefile avoid Homebrew's install of tcl on Mac
77-
ifneq ($(OSTYPE), Darwin)
78-
TCL_INC_FLAGS = $(shell pkg-config --silence-errors --cflags-only-I tcl || echo -I/usr/include/tcl)
79-
endif
80-
81-
# TCL library flags
82-
TCL_LIB_FLAGS = -ltcl$(TCL_VER)
83-
8463
# -----
8564
# GHC
8665

0 commit comments

Comments
 (0)