-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
139 lines (118 loc) · 4.82 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
##
## Copyright (c) 2018-2024 Stéphane Micheloud
##
## Licensed under the MIT License.
##
##############################################################################
DEBUG ?= false
TOOLSET ?= xds
include ../Makefile.inc
ADWM2_SYM_DIR = $(subst \,/,$(ADWM2_HOME))/ascii/winamd64sym
LIB_DIR = ../lib/$(TOOLSET)
SOURCE_DIR = src
SOURCE_DEF_DIR = src/main/def
SOURCE_MOD_DIR = src/main/mod
TARGET_DIR = target
TARGET_DEF_DIR = $(TARGET_DIR)/def
TARGET_MOD_DIR = $(TARGET_DIR)/mod
## library dependencies
TARGET_BIN_DIR = $(TARGET_DIR)/bin
TARGET_SYM_DIR = $(TARGET_DIR)/sym
##############################################################################
## main rules
DEFS = $(shell [ -d "$(SOURCE_DEF_DIR)" ] && $(FIND) "$(SOURCE_DEF_DIR)" -type f -name "*.def")
MODS = $(shell $(FIND) "$(SOURCE_MOD_DIR)" -type f -name "*.mod")
APP_NAME = Hello
TARGET = $(TARGET_DIR)/$(APP_NAME)$(TARGET_EXT)
M2C_OPTS =
LINKER_OPTS_FILE = $(TARGET_DIR)/linker_opts.txt
all: build
build: build_$(TOOLSET)
build_adw: $(DEFS) $(MODS)
if [ -d "$(SOURCE_DEF_DIR)" ]; then \
[ -d "$(TARGET_DEF_DIR)" ] || "$(MKDIR)" -p "$(TARGET_DEF_DIR)"; \
"$(CP)" "$(SOURCE_DEF_DIR)"/*.def "$(TARGET_DEF_DIR)"; \
fi
[ -d "$(TARGET_MOD_DIR)" ] || "$(MKDIR)" -p "$(TARGET_MOD_DIR)"
@$(CP) $(SOURCE_MOD_ADW_DIR)/*.mod "$(TARGET_MOD_DIR)"
[ -d "$(TARGET_SYM_DIR)" ] || "$(MKDIR)" -p "$(TARGET_SYM_DIR)"
@$(CP) $(subst \,/,$(ADWM2_HOME))/Unicode/winamd64sym/*.sym "$(TARGET_SYM_DIR)"
$(CP) ../lib/adw/*.sym "$(TARGET_SYM_DIR)"
$(eval ABS_TARGET_SYM_DIR := $(shell realpath $(TARGET_SYM_DIR)))
$(eval M2C_OPTS := "-sym:$(shell cygpath -w $(ABS_TARGET_SYM_DIR))")
##for f in $(TARGET_MOD_DIR)/*.mod; do \
## @$(ECHO) $$f \
"$(M2C)" $(M2C_OPTS) "$(shell cygpath -w $(TARGET_MOD_DIR)/Factorial.mod)"
##done
$(eval ABS_TARGET_DIR := $(shell realpath $(TARGET_DIR)))
$(eval LINKE_OPTS_FILE := $(shell cygpath -m $(ABS_TARGET_DIR))/linker_opts.txt)
##@$(ECHO) "-EXETYPE:exe"
@$(ECHO) "-MACHINE:X86_64" > "$(LINKER_OPTS_FILE)"
@$(ECHO) "-SUBSYSTEM:CONSOLE" >> "$(LINKER_OPTS_FILE)"
@$(ECHO) "-MAP:$(TARGET_DIR)\$(APP_NAME)" >> "$(LINKER_OPTS_FILE)"
@$(ECHO) "-OUT:$(TARGET_FILE) >> "$(LINKER_OPTS_FILE)"
##for f in $(TARGET_MOD_DIR)/*.obj; do \
$(ECHO) $$f >> "$(LINKER_OPTS_FILE)"; \
##done
@$(ECHO) "$(ADWM2_HOME)\rtl-win-amd64.lib" >> "$(LINKER_OPTS_FILE)"
@$(ECHO) "$(ADWM2_HOME)\win64api.lib" >> "$(LINKER_OPTS_FILE)"
"$(SBLINK)" "@$(LINKER_OPTS_FILE)"
build_xds: $(DEFS) $(MODS)
if [ -d "$(SOURCE_DEF_DIR)" ]; then \
[ -d "$(TARGET_DEF_DIR)" ] || "$(MKDIR)" -p "$(TARGET_DEF_DIR)"; \
"$(CP)" "$(SOURCE_DEF_DIR)"/*.def "$(TARGET_DEF_DIR)"; \
fi
[ -d "$(TARGET_MOD_DIR)" ] || "$(MKDIR)" -p "$(TARGET_MOD_DIR)"
@$(CP) $(SOURCE_MOD_DIR)/*.mod "$(TARGET_MOD_DIR)"
[ -d "$(TARGET_BIN_DIR)" ] || "$(MKDIR)" -p "$(TARGET_BIN_DIR)"
@$(CP) $(LIB_DIR)/*.dll "$(TARGET_BIN_DIR)"
@$(CP) $(LIB_DIR)/*.lib "$(TARGET_BIN_DIR)"
[ -d "$(TARGET_SYM_DIR)" ] || "$(MKDIR)" -p "$(TARGET_SYM_DIR)"
@$(CP) $(LIB_DIR)/*.sym "$(TARGET_SYM_DIR)"
@# we compute the absolute path for PRJ_FILE since we use TARGET_DIR as current directory.
$(eval ABS_TARGET_DIR := $(shell realpath $(TARGET_DIR)))
$(eval PRJ_FILE := $(shell cygpath -m $(ABS_TARGET_DIR))/$(APP_NAME).prj)
@##[ -f "$(PRJ_FILE)" ] || "$(RM)" "$(PRJ_FILE)"
@$(ECHO) "%% generated on $(shell date '+%F %T')" > "$(PRJ_FILE)"
if $(DEBUG); then \
@$(ECHO) "%% debug ON" >> "$(PRJ_FILE)"; \
@$(ECHO) "-gendebug+" >> "$(PRJ_FILE)"; \
@$(ECHO) "-genhistory+" >> "$(PRJ_FILE)"; \
@$(ECHO) "-lineno+" >> "$(PRJ_FILE)"; \
fi
@$(ECHO) "-cpu = 486" >> "$(PRJ_FILE)"
@$(ECHO) "-lookup = *.sym = sym;$(XDSM2_HOME)\sym" >> "$(PRJ_FILE)"
@$(ECHO) "-lookup = *.dll|*.lib = bin;$(XDSM2_HOME)\bin" >> "$(PRJ_FILE)"
@$(ECHO) "-m2" >> "$(PRJ_FILE)"
@$(ECHO) "-verbose" >> "$(PRJ_FILE)"
@$(ECHO) "-werr" >> "$(PRJ_FILE)"
for f in $(TARGET_MOD_DIR)/*.mod; do \
$(ECHO) "!module $${f/$(TARGET_DIR)\//}" >> "$(PRJ_FILE)"; \
done
for f in $(TARGET_BIN_DIR)/*.lib; do \
[ -f "$$f" ] || continue; \
$(ECHO) "!module $${f/$(TARGET_DIR)\//}" >> "$(PRJ_FILE)"; \
done
cd "$(TARGET_DIR)" && "$(XC)" =p "$(PRJ_FILE)"
clean:
"$(RM)" -rf "$(TARGET_DIR)"
"$(RM)" -f "$(APP_NAME).err" "errinfo.$$$$$$"
run: build
"$(TARGET)"
help:
@$(ECHO) "Usage: make all|build|clean|help|run"
@$(ECHO) ""
@$(ECHO) " Subcommands:"
@$(ECHO) " all alias for build"
@$(ECHO) " build compile Modula-2 source files"
@$(ECHO) " clean delete generated files"
@$(ECHO) " help print this help message"
@$(ECHO) " run execute main program \"$(APP_NAME)$(TARGET_EXT)\""
@$(ECHO) ""
@$(ECHO) " Variables:"
@$(ECHO) " TOOLSET=<name> where name=adw,xds"
##############################################################################
## phony
.PHONY: all build clean help run test
.SUFFIXES:
.SUFFIXES: .def .exe .mod .obj .prj