Improve build on Windows via llvm-mingw

This commit is contained in:
Ivan Baravy 2021-12-13 15:58:19 +03:00
parent 74f78a60de
commit 5eb6770760
12 changed files with 84 additions and 61 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.ref.log text eol=auto

2
.gitignore vendored
View File

@ -34,3 +34,5 @@ covpreproc
*.aml
ignore.*
t.d
*~
*.exe

View File

@ -1,15 +0,0 @@
#include "isatty.h"
#ifdef _WIN32
int isatty(int fd) {
// TODO: Make it work for win32
return 0;
}
int fileno(FILE *fp) {
// TODO: Make it work for win32
return 0;
}
#endif // _WIN32

View File

@ -1,6 +0,0 @@
#pragma once
#include <stdio.h>
int isatty(int fd);
int fileno(FILE *fp);

View File

@ -2,32 +2,56 @@ ifndef KOLIBRIOS
$(error "Set KOLIBRIOS environment variable to KolibriOS root")
endif
FASM ?= fasm -dUEFI=1 -dextended_primary_loader=1 -dUMKA=1
ifndef HOST
$(error "Set HOST variable to linux/windows")
endif
FASM_EXE ?= fasm
FASM_INCLUDE=$(KOLIBRIOS)/kernel/trunk;$(KOLIBRIOS)/programs/develop/libraries/libcrash/hash
FASM_FLAGS=-dUEFI=1 -dextended_primary_loader=1 -dUMKA=1 -dHOST=$(HOST)
CC ?= gcc
WARNINGS_COMMON=-Wall -Wextra \
-Wnull-dereference -Wshadow -Wformat=2 -Wswitch -Wswitch-enum \
-Wpedantic \
#-Wconversion -Wsign-conversion
NOWARNINGS_COMMON=-Wno-address-of-packed-member -Wno-missing-prototype-for-cc
NOWARNINGS_COMMON=-Wno-address-of-packed-member
ifeq ($(CC),gcc)
ifneq (,$(findstring gcc,$(CC)))
WARNINGS=$(WARNINGS_COMMON) -Wduplicated-cond -Wduplicated-branches -Wrestrict -Wlogical-op -Wjump-misses-init
NOWARNINGS=$(NOWARNINGS_COMMON)
else ifeq ($(CC),clang)
else ifneq (,$(findstring clang,$(CC)))
WARNINGS=$(WARNINGS_COMMON)
NOWARNINGS=$(NOWARNINGS_COMMON)
NOWARNINGS=$(NOWARNINGS_COMMON) -Wno-missing-prototype-for-cc
else
$(error compiler $(CC) is not supported)
$(error your compiler is not supported)
endif
CFLAGS=$(WARNINGS) $(NOWARNINGS) -std=c11 -g -O0 -D_FILE_OFFSET_BITS=64 \
-DNDEBUG -masm=intel -D_POSIX_C_SOURCE=200809L -Ilinux -fno-pie
-DNDEBUG -masm=intel -D_POSIX_C_SOURCE=200809L -I$(HOST) -fno-pie
CFLAGS_32=$(CFLAGS) -m32
LDFLAGS=-no-pie
LDFLAGS_32=$(LDFLAGS) -m32
ifeq ($(HOST),linux)
FASM_INCLUDE=$(KOLIBRIOS)/kernel/trunk;$(KOLIBRIOS)/programs/develop/libraries/libcrash/hash
FASM=INCLUDE="$(FASM_INCLUDE)" $(FASM_EXE) $(FASM_FLAGS)
else ifeq ($(HOST),windows)
FASM_INCLUDE=$(KOLIBRIOS)\kernel\trunk;$(KOLIBRIOS)\programs\develop\libraries\libcrash\hash
FASM=set INCLUDE=$(FASM_INCLUDE)&&$(FASM_EXE) $(FASM_FLAGS)
else
$(error your OS is not supported)
endif
ifeq ($(HOST),linux)
all: umka_shell umka_fuse umka_os umka_gen_devices_dat umka.sym umka.prp \
umka.lst tags covpreproc default.skn skin.skn
else ifeq ($(HOST),windows)
all: umka_shell umka.sym umka.prp \
umka.lst default.skn skin.skn
else
$(error your OS is not supported)
endif
.PHONY: test
@ -38,7 +62,7 @@ covpreproc: covpreproc.c
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
umka_shell: umka_shell.o umka.o shell.o trace.o trace_lbr.o vdisk.o vnet.o \
lodepng.o pci.o thread.o util.o getopt.o isatty.o
lodepng.o pci.o thread.o util.o getopt.o
$(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld
umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o pci.o thread.o
@ -52,17 +76,16 @@ umka_gen_devices_dat: umka_gen_devices_dat.o umka.o pci.o thread.o util.o
$(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld
umka.o umka.fas: umka.asm
INCLUDE="$(KOLIBRIOS)/kernel/trunk;$(KOLIBRIOS)/programs/develop/libraries/libcrash/hash" \
$(FASM) $< umka.o -s umka.fas -m 2000000
$(FASM) $< umka.o -s umka.fas
shell.o: shell.c
$(CC) $(CFLAGS_32) -c $<
thread.o: linux/thread.c
thread.o: $(HOST)/thread.c
$(CC) $(CFLAGS_32) -c $<
pci.o: linux/pci.c
$(CC) $(CFLAGS_32) -c $<
pci.o: $(HOST)/pci.c
$(CC) $(CFLAGS_32) -std=gnu11 -c $<
lodepng.o: lodepng.c lodepng.h
$(CC) $(CFLAGS_32) -c $<
@ -70,9 +93,6 @@ lodepng.o: lodepng.c lodepng.h
getopt.o: getopt.c getopt.h
$(CC) $(CFLAGS_32) -c $<
isatty.o: isatty.c isatty.h
$(CC) $(CFLAGS_32) -c $<
util.o: util.c util.h umka.h
$(CC) $(CFLAGS_32) -c $<

View File

@ -35,7 +35,6 @@
#include <sys/select.h>
#endif
#include "isatty.h"
#include "getopt.h"
#include "vdisk.h"
#include "vnet.h"
@ -45,7 +44,7 @@
#include "util.h"
#include "lodepng.h"
#define PATH_MAX 4096
//#define PATH_MAX 4096
#define FGETS_BUF_LEN 4096
#define MAX_COMMAND_ARGS 42
#define PRINT_BYTES_PER_LINE 32

View File

@ -1,7 +1,7 @@
ifndef COVERAGE
UMKA_SHELL=../umka_shell
UMKA_SHELL ?= ../umka_shell
else
UMKA_SHELL=sudo taskset 1 ../umka_shell -c
UMKA_SHELL ?= sudo taskset 1 ../umka_shell -c
endif
xfs_tests := $(addsuffix .out.log, $(basename $(wildcard *\#xfs_*.t)))
@ -48,9 +48,14 @@ arp: $(arp_tests)
acpi: $(acpi_tests)
%.out.log: %.t
$(UMKA_SHELL) < $*.t > $@
$(UMKA_SHELL) -i $*.t
ifeq ($(HOST),linux)
@ cmp $*.out.log $*.ref.log
@ if [ -f "$*.ref.png" ]; then cmp $*.out.png $*.ref.png; fi
else
@ comp /M $*.out.log $*.ref.log
# @ if [ -f "$*.ref.png" ]; then cmp $*.out.png $*.ref.png; fi
endif
collect_coverage:
../covpreproc ../umka.lst 0x34 coverage.* > ../umka.cov

View File

@ -1,9 +1,11 @@
; TODO: SPDX
if defined WIN32
if HOST eq windows
format MS COFF
else
else if HOST eq linux
format ELF
else
error "Your OS is not supported"
end if
; win32:
@ -21,7 +23,7 @@ end if
; pubsym name, "name", 20 -> public name as "name"
; pubsym name, "name", no_mangle -> public name as "name"
macro pubsym name, marg1, marg2 {
if defined WIN32
if HOST eq windows
if marg1 eq no_mangle
public name
else if marg1 eqtype 20
@ -37,12 +39,14 @@ macro pubsym name, marg1, marg2 {
else
public name as '_' # `name
end if
else
else if HOST eq linux
if marg1 eqtype 'string'
public name as marg1
else
public name
end if
else
error "Your OS is not supported"
end if
}
@ -53,14 +57,16 @@ macro pubsym name, marg1, marg2 {
; extrn name -> extrn name
; extrn name, 20 -> extrn name
macro extrn name, [argsize] {
if defined WIN32
if HOST eq windows
if argsize eqtype 20
extrn '_' # `name # '@' # `argsize as name
else
extrn '_' # `name as name
end if
else
else if HOST eq linux
extrn name
else
error "Your OS is not supported"
end if
}
@ -192,11 +198,13 @@ include 'macros.inc'
macro diff16 msg,blah2,blah3 {
if msg eq "end of .data segment"
if defined WIN32
if HOST eq windows
section '.bss.8k' writeable align 8192
else
else if HOST eq linux
; fasm doesn't align on 65536, but ld script does
section '.bss.aligned65k' writeable align 65536
else
error "Your OS is not supported"
end if
bss_base:
end if
@ -683,14 +691,14 @@ endp
proc sys_msg_board
cmp cl, 0x0d
jz @f
if defined WIN32
if HOST eq windows
extrn putchar
pushad
push ecx
call putchar
pop ecx
popad
else
else if HOST eq linux
pushad
mov eax, SYS_WRITE
mov ebx, STDOUT
@ -700,6 +708,8 @@ else
int 0x80
pop ecx
popad
else
error "Your OS is not supported"
end if
@@:
ret
@ -888,11 +898,13 @@ restore sys_msg_board,delay_ms
coverage_end:
if defined WIN32
if HOST eq windows
section '.data.8k' writeable align 8192
else
else if HOST eq linux
; fasm doesn't align on 65536, but ld script does
section '.data.aligned65k' writeable align 65536
else
error "Your OS is not supported"
end if
pubsym umka_tool
umka_tool dd ?

9
umka.h
View File

@ -3,15 +3,16 @@
#include <inttypes.h>
#include <stddef.h>
#include <sys/types.h>
#define UMKA_PATH_MAX 4096
// TODO: Cleanup
#ifndef _WIN32
#include <signal.h> // for irq0: siginfo_t
#else
typedef int32_t ssize_t;
typedef int64_t off_t;
#define PATH_MAX 255
typedef void siginfo_t
//typedef int32_t ssize_t;
//typedef int64_t off_t;
typedef void siginfo_t;
#endif
#define STDCALL __attribute__((__stdcall__))

View File

@ -1,8 +1,10 @@
#include "pci.h"
#include <stdio.h>
#include <stdint.h>
#include "../umka.h"
char pci_path[PATH_MAX] = ".";
char pci_path[UMKA_PATH_MAX] = ".";
__attribute__((stdcall)) uint32_t pci_read(uint32_t bus, uint32_t dev,
uint32_t fun, uint32_t offset,

View File

@ -1,8 +1,8 @@
#ifndef PCI_H_INCLUDED
#define PCI_H_INCLUDED
#define PATH_MAX 255
#include "../umka.h"
extern char pci_path[PATH_MAX];
extern char pci_path[UMKA_PATH_MAX];
#endif // PCI_H_INCLUDED

View File

@ -1,3 +1,5 @@
#include <stdio.h>
void reset_procmask(void) {
printf("STUB: %s:%d", __FILE__, __LINE__);
}