Debian Codegraph @

jmake.sh

raw
1 #!/bin/sh -ex
2 # NOTE: Jove does not use autotools/configure. This is
3 # a minimal convenience wrapper that crudely auto-detects the OS on
4 # a few of the most common modern (2020+) open-source
5 # operating systems by using uname (which can be overridden for
6 # testing or cross-build). It sets appropriate variables
7 # (CC, SYSDEFS, OPTFLAGS, LDLIBS, LDFLAGS) for make.
8 # All command-line arguments given to jmake.sh are
9 # passed directly onward to make.
10 # For distro maintainers or sysadmins with complex or multi-target
11 # build environments, or those who just prefer full control of config,
12 # just ignore this script, invoke make directly with
13 # the flags you want (see last line for examples.
14 # JMAKE_RELATIVE=1 to set SHAREDIR=doc LIBDIR= for a portable
15 # install (can copy around a directory with the jove, recover and portsrv
16 # executables and a doc subdirectory with cmds.txt, teach-jove, jove.rc)
17 # JMAKE_UNAME=i686-w64-mingw32 sets up a cross-compile for Win32
18
19 u=${JMAKE_UNAME-`uname | tr -d -c '[a-zA-Z0-9_]'`}
20 defcc=${CC-cc}
21 sysdefs="-D$u" # see sysdep.h for symbols to define for porting Jove to various systems
22 # most modern compilers are gcc-compatible (even if called cc)
23 optflags=${OPTFLAGS-${CFLAGS-"-g -Os -Wall -Werror -pedantic"}}
24 ldlibs=
25 ldflags= # special link flags, usually none needed
26 extra= # older UN*X (e.g Solaris, SunOS, etc, might need these)
27 rel=
28 locc=${LOCALCC-$defcc}
29
30 case "$u" in
31 *mingw*) # presumably set via something like JMAKE_UNAME=i686-w64-mingw32
32 : ${JMAKE_RELATIVE=1}
33 defcc="$u-gcc"
34 sysdefs="-DMINGW"
35 case "$u" in
36 *x86_64*) optflags="$optflags -Wno-long-long" # Win64 needs long long, and older gcc produce a C90 complaint;;
37 esac
38 extra="LOCALCC=$locc XEXT=.exe WINDRES=$u-windres EXTRAOBJS=win32.o ICON=jjove.coff"
39 ldlibs="-static -static-libgcc -lcomdlg32 -lssp_nonshared"
40 ;;
41 *-linux-musl*) # presumably set via something like JMAKE_UNAME=i486-alpine-linux-musl or JMAKE_UNAME=$(gcc -dumpmachine)
42 : ${JMAKE_RELATIVE=1}
43 defcc="$u-gcc"
44 sysdefs="-DLinux -DJTC"
45 optflags="$optflags -static"
46 extra="LOCALCC=$locc" # for setmaps
47 ;;
48 CYGWIN*)
49 sysdefs="-DCYGWIN"
50 ;;
51 *BSD|DragonFly|Darwin)
52 # openpty on *BSD requires libutil
53 ldlibs="-ltermcap -lutil"
54 optflags="$optflags"
55 ;;
56 SunOS) for dx in /usr/bin /usr/sfw/bin; do
57 if test -e $dx/gcc; then
58 defcc=$dx/gcc
59 break
60 fi
61 done
62 case "${CC-$defcc}" in
63 *gcc|*clang) ;;
64 *) optflags=-O;; # generally not gcc, perhaps Sunpro or classic Unix cc
65 esac
66 ldlibs="-ltermcap"
67 extra="$extra NROFF=nroff TROFF=troff"
68 xi=/usr/gnu/bin/install
69 if test ! -x $xi; then
70 xi=cp
71 fi
72 extra="$extra XINSTALL=$xi TINSTALL=$xi"
73 ;;
74 GNU|Linux)
75 if dpkg-buildflags > /dev/null 2>&1; then
76 sysdefs="$sysdefs `dpkg-buildflags --get CPPFLAGS`"
77 optflags="$optflags `dpkg-buildflags --get CFLAGS`"
78 ldflags="$ldflags `dpkg-buildflags --get LDFLAGS`"
79 fi
80 jtc=y
81 # see if we can find ncurses installed via pkgconf or pkg-config
82 # generally results in no cflags, but some libs
83 for pkc in pkgconf pkg-config; do
84 if $pkc --version > /dev/null 2>&1; then
85 if $pkc ncurses > /dev/null 2>&1; then
86 optflags="$optflags `$pkc --cflags ncurses`"
87 ldlibs="$ldlibs `$pkc --libs ncurses`"
88 jtc=n
89 fi
90 break
91 fi
92 done
93 if test x$jtc = xy -a -e /etc/gentoo-release; then
94 ldlibs="$ldlibs -ltinfo"
95 jtc=n
96 fi
97 # if no ncurses, use built-in VT1xx code
98 case "$jtc" in y) sysdefs="$sysdefs -DJTC";; esac
99 # best to use openpty on Linux, so need libutil
100 ldlibs="$ldlibs -lutil"
101 ;;
102 *) # for unknown platforms, we try fairly generic, builtin vt1xx
103 sysdefs="-DBSDPOSIX -DJTC"; optflags="-O"
104 ;;
105 esac
106 case "${JMAKE_RELATIVE-}" in
107 y*|1|t*)
108 # Use relative paths for share and bin, useful for mingw or personal
109 rel="DESTDIR=${DESTDIR-/none/} JOVEHOME= JBINDIR= JSHAREDIR=doc JLIBDIR="
110 ;;
111 esac
112
113 exec make ${JMAKE_OPTS-} CC="${CC-$defcc}" LOCALCC="$locc" SYSDEFS="$sysdefs" OPTFLAGS="$optflags" LDLIBS="$ldlibs" LDFLAGS="$ldflags" $rel $extra "$@"