-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
68 lines (52 loc) · 2.42 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ROOTDIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))/../..))
OUTDIR := $(ROOTDIR)/target
DOSOUTDIR := $(ROOTDIR)/target/dos
KALOS_SRCDIR := $(ROOTDIR)/src
KALOS_SOURCES := $(wildcard $(KALOS_SRCDIR)/*.c) $(wildcard $(KALOS_SRCDIR)/modules/*.c)
KALOS_OBJECTS := $(patsubst $(KALOS_SRCDIR)/%.c,$(DOSOUTDIR)/kalos/%.o,$(KALOS_SOURCES))
SRCDIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES := $(wildcard $(SRCDIR)/*.c)
OBJECTS := $(patsubst $(SRCDIR)/%.c,$(DOSOUTDIR)/%.o,$(SOURCES))
SPACE_CHAR := $(subst ,, )
COMMA_CHAR := ,
.PHONY: all clean
all: $(DOSOUTDIR)/compiler.exe $(DOSOUTDIR)/example.exe
clean:
rm -rf $(DOSOUTDIR)
WATCOM_MODEL=m
CFLAGS=-c -march=i86 -Wall -std=c99 \
-fno-writable-strings -fnonconst-initializers -fshort-enum -ffunction-sections \
-mcmodel=$(WATCOM_MODEL) -O3 -frerun-optimizer -floop-optimize -funroll-loops -fno-stack-check
WATCOM=docker run --rm \
-v $(ROOTDIR)/src:/src/ \
-v $(DOSOUTDIR):/obj/ \
-v $(OUTDIR):/out/ \
-v $(SRCDIR):/src2/ \
mmastrac/openwatcom:2021-05-01
CC=$(WATCOM) owcc
$(SRCDIR)/dos_dispatch.inc: $(OUTDIR)/$(OS)/compiler $(SRCDIR)/dos.kidl
$(OUTDIR)/$(OS)/compiler dispatch $(SRCDIR)/dos.kidl $(SRCDIR)/dos_dispatch.inc
$(SRCDIR)/dos_script.inc: $(OUTDIR)/$(OS)/compiler $(SRCDIR)/dos.kidl
$(OUTDIR)/$(OS)/compiler compile $(SRCDIR)/dos.kidl $(SRCDIR)/dos.kalos $(DOSOUTDIR)/dos_script.bin
xxd -i < $(DOSOUTDIR)/dos_script.bin > $(SRCDIR)/dos_script.inc
$(DOSOUTDIR)/kalos/%.o: $(KALOS_SRCDIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -I/src /src/$(<:$(KALOS_SRCDIR)/%=%) -o /obj/$(@:$(DOSOUTDIR)/%=%)
$(DOSOUTDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/dos_dispatch.inc $(SRCDIR)/dos_script.inc
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -I/src /src2/$(<:$(SRCDIR)/%=%) -o /obj/$(@:$(DOSOUTDIR)/%=%)
$(DOSOUTDIR)/compiler.exe.lst: $(KALOS_OBJECTS) $(DOSOUTDIR)/kalos/compiler/compiler_main.o $(DOSOUTDIR)/kalos/compiler/compiler_idl.o
echo $(patsubst $(DOSOUTDIR)/%.o,/obj/%.o,$^) > $@
$(DOSOUTDIR)/example.exe.lst: $(KALOS_OBJECTS) $(OBJECTS)
echo $(patsubst $(DOSOUTDIR)/%.o,/obj/%.o,$^) > $@
$(DOSOUTDIR)/%.exe: $(DOSOUTDIR)/%.exe.lst
$(WATCOM) wlink \
name /out/dos/$(notdir $@) \
system dos \
file $(subst $(SPACE_CHAR),$(COMMA_CHAR),$(shell cat $^)) \
library clib$(WATCOM_MODEL) \
option map=/out/dos/$(notdir $@).map \
option showdead \
option nodefaultlibs \
option eliminate > /dev/null