Permalink
Browse files

A release tarball built on Linux now compiles on OS X (#127)

- modify detect_readline for Mac OS in configure
- pull stuff out of Python-2.7.13/pyconfig.h and into OSH configure
- more robust readline check
- add --readline flag to configure
  • Loading branch information...
aykamko authored and andychu committed Jun 1, 2018
1 parent 3d83b92 commit ed0b03b20c8f200dcfcaa57b7e9435afdca249aa
Showing with 100 additions and 54 deletions.
  1. +15 −1 Makefile
  2. +0 −30 Python-2.7.13/pyconfig.h
  3. +18 −16 build/compile.sh
  4. +9 −1 build/detect-readline.c
  5. +58 −6 configure
View
@@ -83,6 +83,8 @@ COMPILE_SH := build/compile.sh
#BYTECODE_ZIP := bytecode-cpython.zip
BYTECODE_ZIP := bytecode-opy.zip
HAVE_DSYMUTIL := $(shell command -v dsymutil 2>/dev/null)
# For faster tesing of builds
#default: _bin/oil.ovm-dbg
@@ -133,10 +135,20 @@ _build/%/ovm-opt: _build/%/module_init.c _build/%/main_name.c \
_build/%/c-module-srcs.txt $(COMPILE_SH)
$(COMPILE_SH) build-opt $@ $(filter-out $(COMPILE_SH),$^)
ifdef HAVE_DSYMUTIL
# NOTE: Debug symbols work a bit different on Mac OS
# NOTE: https://stackoverflow.com/a/33307778
_build/%/ovm-opt.stripped: _build/%/ovm-opt
strip -o $@ -S _build/$*/ovm-opt
dsymutil $@ -o _build/$*/$@.dSYM
else
# NOTE: This gets run on the end user's machine! It requires binutils for now?
# NOTE: objcopy fails if the linked files does not exist!
_build/%/ovm-opt.stripped: _build/%/ovm-opt _build/%/ovm-opt.symbols
#strip -o $@ --strip-debug $^
#strip -o $@ --strip-debug $^
strip -o $@ _build/$*/ovm-opt # What's the difference with debug symbols?
# We need a relative path since it will be _bin/oil.ovm
objcopy --add-gnu-debuglink=_build/$*/ovm-opt.symbols $@
@@ -146,6 +158,8 @@ _build/%/ovm-opt.stripped: _build/%/ovm-opt _build/%/ovm-opt.symbols
_build/%/ovm-opt.symbols: _build/%/ovm-opt
objcopy --only-keep-debug $^ $@
endif
# Fast build, with symbols for debugging.
_build/%/ovm-dbg: _build/%/module_init.c _build/%/main_name.c \
_build/%/c-module-srcs.txt $(COMPILE_SH)
View
@@ -226,9 +226,6 @@
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have the 'fdatasync' function. */
#define HAVE_FDATASYNC 1
/* Define to 1 if you have the `finite' function. */
#define HAVE_FINITE 1
@@ -341,12 +338,6 @@
/* Define to 1 if you have the `getpwent' function. */
#define HAVE_GETPWENT 1
/* Define to 1 if you have the `getresgid' function. */
#define HAVE_GETRESGID 1
/* Define to 1 if you have the `getresuid' function. */
#define HAVE_GETRESUID 1
/* Define to 1 if you have the `getsid' function. */
#define HAVE_GETSID 1
@@ -440,9 +431,6 @@
/* Define to 1 if you have the `resolv' library (-lresolv). */
/* #undef HAVE_LIBRESOLV */
/* Define to 1 if you have the <libutil.h> header file. */
/* #undef HAVE_LIBUTIL_H */
/* Define if you have the 'link' function. */
#define HAVE_LINK 1
@@ -524,9 +512,6 @@
/* Define if you have GNU PTH threads. */
/* #undef HAVE_PTH */
/* Define to 1 if you have the <pty.h> header file. */
#define HAVE_PTY_H 1
/* Define to 1 if you have the `putenv' function. */
#define HAVE_PUTENV 1
@@ -605,12 +590,6 @@
/* Define to 1 if you have the `setregid' function. */
#define HAVE_SETREGID 1
/* Define to 1 if you have the `setresgid' function. */
#define HAVE_SETRESGID 1
/* Define to 1 if you have the `setresuid' function. */
#define HAVE_SETRESUID 1
/* Define to 1 if you have the `setreuid' function. */
#define HAVE_SETREUID 1
@@ -659,12 +638,6 @@
/* Define to 1 if you have the `statvfs' function. */
#define HAVE_STATVFS 1
/* Define if you have struct stat.st_mtim.tv_nsec */
#define HAVE_STAT_TV_NSEC 1
/* Define if you have struct stat.st_mtimensec */
/* #undef HAVE_STAT_TV_NSEC2 */
/* Define if your compiler supports variable length function prototypes (e.g.
void fprintf(FILE *, char *, ...);) *and* <stdarg.h> */
#define HAVE_STDARG_PROTOTYPES 1
@@ -861,9 +834,6 @@
Include/unicodeobject.h). */
/* #undef HAVE_USABLE_WCHAR_T */
/* Define to 1 if you have the <util.h> header file. */
/* #undef HAVE_UTIL_H */
/* Define to 1 if you have the `utimes' function. */
#define HAVE_UTIMES 1
View
@@ -96,12 +96,12 @@ Modules/gcmodule.c
# 'configure' output.
MODOBJS='
Modules/posixmodule.c
Modules/errnomodule.c
Modules/errnomodule.c
Modules/pwdmodule.c
Modules/_sre.c
Modules/_codecsmodule.c
Modules/_sre.c
Modules/_codecsmodule.c
Modules/_weakref.c
Modules/zipimport.c
Modules/zipimport.c
Modules/signalmodule.c
'
@@ -111,7 +111,7 @@ OVM_LIBRARY_OBJS="
Modules/getbuildinfo.c
Parser/myreadline.c
$OBJECT_OBJS
$OVM_PYTHON_OBJS
$OVM_PYTHON_OBJS
$MODULE_OBJS
$MODOBJS
"
@@ -171,22 +171,24 @@ build() {
pushd $PY27
local compile_readline
local link_readline
if test "$HAVE_READLINE" = 1; then
local -a readline_flags
if [[ "$HAVE_READLINE" -eq 1 ]]; then
# Readline interface for tokenizer.c and [raw_]input() in bltinmodule.c.
# For now, we are using raw_input() for the REPL. TODO: Parameterize this!
# We should create a special no_readline_raw_input().
c_module_src_list=$(cat $abs_c_module_srcs)
if [[ -n "$READLINE_DIR" ]]; then
readline_flags+=(-L "$READLINE_DIR/lib" -I "$READLINE_DIR/include")
fi
# NOTE: pyconfig.h has HAVE_LIBREADLINE but doesn't appear to use it?
compile_readline='-D HAVE_READLINE'
link_readline='-l readline'
readline_flags+=(-l readline -D HAVE_READLINE)
else
# don't fail
c_module_src_list=$(grep -v '/readline.c' $abs_c_module_srcs || true)
compile_readline=''
link_readline=''
readline_flags=()
fi
# $PREFIX comes from ./configure and defaults to /usr/local.
@@ -206,9 +208,8 @@ build() {
$abs_main_name \
$c_module_src_list \
Modules/ovm.c \
$compile_readline \
-l m \
$link_readline \
"${readline_flags[@]}" \
"$@" \
|| true
popd
@@ -262,14 +263,15 @@ _headers() {
local c_module_srcs=${1:-_tmp/hello/c-module-srcs.txt}
local abs_c_module_srcs=$PWD/$c_module_srcs
# -MM: no system headers
cd $PY27
# -MM: no system headers
gcc \
"${INCLUDE_PATHS[@]}" \
"${PREPROC_FLAGS[@]}" \
-MM $OVM_LIBRARY_OBJS \
Modules/ovm.c \
$(cat $abs_c_module_srcs)
$(cat $abs_c_module_srcs)
}
# NOTE: 91 headers in Include, but only 81 referenced here. So it's worth it.
View
@@ -4,8 +4,16 @@
#include <readline/readline.h>
#include <readline/history.h>
static int test_event_hook(void) {
return 0;
}
int main(void) {
char *line = readline("");
/* Ensure readline version is recent enough.
This line will break the build otherwise: https://git.io/vhZ3B */
rl_event_hook = test_event_hook;
return 0;
}
View
@@ -34,6 +34,7 @@ Detects system settings before a build of Oil.
--with-readline Fail unless readline is available.
--without-readline Don't compile with readline, even if it's available.
The shell won't have any interactive features.
--readline An alternative readline installation to link against
EOF
}
@@ -43,6 +44,7 @@ EOF
FLAG_prefix='/usr/local'
FLAG_with_readline='' # Fail if it's not available.
FLAG_without_readline='' # Don't even check if it's available>
FLAG_readline=''
while true; do
case "$1" in
@@ -63,6 +65,17 @@ while true; do
FLAG_without_readline=1
;;
--readline=*)
FLAG_readline=$(expr "$1" : '--readline=\(.*\)')
;;
--readline)
if test $# -eq 1; then
die "--readline requires an argument"
fi
shift
FLAG_readline=$1
;;
# TODO: Maybe prefix only needs to be part of the install step? I'm not
# sure if we need it for building anything.
--prefix=*)
@@ -100,8 +113,10 @@ cc_or_die() {
cc_statement() {
local pp_var="$1"
local prog="$2"
local includes="$3"
cat >$TMP/cc_statement.c <<EOF
$includes
int main() {
$prog
}
@@ -115,16 +130,39 @@ EOF
fi
}
# Check if a given library is installed via compilation
cc_header_file() {
local pp_var="$1"
local c_lib="$2"
cc_statement "$pp_var" 'return 0;' "#include <$c_lib>"
}
# Write a shell script to standard out with variables, or fail.
detect_readline() {
if cc_quiet build/detect-readline.c -l readline; then
echo 'HAVE_READLINE=1'
if test -n "$FLAG_readline"; then
if cc_quiet build/detect-readline.c \
-L "$FLAG_readline/lib" \
-I "$FLAG_readline/include" \
-l readline; then
echo "READLINE_DIR=$FLAG_readline"
echo 'HAVE_READLINE=1'
return 0
fi
else
if test "$FLAG_with_readline" = 1; then
die 'readline was not detected on the system (--with-readline passed).'
if cc_quiet build/detect-readline.c -l readline; then
echo "READLINE_DIR="
echo 'HAVE_READLINE=1'
return 0
fi
echo 'HAVE_READLINE='
fi
if test "$FLAG_with_readline" = 1; then
die 'readline was not detected on the system (--with-readline passed).'
fi
echo 'READLINE_DIR='
echo 'HAVE_READLINE='
return 1
}
detect_and_echo_vars() {
@@ -147,7 +185,7 @@ int main() {
printf("%lu", $c_expr);
}
EOF
cc_or_die -o $TMP/print_expr $TMP/print_expr.c
cc_or_die -o $TMP/print_expr $TMP/print_expr.c
$TMP/print_expr > $TMP/print_expr.out
}
@@ -242,6 +280,20 @@ EOF
else
echo '#define VA_LIST_IS_ARRAY 1'
fi
# TODO: are these feature checks really necessary, or can we
# strip these out of posixmodule.c entirely?
cc_header_file HAVE_PTY_H 'pty.h'
cc_header_file HAVE_LIBUTIL_H 'libutil.h'
cc_header_file HAVE_UTIL_H 'util.h'
# TODO: are these feature checks really necessary?
cc_statement HAVE_STAT_TV_NSEC \
'struct stat st; st.st_mtim.tv_nsec = 1; return 0;' \
'#include <sys/stat.h>'
cc_statement HAVE_STAT_TV_NSEC2 \
'struct stat st; st.st_mtimespec.tv_nsec = 1; return 0;' \
'#include <sys/stat.h>'
}
# Another way of working: set detected-config.mk ?

0 comments on commit ed0b03b

Please sign in to comment.