Skip to content

Commit

Permalink
tinyx: partially port micropolis, fix colors in xserver
Browse files Browse the repository at this point in the history
Micropolis runs and draws "Micropolis Scenarios" window, but not much
else for now. But similar patches allowed building and running it on
linux host with X11 forwarding via TCP, which helped debugging and
fixing xserver colormaps

JIRA: RTOS-889
  • Loading branch information
adamgreloch committed Aug 30, 2024
1 parent 9acfb3b commit 7cd0c06
Show file tree
Hide file tree
Showing 3 changed files with 467 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tinyx/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,33 @@ build_suckless() {
}


build_micropolis() {
b_log "tinyx: building micropolis"

ref="b0c5a3f495ebabbc51d5e45dac948d8e40fc53ee"
short_ref=$(echo ${ref} | cut -c -6)
archive_filename="${ref}.tar.gz"

PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/micropolis/${short_ref}"
b_port_download "https://github.com/SimHacker/micropolis/archive/" "${archive_filename}"

extract_sources

b_port_apply_patches "${PREFIX_PORT_SRC}" "micropolis/${short_ref}"

set +e
for i in {1..3} # If you run make exactly 3 times, micropolis will compile...
do
make -C "${PREFIX_PORT_SRC}/micropolis-activity" PREFIX="${PREFIX_A}"
done
set -e

$STRIP -o "${PREFIX_PROG_STRIPPED}/Micropolis" "${PREFIX_PORT_SRC}/micropolis-activity/src/sim/sim"

b_install "${PREFIX_PORTS_INSTALL}/Micropolis" /bin
}


# Call ordering is important here
build_tinyxlib
build_a_lib libfontenc 1.1.8
Expand All @@ -411,5 +438,6 @@ build_x11_app xsetroot 1.1.1
build_x11_app xinit 1.3.3
build_x11_app xrdb 1.2.2
build_x11_app xgc 1.0.6
# build_micropolis

rm -rf "$TMP_DIR"
292 changes: 292 additions & 0 deletions tinyx/patches/micropolis/b0c5a3/01-micropolis.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
diff -ruN a/micropolis-activity/res/micropolis.tcl b/micropolis-activity/res/micropolis.tcl
--- a/micropolis-activity/res/micropolis.tcl 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/res/micropolis.tcl 2024-08-29 10:58:30.934849614 +0200
@@ -128,7 +128,7 @@
set HomeDir ""
set ResourceDir ""
set HostName ""
-set LocalHostName "[exec hostname]"
+set LocalHostName "phoenix"
set SaveCityWin ""
set MapHistory {}
set MapHistoryNum -1
diff -ruN a/micropolis-activity/src/sim/headers/sim.h b/micropolis-activity/src/sim/headers/sim.h
--- a/micropolis-activity/src/sim/headers/sim.h 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/sim/headers/sim.h 2024-08-29 10:39:07.930492735 +0200
@@ -121,8 +121,6 @@
#endif
#endif

-#include <sys/ipc.h>
-#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
diff -ruN a/micropolis-activity/src/sim/makefile b/micropolis-activity/src/sim/makefile
--- a/micropolis-activity/src/sim/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/sim/makefile 2024-08-29 10:39:07.930492735 +0200
@@ -1,12 +1,12 @@
-XINCLUDE = /usr/X11R6/include/X11
-XLIB = /usr/X11R6/lib
+XINCLUDE = $(PREFIX_H)/X11
+XLIB = $(PREFIX_A)
TCLHOME = ../tcl
TKHOME = ../tk
TCLXHOME = ../tclx
TCLLIBRARY = /usr/local/lib/tcl
TKLIBRARY = /usr/local/lib/tk

-CC = gcc
+# CC = gcc

OPTFLAGS = -O3
#OPTFLAGS = -g
@@ -14,9 +14,9 @@
#DEFINES = -DIS_LINUX -DCAM -DNET
DEFINES = -DIS_LINUX -DNO_AIRCRASH

-CFLAGS = $(OPTFLAGS) $(DEFINES)
+CFLAGS += $(OPTFLAGS) $(DEFINES)

-LDFLAGS = -L/usr/X11/lib -L/usr/X11R6/lib
+LDFLAGS += -L$(PREFIX_A)

INSTALL = install -s

@@ -28,15 +28,15 @@
-I$(TCLXHOME)/src \
-I$(TKHOME)

-CPPFLAGS = $(INCLUDES)
+CPPFLAGS += $(INCLUDES)

LIBS = $(TCLXHOME)/libtk.a \
$(TCLXHOME)/libtcl.a \
-lm \
-L$(XLIB) \
- -lX11 \
- -lXext \
- -lXpm
+ -l:libXext.a \
+ -l:libXpm.a \
+ -l:libX11.a

SRCS = \
sim.c \
diff -ruN a/micropolis-activity/src/sim/s_fileio.c b/micropolis-activity/src/sim/s_fileio.c
--- a/micropolis-activity/src/sim/s_fileio.c 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/sim/s_fileio.c 2024-08-29 10:39:07.930492735 +0200
@@ -486,12 +486,12 @@
CityFileName = (char *)ckalloc(strlen(filename) + 1);
strcpy(CityFileName, filename);

- if (cp = (char *)rindex(filename, '.'))
+ if (cp = (char *)strrchr(filename, '.'))
*cp = 0;
#ifdef MSDOS
- if (cp = (char *)rindex(filename, '\\'))
+ if (cp = (char *)strrchr(filename, '\\'))
#else
- if (cp = (char *)rindex(filename, '/'))
+ if (cp = (char *)strrchr(filename, '/'))
#endif
cp++;
else
@@ -579,12 +579,12 @@
strcpy(CityFileName, filename);

if (saveFile(CityFileName)) {
- if (cp = (char *)rindex(filename, '.'))
+ if (cp = (char *)strrchr(filename, '.'))
*cp = 0;
#ifdef MSDOS
- if (cp = (char *)rindex(filename, '\\'))
+ if (cp = (char *)strrchr(filename, '\\'))
#else
- if (cp = (char *)rindex(filename, '/'))
+ if (cp = (char *)strrchr(filename, '/'))
#endif
cp++;
else
diff -ruN a/micropolis-activity/src/sim/w_x.c b/micropolis-activity/src/sim/w_x.c
--- a/micropolis-activity/src/sim/w_x.c 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/sim/w_x.c 2024-08-29 10:39:07.932501038 +0200
@@ -71,6 +71,8 @@
#endif
int GotXError;

+#define MSDOS
+

unsigned char ColorIntensities[] = {
/* COLOR_WHITE */ 255,
diff -ruN a/micropolis-activity/src/tcl/makefile b/micropolis-activity/src/tcl/makefile
--- a/micropolis-activity/src/tcl/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tcl/makefile 2024-08-29 10:39:07.933505190 +0200
@@ -23,10 +23,10 @@
#

TCL_LIBRARY = /usr/local/lib/tcl
+#
+# CC = gcc

-CC = gcc
-
-CFLAGS = -O3 -I. -DTCL_LIBRARY=\"${TCL_LIBRARY}\" -DIS_LINUX
+CFLAGS += -O3 -I. -DTCL_LIBRARY=\"${TCL_LIBRARY}\" -DIS_LINUX
#CFLAGS = -g -I. -DTCL_LIBRARY=\"${TCL_LIBRARY}\" -DIS_LINUX

GENERIC_OBJS = \
diff -ruN a/micropolis-activity/src/tcl/tclglob.c b/micropolis-activity/src/tcl/tclglob.c
--- a/micropolis-activity/src/tcl/tclglob.c 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tcl/tclglob.c 2024-08-29 10:39:07.934509341 +0200
@@ -493,7 +493,7 @@
strcat(curBuf, p);
#ifndef MSDOS
if (fromPw) {
- endpwent();
+ // endpwent();
}
#endif
return curBuf;
diff -ruN a/micropolis-activity/src/tclx/config/linux b/micropolis-activity/src/tclx/config/linux
--- a/micropolis-activity/src/tclx/config/linux 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tclx/config/linux 2024-08-29 10:39:07.935513493 +0200
@@ -2,9 +2,9 @@
# Linux and also Mac OS/X for that matter.
#------------------------------------------------------------------------------
#
-SYS_DEP_FLAGS=-DTCL_HAVE_SETLINEBUF -DTCL_32_BIT_RANDOM -DTCL_POSIX_SIG -DTCL_TM_GMTOFF
+SYS_DEP_FLAGS=-DTCL_32_BIT_RANDOM -DTCL_POSIX_SIG -DTCL_TIMEZONE_VAR -DTCL_IEEE_FP_MATH -DTCL_NO_ITIMER
LIBS=-lm
RANLIB_CMD=ranlib
MCS_CMD=true
-TCL_TK_LIBS= -L/usr/X11R6/lib -lX11 -lm -lXpm
+TCL_TK_LIBS= -L$(PREFIX_A) -lm -l:libXpm.a -l:libX11.a
TCL_MAN_SEPARATOR=
diff -ruN a/micropolis-activity/src/tclx/config.mk b/micropolis-activity/src/tclx/config.mk
--- a/micropolis-activity/src/tclx/config.mk 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tclx/config.mk 2024-08-29 10:39:07.935513493 +0200
@@ -53,14 +53,14 @@
TCL_TK_SHELL=wish
TCL_TK_DIR=../tk
TK_LIBRARY=/usr/local/lib/tk
-XPM_LIBS=-L/usr/X11R6/lib -lXpm
+XPM_LIBS=-L$(PREFIX_A) -l:libXpm.a -l:libX11.a

#------------------------------------------------------------------------------
# Compiler debug/optimization/profiling flag to use. Not that if debugging or
# profiling is enabled, the DO_STRIPPING option below must be disabled.
#

-CC=gcc
+# CC=gcc

OPTIMIZE_FLAG=-O3 -DIS_LINUX
#OPTIMIZE_FLAG=-g -DIS_LINUX
@@ -212,6 +212,8 @@
TK_MAN_CMD_SECTION=1
TK_MAN_FUNC_SECTION=3

+LIBS=-l:libX11.a
+

#..............................................................................
# The rest of the manual page install options are set in the system dependent
diff -ruN a/micropolis-activity/src/tclx/makefile b/micropolis-activity/src/tclx/makefile
--- a/micropolis-activity/src/tclx/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tclx/makefile 2024-08-29 10:39:07.935513493 +0200
@@ -30,7 +30,7 @@
MADE.FILES=ucbsrc/made.tmp ossupp/made.tmp src/made.tmp
TKMADE.FILES=tkucbsrc/made.tmp

-CFLAGS= $(OPTIMIZE_FLAG) $(XCFLAGS) -I$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) \
+CFLAGS+= $(OPTIMIZE_FLAG) $(XCFLAGS) -I$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) \
$(SYS_DEP_FLAGS)

#------------------------------------------------------------------------------
diff -ruN a/micropolis-activity/src/tclx/ossupp/makefile b/micropolis-activity/src/tclx/ossupp/makefile
--- a/micropolis-activity/src/tclx/ossupp/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tclx/ossupp/makefile 2024-08-29 10:39:07.935513493 +0200
@@ -22,7 +22,7 @@

#------------------------------------------------------------------------------

-CFLAGS=$(OPTIMIZE_FLAG) $(XCFLAGS) -I../$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) \
+CFLAGS+=$(OPTIMIZE_FLAG) $(XCFLAGS) -I../$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) \
$(SYS_DEP_FLAGS) $(SUPPORT_FLAGS)

#------------------------------------------------------------------------------
diff -ruN a/micropolis-activity/src/tclx/src/makefile b/micropolis-activity/src/tclx/src/makefile
--- a/micropolis-activity/src/tclx/src/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tclx/src/makefile 2024-08-29 10:39:07.935513493 +0200
@@ -25,7 +25,7 @@

#------------------------------------------------------------------------------

-CFLAGS= $(OPTIMIZE_FLAG) $(XCFLAGS) -I../$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) \
+CFLAGS+= $(OPTIMIZE_FLAG) $(XCFLAGS) -I../$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) \
$(SYS_DEP_FLAGS)

#------------------------------------------------------------------------------
diff -ruN a/micropolis-activity/src/tclx/tksrc/makefile b/micropolis-activity/src/tclx/tksrc/makefile
--- a/micropolis-activity/src/tclx/tksrc/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tclx/tksrc/makefile 2024-08-29 10:39:07.938525948 +0200
@@ -23,7 +23,7 @@

#------------------------------------------------------------------------------

-CFLAGS= $(OPTIMIZE_FLAG) $(XCFLAGS) -I$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS)
+CFLAGS+= $(OPTIMIZE_FLAG) $(XCFLAGS) -I$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS)

#------------------------------------------------------------------------------

diff -ruN a/micropolis-activity/src/tclx/tkucbsrc/makefile b/micropolis-activity/src/tclx/tkucbsrc/makefile
--- a/micropolis-activity/src/tclx/tkucbsrc/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tclx/tkucbsrc/makefile 2024-08-29 10:39:07.938525948 +0200
@@ -23,7 +23,7 @@

#------------------------------------------------------------------------------

-CFLAGS= $(OPTIMIZE_FLAG) $(XCFLAGS) -I../src -I../$(TCL_TK_DIR) \
+CFLAGS+= $(OPTIMIZE_FLAG) $(XCFLAGS) -I../src -I../$(TCL_TK_DIR) \
-I../$(TCL_UCB_DIR) -I$(XHOME)/include \
$(MEM_DEBUG_FLAGS) $(SYS_DEP_FLAGS) \
-DTK_VERSION=\"2.2/\"
diff -ruN a/micropolis-activity/src/tclx/ucbsrc/makefile b/micropolis-activity/src/tclx/ucbsrc/makefile
--- a/micropolis-activity/src/tclx/ucbsrc/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tclx/ucbsrc/makefile 2024-08-29 10:39:07.938525948 +0200
@@ -24,7 +24,7 @@

#------------------------------------------------------------------------------

-CFLAGS=$(OPTIMIZE_FLAG) $(XCFLAGS) -I../$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) \
+CFLAGS+=$(OPTIMIZE_FLAG) $(XCFLAGS) -I../$(TCL_UCB_DIR) $(MEM_DEBUG_FLAGS) \
$(SYS_DEP_FLAGS)

#------------------------------------------------------------------------------
diff -ruN a/micropolis-activity/src/tk/makefile b/micropolis-activity/src/tk/makefile
--- a/micropolis-activity/src/tk/makefile 2015-03-15 15:22:19.000000000 +0100
+++ b/micropolis-activity/src/tk/makefile 2024-08-29 10:39:07.941538403 +0200
@@ -27,16 +27,16 @@
# switch unless your library is in a non-standard place.
#

-CC = gcc
+# CC = gcc

-CFLAGS = -I. -I$(XINCLUDE) -I$(TCL_DIR) -O3 -DTK_VERSION=\"2.3\" -DUSE_XPM3 -DIS_LINUX
+CFLAGS += -I. -I$(XINCLUDE) -I$(TCL_DIR) -O3 -DTK_VERSION=\"2.3\" -DUSE_XPM3 -DIS_LINUX
#CFLAGS = -I. -I$(XINCLUDE) -I$(TCL_DIR) -g -DTK_VERSION=\"2.3\" -DUSE_XPM3 -DIS_LINUX

TCL_DIR = ../tcl
-XINCLUDE = /usr/X11R6/include/X11
-XLIB = -L/usr/X11R6/lib -lX11 -lXpm
+XINCLUDE = $(PREFIX_H)/X11
+XLIB = -L$(PREFIX_A) -l:libXpm.a -l:libX11.a

-LIBS = libtk.a $(TCL_DIR)/libtcl.a
+LIBS += libtk.a $(TCL_DIR)/libtcl.a
LINKS = $(LIBS)

WIDGOBJS = \
Loading

0 comments on commit 7cd0c06

Please sign in to comment.