Skip to content

Commit ce4833d

Browse files
committed
Add cosmopolitan support using 'make-cosmo'.
1 parent cda254b commit ce4833d

10 files changed

+180
-15
lines changed

Makefile

+22-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ elks:
2020

2121
clean:
2222
rm -f *.o *.a memopad smallpad huffc fixhelp memopad.hlp
23+
rm -f memopad.com smallpad.com huffc.com fixhelp.com
2324

2425
ifeq ($(SMALL),y)
2526
BUILDOPTS = -DBUILD_SMALL_DFLAT
@@ -35,10 +36,16 @@ CFLAGS += -g
3536
CFLAGS += -Wno-pointer-sign
3637
CFLAGS += -Wno-compare-distinct-pointer-types
3738
CFLAGS += -Wno-invalid-source-encoding
39+
ifneq ($(COSMO),)
40+
CFLAGS += -DCOSMO=1
41+
endif
3842

3943
OBJS = memopad.o dialogs.o menus.o
4044
memopad: $(OBJS) $(LIBS)
4145
$(CC) $(LDFLAGS) -o $@ $(OBJS) -L. -ldflat
46+
ifneq ($(COSMO),)
47+
$(OBJCOPY) -S -O binary $@ [email protected]
48+
endif
4249

4350
SMALLOBJS = smallpad.o
4451
smallpad: $(SMALLOBJS) $(LIBS)
@@ -91,14 +98,23 @@ DFLATOBJS += \
9198
$(LIBS): $(DFLATOBJS)
9299
$(AR) rcs $(LIBS) $(DFLATOBJS)
93100

94-
HUFFOBJS = huffc.o htree.o
95-
huffc: $(HUFFOBJS)
96-
$(CC) $(LDFLAGS) -o $@ $(HUFFOBJS)
101+
huffc: huffc.o htree.o
102+
$(CC) $(LDFLAGS) -o $@ $^
103+
ifneq ($(COSMO),)
104+
$(OBJCOPY) -S -O binary $@ [email protected]
105+
endif
97106

98-
FIXHOBJS = fixhelp.o decomp.o
99-
fixhelp: $(FIXHOBJS)
100-
$(CC) $(LDFLAGS) -o $@ $(FIXHOBJS)
107+
fixhelp: fixhelp.o decomp.o
108+
$(CC) $(LDFLAGS) -o $@ $^
109+
ifneq ($(COSMO),)
110+
$(OBJCOPY) -S -O binary $@ [email protected]
111+
endif
101112

102113
memopad.hlp: memopad.txt huffc fixhelp
114+
ifeq ($(COSMO),)
103115
./huffc memopad.txt memopad.hlp
104116
./fixhelp memopad
117+
else
118+
./huffc.com memopad.txt memopad.hlp
119+
./fixhelp.com memopad
120+
endif

cosmoc++

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/sh
2+
# replacement for c++ command
3+
#
4+
# we assume you run the following beforehand
5+
#
6+
# sudo chmod 1777 /opt
7+
# cd /opt
8+
# git clone https://github.com/jart/cosmopolitan cosmo
9+
# cd cosmo
10+
# make -j
11+
#
12+
# you can then use it to build open source projects, e.g.
13+
#
14+
# export CC=cosmocc
15+
# export CXX=cosmoc++
16+
# export LD=cosmoc++
17+
# ./configure --prefix=/opt/cosmos
18+
# make -j
19+
# make install
20+
#
21+
22+
if [ "$1" = "--version" ]; then
23+
cat <<'EOF'
24+
x86_64-unknown-cosmo-g++ (GCC) 9.2.0
25+
Copyright (C) 2019 Free Software Foundation, Inc.
26+
This is free software; see the source for copying conditions. There is NO
27+
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28+
EOF
29+
exit 0
30+
fi
31+
32+
COSMO="/Users/greg/net/cosmopolitan"
33+
CXX="x86_64-linux-musl-g++"
34+
CCFLAGS="-O2 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
35+
CXXFLAGS="-fno-exceptions -fuse-cxa-atexit -fno-threadsafe-statics"
36+
CPPFLAGS="-DNDEBUG -nostdinc -iquote $COSMO -isystem $COSMO/include -isystem $COSMO/libc/isystem -include libc/integral/normalize.inc"
37+
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,--gc-sections -L$COSMO/lib -Wl,-T,$COSMO/o/ape/public/ape.lds $COSMO/o/ape/ape-no-modify-self.o $COSMO/o/libc/crt/crt.o"
38+
LDLIBS="$COSMO/o/third_party/libcxx/libcxx.a $COSMO/o/cosmopolitan.a"
39+
40+
HAS_C=0
41+
HAS_O=0
42+
HAS_E=0
43+
FIRST=1
44+
for x; do
45+
if [ $FIRST -eq 1 ]; then
46+
set --
47+
FIRST=0
48+
fi
49+
if [ "$x" = "-c" ]; then
50+
HAS_C=1
51+
fi
52+
if [ "$x" = "-E" ]; then
53+
HAS_E=1
54+
fi
55+
if [ "$x" = "-o" ] || [ "${x#-o}" != "$x" ]; then
56+
HAS_O=1
57+
fi
58+
set -- "$@" "$x"
59+
done
60+
61+
if [ "$HAS_E" = "1" ]; then
62+
set -- $CPPFLAGS "$@"
63+
elif [ "$HAS_C" = "1" ]; then
64+
set -- $CCFLAGS $CXXFLAGS $CPPFLAGS "$@"
65+
else
66+
set -- $LDFLAGS $CPPFLAGS "$@" $LDLIBS
67+
fi
68+
69+
set -- "$CXX" "$@"
70+
printf '(cd %s; %s)\n' "$PWD" "$*" >>/tmp/build.log
71+
echo "$@"
72+
exec "$@"

cosmocc

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/sh
2+
# replacement for cc command
3+
#
4+
# we assume you run the following beforehand
5+
#
6+
# sudo chmod 1777 /opt
7+
# cd /opt
8+
# git clone https://github.com/jart/cosmopolitan cosmo
9+
# cd cosmo
10+
# make -j
11+
#
12+
# you can then use it to build open source projects, e.g.
13+
#
14+
# export CC=cosmocc
15+
# export CXX=cosmoc++
16+
# export LD=cosmoc++
17+
# ./configure --prefix=/opt/cosmos
18+
# make -j
19+
# make install
20+
#
21+
22+
if [ "$1" = "--version" ]; then
23+
cat <<'EOF'
24+
x86_64-unknown-cosmo-gcc (GCC) 9.2.0
25+
Copyright (C) 2019 Free Software Foundation, Inc.
26+
This is free software; see the source for copying conditions. There is NO
27+
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28+
EOF
29+
exit 0
30+
fi
31+
32+
COSMO="/Users/greg/net/cosmopolitan"
33+
CC="x86_64-linux-musl-gcc"
34+
CFLAGS="-O2 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
35+
CPPFLAGS="-DNDEBUG -nostdinc -iquote $COSMO -isystem $COSMO/include -isystem $COSMO/libc/isystem -include libc/integral/normalize.inc"
36+
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,--gc-sections -L$COSMO/lib -Wl,-T,$COSMO/o/ape/public/ape.lds $COSMO/o/ape/ape-no-modify-self.o $COSMO/o/libc/crt/crt.o"
37+
LDLIBS="$COSMO/o/cosmopolitan.a"
38+
39+
HAS_C=0
40+
HAS_O=0
41+
HAS_E=0
42+
FIRST=1
43+
for x; do
44+
if [ $FIRST -eq 1 ]; then
45+
set --
46+
FIRST=0
47+
fi
48+
if [ "$x" = "-c" ]; then
49+
HAS_C=1
50+
fi
51+
if [ "$x" = "-E" ]; then
52+
HAS_E=1
53+
fi
54+
if [ "$x" = "-o" ] || [ "${x#-o}" != "$x" ]; then
55+
HAS_O=1
56+
fi
57+
set -- "$@" "$x"
58+
done
59+
60+
if [ "$HAS_E" = "1" ]; then
61+
set -- $CPPFLAGS "$@"
62+
elif [ "$HAS_C" = "1" ]; then
63+
set -- $CFLAGS $CPPFLAGS "$@"
64+
else
65+
set -- $LDFLAGS $CPPFLAGS "$@" $LDLIBS
66+
fi
67+
68+
set -- "$CC" "$@"
69+
printf '(cd %s; %s)\n' "$PWD" "$*" >>/tmp/build.log
70+
exec "$@"

make-cosmo

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#make CC=./cosmocc CXX=./cosmoc++ LD=./cosmoc++ AR=/Users/greg/net/cosmopolitan/build/bootstrap/ar.com
2+
3+
make COSMO=1 CC=./cosmocc LD=./cosmoc++ AR=x86_64-linux-musl-ar OBJCOPY=x86_64-linux-musl-objcopy

memopad.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static void OpenPadWindow(WINDOW wnd, char *FileName)
202202
wndpos += 2;
203203
if (wndpos == 20)
204204
wndpos = 2;
205-
wnd1 = CreateWindow(EDITOR,
205+
wnd1 = CreateWindow(EDITBOX,
206206
Fname,
207207
(wndpos-1)*2, wndpos, 10, 40,
208208
NULL, wnd, OurEditorProc,

runshell.c

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
typedef void (*sighandler_t) (int);
77
#endif
88

9+
#ifdef COSMO
10+
extern void _exit(int);
11+
#endif
12+
913
int
1014
runshell(void)
1115
{

tty-cp437.c

-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ static int elks_displayable(int c)
7777
/* convert CP 437 byte to string + NUL, depending on platform */
7878
int cp437tostr(char *s, int c)
7979
{
80-
extern unsigned short kCp437[256];
81-
8280
#if ELKS
8381
if (iselksconsole) {
8482
if (!elks_displayable(c & 255))

unikey.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define CHECK_MOUSE 1 /* =1 to validate ANSI mouse sequences */
1717
#define DEBUG 1 /* =1 for keyname() */
1818
#define ESC 27
19-
#define unreachable
2019

2120
static char scroll_reverse = 0; /* report reversed scroll wheel direction */
2221
int kDoubleClickTime = 200;
@@ -277,11 +276,9 @@ int stream_to_rune(unsigned int ch)
277276
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
278277
│ PERFORMANCE OF THIS SOFTWARE. │
279278
╚─────────────────────────────────────────────────────────────────────────────*/
280-
//#include "libc/calls/calls.h"
281-
//#include "libc/calls/internal.h"
282-
//#include "libc/str/thompike.h"
283-
//#include "libc/sysv/errfuns.h"
284279

280+
#ifndef COSMO
281+
#define unreachable
285282
/**
286283
* Reads single keystroke or control sequence from character device.
287284
*
@@ -539,6 +536,7 @@ static int startswith(const char *s, const char *prefix) {
539536
if (*s++ != *prefix++) return 0;
540537
}
541538
}
539+
#endif
542540

543541
static int getparm(char *buf, int n)
544542
{

unikey.h

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ extern int iselksconsole;
2727
char *tty_allocate_screen(int cols, int lines);
2828
void tty_output_screen(int flush);
2929
void tty_setfgpalette(const int *pal16, const int *pal256);
30+
#ifndef COSMO
31+
extern unsigned short kCp437[256];
32+
#endif
3033

3134
/* unikey.c - recognize ANSI input */
3235

@@ -47,8 +50,10 @@ char *unikeyname(int k);
4750
/* state machine conversion of UTF-8 byte sequence to Rune */
4851
int stream_to_rune(unsigned int ch);
4952

53+
#ifndef COSMO
5054
/* Reads single keystroke or control sequence from character device */
5155
int readansi(int fd, char *p, int n);
56+
#endif
5257

5358
#define bsr(x) ((x)? (__builtin_clz(x) ^ ((sizeof(int) * 8) -1)): 0)
5459
#if 0

video.h

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#define far
1414
#define poke(a,o,w) (*((unsigned short *)((char *)(a)+(o))) = (w))
1515
#define peek(a,o) (*((unsigned short *)((char *)(a)+(o))))
16-
extern unsigned short kCp437[256];
1716
void convert_screen_to_ansi(void);
1817
#endif
1918

0 commit comments

Comments
 (0)