From afabce40f10bf99a9a916ea268aca63e6c7dbca2 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Wed, 14 Oct 2015 09:31:20 +0000 Subject: [PATCH] build: improve portability - detect X11 configuration in configure script, no longer assume directories in Makefile - added CONFIG_XSHM and check for XShm availability - added TARGET_OS and TARGET_ARCH to make specific object dirs - no longer redefine qe_module_init in qe.c - added tqe.c: combined source version of tiny version - added target xqe to build it, but it currently generates an executable significantly larger than tqe. This oddity is under investigation. --- Makefile | 49 +++++++++++++++++++++++++++++++++---------------- configure | 40 ++++++++++++++++++++++++++++++++++++++-- qe.c | 9 ++++----- tqe.c | 24 ++++++++++++++++++++++++ x11.c | 33 ++++++++++++++++++++++++++++++--- 5 files changed, 129 insertions(+), 26 deletions(-) create mode 100644 tqe.c diff --git a/Makefile b/Makefile index 867a86f..5a40403 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ ifeq ($(CC),gcc) CFLAGS += -Wall -g -O2 -funsigned-char # do not warn about zero-length formats. CFLAGS += -Wno-format-zero-length - LDFLAGS := -g + LDFLAGS += -g endif #include local compiler configuration file @@ -49,9 +49,9 @@ TLDFLAGS := $(LDFLAGS) ifdef TARGET_ARCH_X86 #CFLAGS+=-fomit-frame-pointer ifeq ($(GCC_MAJOR),2) - CFLAGS+=-m386 -malign-functions=0 + CFLAGS += -m386 -malign-functions=0 else - CFLAGS+=-march=i386 -falign-functions=0 + CFLAGS += -march=i386 -falign-functions=0 endif endif @@ -70,22 +70,22 @@ TOBJS:= $(OBJS) OBJS+= extras.o variables.o ifdef CONFIG_PNG_OUTPUT - HTMLTOPPM_LIBS+= -lpng + HTMLTOPPM_LIBS += -lpng endif ifdef CONFIG_DLL - LIBS+=$(DLLIBS) + LIBS += $(DLLIBS) # export some qemacs symbols - LDFLAGS+=-Wl,-E + LDFLAGS += -Wl,-E endif ifdef CONFIG_DOC - TARGETS+= qe-doc.html + TARGETS += qe-doc.html endif ifdef CONFIG_HAIKU - OBJS+= haiku.o - LIBS+= -lbe + OBJS += haiku.o + LIBS += -lbe endif ifdef CONFIG_WIN32 @@ -133,12 +133,15 @@ endif ifdef CONFIG_X11 OBJS+= x11.o ifdef CONFIG_XRENDER - LIBS+= -lXrender + LIBS += -lXrender endif ifdef CONFIG_XV - LIBS+= -lXv + LIBS += -lXv endif - LIBS+= -L/usr/X11R6/lib -lXext -lX11 + ifdef CONFIG_XSHM + LIBS += -lXext + endif + LIBS += -lX11 endif ifdef CONFIG_HTML @@ -172,8 +175,8 @@ TSRCS:= $(TOBJS:.o=.c) DEPENDS:= qe.h config.h cutils.h display.h qestyles.h variables.h config.mak DEPENDS:= $(addprefix $(DEPTH)/, $(DEPENDS)) -OBJS_DIR:= $(DEPTH)/.objs -TOBJS_DIR:= $(DEPTH)/.tobjs +OBJS_DIR:= $(DEPTH)/.objs-$(TARGET_OS)-$(TARGET_ARCH)-$(CC) +TOBJS_DIR:= $(DEPTH)/.tobjs-$(TARGET_OS)-$(TARGET_ARCH)-$(CC) OBJS:= $(addprefix $(OBJS_DIR)/, $(OBJS)) TOBJS:= $(addprefix $(TOBJS_DIR)/, $(TOBJS)) @@ -214,6 +217,18 @@ tqe$(EXE): tqe_g$(EXE) Makefile @echo `size $@` `wc -c $@` tqe $(OPTIONS) \ | cut -d ' ' -f 7-10,13,15-40 >> STATS +xqe_g$(EXE): tqe.c $(TSRCS) Makefile + $(echo) CC -o $@ $< + $(cmd) $(CC) $(DEFINES) $(CFLAGS) $(TLDFLAGS) -o $@ $< $(TLIBS) + +xqe$(EXE): xqe_g$(EXE) Makefile + @rm -f $@ + cp $< $@ + -$(STRIP) $@ + @ls -l $@ + @echo `size $@` `wc -c $@` xqe $(OPTIONS) \ + | cut -d ' ' -f 7-10,13,15-40 >> STATS + ffplay$(EXE): qe$(EXE) Makefile ln -sf $< $@ @@ -225,12 +240,14 @@ endif allmodules.txt: $(SRCS) Makefile @echo creating $@ @echo '/* This file was generated automatically */' > $@ - @grep -h ^qe_module_init $(SRCS) >> $@ + @grep -h ^qe_module_init $(SRCS) | \ + sed s/qe_module_init/qe_module_declare/ >> $@ basemodules.txt: $(TSRCS) Makefile @echo creating $@ @echo '/* This file was generated automatically */' > $@ - @grep -h ^qe_module_init $(TSRCS) >> $@ + @grep -h ^qe_module_init $(TSRCS) | \ + sed s/qe_module_init/qe_module_declare/ >> $@ $(OBJS_DIR)/cfb.o: cfb.c cfb.h fbfrender.h $(OBJS_DIR)/charsetjis.o: charsetjis.c charsetjis.def diff --git a/configure b/configure index 4c14c94..354a35c 100755 --- a/configure +++ b/configure @@ -67,6 +67,7 @@ mpegaudio_hp="yes" tiny="no" x11="no" xv="no" +xshm="no" xrender="no" png="no" ffmpeg="no" @@ -141,7 +142,6 @@ case $targetos in html="yes" png="yes" x11="no" - xv="no" ;; *) extralibs="-lm" @@ -175,15 +175,27 @@ if test -f "/usr/include/X11/Xlib.h" ; then if test -f "/usr/include/X11/extensions/Xv.h" ; then xv="yes" fi + if test -f "/usr/include/X11/extensions/Xshm.h" ; then + xshm="yes" + fi +fi + +if test -d "/opt/X11/lib" ; then + x11_libdir="/opt/X11/lib" +elif test -d "/usr/X11R6/lib" ; then + x11_libdir="/usr/X11R6/lib" fi if test -f "/opt/X11/include/X11/Xlib.h" ; then - CFLAGS="$CFLAGS -I/opt/X11/include" x11="yes" + x11_includedir="/opt/X11/include" html="yes" if test -f "/opt/X11/include/X11/extensions/Xv.h" ; then xv="yes" fi + if test -f "/opt/X11/include/X11/extensions/Xshm.h" ; then + xshm="yes" + fi fi if test -z `which texi2html` ; then @@ -205,6 +217,7 @@ echo " --enable-win32 enable win32 cross compile" echo " --enable-cygwin compile for cygwin systems" echo " --disable-x11 disable Xwindow support" echo " --disable-xv disable Xvideo extension support" +echo " --disable-xshm disable XShm extension support" echo " --disable-xrender disable Xrender extension support" echo " --enable-tiny build a very small version" echo " --disable-html disable graphical html support" @@ -309,6 +322,9 @@ for opt do --enable-xv | --disable-xv) xv="$value" ;; + --enable-xshm | --disable-xshm) + xshm="$value" + ;; --enable-xrender | --disable-xrender) xrender="$value" ;; @@ -377,6 +393,7 @@ fi if test "$x11" = "no" ; then xv="no" + xshm="no" xrender="no" fi @@ -430,6 +447,7 @@ if test "$tiny" = "yes" ; then ffmpeg="no" x11="no" xv="no" + xshm="no" xrender="no" png="no" html="no" @@ -473,6 +491,15 @@ if $cc -o $TMPO $TMPC 2> /dev/null ; then has_typeof="yes" fi +if test "$x11" = "yes" ; then + if test ! -z "$x11_libdir" ; then + LIBS="$LIBS -L$x11_libdir" + fi + if test ! -z "$x11_includedir" ; then + CFLAGS="$CFLAGS -I$x11_includedir" + fi +fi + echo "Install prefix $prefix" echo "Shared data dir $datadir" echo "Manpages dir $mandir" @@ -481,6 +508,7 @@ echo "C compiler $cc" echo "Tiny build $tiny" echo "X11 support $x11" echo "Xvideo support $xv" +echo "XShm support $xshm" #echo "Xrender support $xrender" echo "libpng support $png" echo "FFMPEG support $ffmpeg" @@ -512,8 +540,11 @@ echo "AR=$ar" >> $TMPMAK echo "STRIP=$strip $strip_args" >> $TMPMAK echo "INSTALL=install" >> $TMPMAK echo "CFLAGS=$CFLAGS" >> $TMPMAK +echo "LIBS=$LIBS" >> $TMPMAK echo "LDFLAGS=$LDFLAGS" >> $TMPMAK echo "EXE=$exe" >> $TMPMAK +echo "TARGET_OS=$targetos" >> $TMPMAK +echo "TARGET_ARCH=$cpu" >> $TMPMAK if test "$cpu" = "x86" ; then echo "TARGET_ARCH_X86=yes" >> $TMPMAK @@ -596,6 +627,11 @@ if test "$xv" = "yes" ; then echo "CONFIG_XV=yes" >> $TMPMAK fi +if test "$xshm" = "yes" ; then + echo "#define CONFIG_XSHM 1" >> $TMPH + echo "CONFIG_XSHM=yes" >> $TMPMAK +fi + if test "$xrender" = "yes" ; then echo "#define CONFIG_XRENDER 1" >> $TMPH echo "CONFIG_XRENDER=yes" >> $TMPMAK diff --git a/qe.c b/qe.c index 8839c40..6c05e1c 100644 --- a/qe.c +++ b/qe.c @@ -7916,16 +7916,15 @@ static void exit_all_modules(void) #define MODULE_LIST "allmodules.txt" #endif -#undef qe_module_init -#define qe_module_init(fn) extern int module_ ## fn(void) +#define qe_module_declare(fn) extern int module_ ## fn(void) #include MODULE_LIST -#undef qe_module_init +#undef qe_module_declare static void init_all_modules(void) { -#define qe_module_init(fn) module_ ## fn() +#define qe_module_declare(fn) module_ ## fn() #include MODULE_LIST -#undef qe_module_init +#undef qe_module_declare } #endif diff --git a/tqe.c b/tqe.c new file mode 100644 index 0000000..b3521ad --- /dev/null +++ b/tqe.c @@ -0,0 +1,24 @@ +#define CONFIG_TINY 1 +#include "qe.c" +#include "util.c" +#include "cutils.c" +#include "charset.c" +#include "buffer.c" +#include "search.c" +#include "parser.c" +#include "input.c" +#include "display.c" +#include "hex.c" +#include "list.c" + +#ifdef CONFIG_WIN32 +#include "unix.c" +#include "win32.c" +#else +#include "unix.c" +#include "tty.c" +#endif + +#ifdef CONFIG_INIT_CALLS +#include "qeend.c" +#endif diff --git a/x11.c b/x11.c index 20a7abd..8912e35 100644 --- a/x11.c +++ b/x11.c @@ -30,7 +30,9 @@ #include #include #include +#ifdef CONFIG_XSHM #include +#endif #ifdef CONFIG_XFT #include #include @@ -64,9 +66,11 @@ static int last_window_width, last_window_height, last_window_x, last_window_y; static XIM xim; /* X11 input method */ static XIC xic; /* X11 input context */ static Pixmap dbuffer; +#ifdef CONFIG_XSHM static int shm_use; +#endif #ifdef CONFIG_XFT -static XftDraw *renderDraw; +static XftDraw *renderDraw; #endif #ifdef CONFIG_XV static unsigned int xv_nb_adaptors; @@ -342,6 +346,7 @@ static int term_init(QEditScreen *s, int w, int h) dbuffer = window; #endif +#ifdef CONFIG_XSHM /* shm extension usable ? */ p = XDisplayName(display_str); strstart(p, "unix:", &p); @@ -350,6 +355,7 @@ static int term_init(QEditScreen *s, int w, int h) /* Check if display is local and XShm available */ if ((*p == ':') && XShmQueryExtension(display)) shm_use = 1; +#endif /* compute bitmap format */ switch (visual_depth) { @@ -1412,6 +1418,13 @@ static void x11_handle_event(void *opaque) meta ? "meta " : "", len, buf[0]); #endif + if (shift) { + switch (keysym) { + case XK_ISO_Left_Tab: key = KEY_SHIFT_TAB; goto got_key; + default: + break; + } + } else if (meta) { switch (keysym) { case XK_BackSpace: @@ -1513,7 +1526,9 @@ static void x11_handle_event(void *opaque) enum X11BitmapType { BMP_PIXMAP, BMP_XIMAGE, +#ifdef CONFIG_XSHM BMP_XSHMIMAGE, +#endif #ifdef CONFIG_XV BMP_XVIMAGE, BMP_XVSHMIMAGE, @@ -1529,7 +1544,9 @@ typedef struct X11Bitmap { XvImage *xvimage; #endif } u; +#ifdef CONFIG_XSHM XShmSegmentInfo *shm_info; +#endif int x_lock, y_lock; /* destination for locking */ XImage *ximage_lock; } X11Bitmap; @@ -1556,9 +1573,11 @@ static int x11_bmp_alloc(QEditScreen *s, QEBitmap *b) } else #endif { +#ifdef CONFIG_XSHM if (shm_use) xb->type = BMP_XSHMIMAGE; else +#endif xb->type = BMP_XIMAGE; b->format = s->bitmap_format; } @@ -1584,6 +1603,7 @@ static int x11_bmp_alloc(QEditScreen *s, QEBitmap *b) xb->u.ximage = ximage; } break; +#ifdef CONFIG_XSHM case BMP_XSHMIMAGE: { XImage *ximage; @@ -1609,6 +1629,7 @@ static int x11_bmp_alloc(QEditScreen *s, QEBitmap *b) xb->u.ximage = ximage; } break; +#endif #ifdef CONFIG_XV case BMP_XVIMAGE: { @@ -1663,12 +1684,14 @@ static void x11_bmp_free(qe__unused__ QEditScreen *s, QEBitmap *b) /* NOTE: also frees the ximage data */ XDestroyImage(xb->u.ximage); break; +#ifdef CONFIG_XSHM case BMP_XSHMIMAGE: XShmDetach(display, xb->shm_info); XDestroyImage(xb->u.ximage); shmdt(xb->shm_info->shmaddr); qe_free(&xb->shm_info); break; +#endif #ifdef CONFIG_XV case BMP_XVIMAGE: qe_free(&xb->u.xvimage->data); @@ -1708,11 +1731,13 @@ static void x11_bmp_draw(qe__unused__ QEditScreen *s, QEBitmap *b, b->width, b->height); break; +#ifdef CONFIG_XSHM case BMP_XSHMIMAGE: XShmPutImage(display, dbuffer, gc, xb->u.ximage, 0, 0, dst_x, dst_y, b->width, b->height, False); break; +#endif #ifdef CONFIG_XV case BMP_XVIMAGE: XvPutImage(display, xv_port, window, gc, xb->u.xvimage, @@ -1752,7 +1777,9 @@ static void x11_bmp_lock(qe__unused__ QEditScreen *s, QEBitmap *b, QEPicture *pi } break; case BMP_XIMAGE: +#ifdef CONFIG_XSHM case BMP_XSHMIMAGE: +#endif bpp = (xb->u.ximage->bits_per_pixel + 7) >> 3; pict->data[0] = (unsigned char *)xb->u.ximage->data + y1 * xb->u.ximage->bytes_per_line + x1 * bpp; @@ -1788,10 +1815,10 @@ static void x11_bmp_lock(qe__unused__ QEditScreen *s, QEBitmap *b, QEPicture *pi static void x11_bmp_unlock(qe__unused__ QEditScreen *s, QEBitmap *b) { X11Bitmap *xb = b->priv_data; - int ret; + switch (xb->type) { case BMP_PIXMAP: - ret = XPutImage(display, xb->u.pixmap, gc_pixmap, xb->ximage_lock, + XPutImage(display, xb->u.pixmap, gc_pixmap, xb->ximage_lock, 0, 0, xb->x_lock, xb->y_lock, xb->ximage_lock->width, xb->ximage_lock->height); /* NOTE: also frees the ximage data */