diff --git a/src/stub/src/arch/i086/Makefile.extra b/src/stub/src/arch/i086/Makefile.extra index 9469f0fa..270381f1 100644 --- a/src/stub/src/arch/i086/Makefile.extra +++ b/src/stub/src/arch/i086/Makefile.extra @@ -1,6 +1,10 @@ # # highly experimental support for i086 using Digital Mars C/C++ # +# $(DM849DIR) +# $(WATCOM) +# /usr/bin/wine +# MAKEFLAGS += -rR .SUFFIXES: @@ -29,85 +33,19 @@ include $(top_srcdir)/src/stub/Makefile # /*********************************************************************** -# // method-lzma +# // # ************************************************************************/ -lzma_d_c% : tc_list = method-lzma arch-i086 default -lzma_d_c% : tc_bfdname = +DOSBOX = true +DOSBOX = dosbox +DOSBOX = /usr/bin/time -p dosbox -exit -# gcc -c := tc.arch-i086.gcc -$c += -MF /dev/null -$c += -Wall -W -$c += -I$(UPX_LZMADIR) -$c += -I$(top_srcdir)/src - -# Digital Mars C/C++ 8.49 -# http://www.digitalmars.com/download/freecompiler.html -ifneq ($(wildcard $(DM849DIR)/bin/.),) -c := tc.method-lzma.dmc -$c = @$(WINEENV) CFLAGS='$(DMC)' wine cmd.exe /c tmp/dmc.bat -$c += -ms -R -$c += -NS -$c += -w- -w7 -r -DMC := -o -0 -DMC += -D__INT_MAX__=32767 -DMC += -I$(shell winepath -s z:$(realpath $(UPX_LZMADIR))) -DMC += -I$(shell winepath -s z:$(realpath $(top_srcdir)/src)) -endif - -TMP_DEPS = tmp/.tmp-stamp tmp/bcc.bat tmp/cl.bat tmp/dmc.bat - -lzma_d_c%.S : lzma_d_c%.i cleanasm.py $(MAKEFILE_LIST) - python cleanasm.py --label-prefix=$(LABEL_PREFIX) $< $@ - -ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),) -ifneq ($(wildcard $(DM849DIR)/bin/.),) -ifneq ($(wildcard $(WATCOM)/binl/.),) -ifneq ($(wildcard /usr/bin/wine),) - -lzma_d_c%.i : tmp/lzma_d_c%.i - cp $< $@ - -tmp/lzma_d_c%.i : lzma_d_c.c wdis2gas.py $(MAKEFILE_LIST) $(TMP_DEPS) - rm -f tmp/$T.a tmp/$T.o tmp/$T.obj -# compile - $(call tc,dmc) $(PP_FLAGS) -c -otmp/$T_dm.obj $< - $(call tc,wdis) tmp/$T_dm.obj | $(RTRIM) > tmp/$T_dm.obj.disasm -## $(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T_wc.obj $< -## $(call tc,wdis) tmp/$T_wc.obj | $(RTRIM) > tmp/$T.obj.disasm -## $(call tc,bcc) $(PP_FLAGS) -c -otmp/$T_bc.obj $< -## $(call tc,wdis) tmp/$T_bc.obj | $(RTRIM) > tmp/$T_bc.obj.disasm -## $(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T_vc.obj $< -## $(call tc,wdis) tmp/$T_vc.obj | $(RTRIM) > tmp/$T_vc.obj.disasm -# convert - python wdis2gas.py tmp/$T_dm.obj.disasm tmp/$T.S - $(call tc,gcc) -c -o tmp/$T.o tmp/$T.S - $(call tc,f-objstrip,tmp/$T.o) - $(call tc,objdump) -b elf32-i386 -m i8086 -M intel -dr -j .text.LzmaDecode --no-show -w tmp/$T.o | $(RTRIM) | perl -pe 's/DWORD/dword/g; s/WORD/word/g; s/BYTE/byte/g; s/PTR/ptr/g;' > $@ - -.PRECIOUS: lzma_d_cf.i lzma_d_cs.i -.PRECIOUS: tmp/lzma_d_cf.i tmp/lzma_d_cs.i - -lzma_d_cf.% : PP_FLAGS = -DFAST -lzma_d_cs.% : PP_FLAGS = -DSMALL -lzma_d_cf.% : LABEL_PREFIX = .Lf -lzma_d_cs.% : LABEL_PREFIX = .Ls - -endif -endif -endif -endif - - -# /*********************************************************************** -# // cc_test -# ************************************************************************/ - -CC_TEST_DEPS = $(MAKEFILE_LIST) $(TMP_DEPS) WINEENV = env WINEENV = env -i DISPLAY='$(DISPLAY)' HOME='$(HOME)' PATH='$(PATH)' USER='$(USER)' +winedir_s = $(shell winepath -s z:$(realpath $1)) +winedir_w = $(shell winepath -w $(realpath $1)) + # work around limitations of wine's cmd.exe define mkbat echo -E '@set PATH=$3;%PATH%' > $1 @@ -123,8 +61,7 @@ define mkbat $(UNIX2DOS) $1 endef -winedir_s = $(shell winepath -s z:$(realpath -f -n $1)) -winedir_w = $(shell winepath -w $(realpath -f -n $1)) +TMP_DEPS = tmp/.tmp-stamp tmp/bcc.bat tmp/cl.bat tmp/dmc.bat tmp/bcc.bat: tmp/.tmp-stamp $(MAKEFILE_LIST) @$(call mkbat,$@,bcc.exe,$(call winedir_w,$(BC502DIR)/bin)) @@ -133,9 +70,64 @@ tmp/cl.bat: tmp/.tmp-stamp $(MAKEFILE_LIST) tmp/dmc.bat: tmp/.tmp-stamp $(MAKEFILE_LIST) @$(call mkbat,$@,dmc.exe,$(call winedir_w,$(DM849DIR)/bin)) + +# /*********************************************************************** +# // method-lzma +# ************************************************************************/ + +lzma_d_c% : tc_list = method-lzma arch-i086 default +lzma_d_c% : tc_bfdname = + +# gcc +c := tc.arch-i086.gcc +$c += -MF /dev/null +$c += -Wall -W +$c += -I$(UPX_LZMADIR) +$c += -I$(top_srcdir)/src + +# Borland C/C++ 5.02 +ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),) +c := tc.method-lzma.bcc +$c = @$(WINEENV) wine cmd.exe /c tmp/bcc.bat +$c += -ms +$c += -O1 -1 +$c += -w +$c += -D__INT_MAX__=32767 +$c += -I$(subst \,/,$(call winedir_w,$(UPX_LZMADIR)/C/7zip/Compress/LZMA_C)) +$c += -I$(top_srcdir)/src +endif + +# Digital Mars C/C++ 8.49 +# http://www.digitalmars.com/download/freecompiler.html +ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),) +c := tc.method-lzma.dmc +$c = @$(WINEENV) CFLAGS='$(DMC)' wine cmd.exe /c tmp/dmc.bat +$c += -ms -R +$c += -NS +$c += -w- -w7 -r +DMC := -o -0 +DMC += -D__INT_MAX__=32767 +DMC += -I$(call winedir_w,$(UPX_LZMADIR)) +DMC += -I$(call winedir_w,$(top_srcdir)/src) +endif + +# Visual C/C++ 1.52 (8.00c) +ifneq ($(wildcard $(VC152DIR)/bin/cl.exe),) +c := tc.method-lzma.cl +$c = @$(WINEENV) CL='$(CL)' wine cmd.exe /c tmp/cl.bat +$c += -AS -Gd +$c += -Gy +$c += -O2 -Gf -Gs -G0 +$c += -W4 +CL := -nologo +CL += -D__INT_MAX__=32767 +CL += -I$(call winedir_s,$(UPX_LZMADIR)) +CL += -I$(call winedir_s,$(top_srcdir)/src) +endif + # Open Watcom C/C++ 1.6 # http://openwatcom.com/ -ifneq ($(wildcard $(WATCOM)/binl/.),) +ifneq ($(wildcard $(WATCOM)/binl/wcl),) c := tc.method-lzma.wcl $c = PATH='$(WATCOM)/binl:$(PATH)' $(WATCOM)/binl/wcl -zq -bt=dos $c += -ms -ecc @@ -147,103 +139,148 @@ $c += -I$(UPX_LZMADIR) $c += -I$(top_srcdir)/src endif -# Borland C/C++ 5.02 -ifneq ($(wildcard $(BC502DIR)/bin/.),) -c := tc.method-lzma.bcc -$c = @$(WINEENV) wine cmd.exe /c tmp/bcc.bat -$c += -ms -$c += -O1 -1 -$c += -w -$c += -D__INT_MAX__=32767 -##$c += -I$(subst \,/,$(shell winepath -s z:$(realpath $(UPX_LZMADIR)))) -$c += -I$(subst \,/,$(shell winepath -s z:$(realpath $(UPX_LZMADIR)/C/7zip/Compress/LZMA_C))) -$c += -I$(top_srcdir)/src +lzma_d_c%.S : lzma_d_c%.i cleanasm.py $(MAKEFILE_LIST) + python cleanasm.py --label-prefix=$(LABEL_PREFIX) $< $@ + +ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),) +ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),) +ifneq ($(wildcard $(WATCOM)/binl/wcl),) +ifneq ($(wildcard /usr/bin/wine),) + +lzma_d_c%.i : tmp/lzma_d_c%.i + cp $< $@ + +tmp/lzma_d_c%.i : lzma_d_c.c wdis2gas.py $(MAKEFILE_LIST) $(TMP_DEPS) + rm -f tmp/$T*.i tmp/$T*.o tmp/$T*.obj tmp/$T*.S +# compile +ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),) +## $(call tc,bcc) $(PP_FLAGS) -c -otmp/$T_bc.obj $< +## $(call tc,wdis) tmp/$T_bc.obj | $(RTRIM) > tmp/$T_bc.obj.disasm +endif +ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),) + $(call tc,dmc) $(PP_FLAGS) -c -otmp/$T_dm.obj $< + $(call tc,wdis) tmp/$T_dm.obj | $(RTRIM) > tmp/$T_dm.obj.disasm +endif +ifneq ($(wildcard $(VC152DIR)/bin/cl.exe),) + $(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T_vc.obj $< + $(call tc,wdis) tmp/$T_vc.obj | $(RTRIM) > tmp/$T_vc.obj.disasm +endif +ifneq ($(wildcard $(WATCOM)/binl/wcl),) + $(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T_wc.obj $< + $(call tc,wdis) tmp/$T_wc.obj | $(RTRIM) > tmp/$T_wc.obj.disasm +endif +# convert + python wdis2gas.py tmp/$T_dm.obj.disasm tmp/$T.S + $(call tc,gcc) -c -o tmp/$T.o tmp/$T.S + $(call tc,f-objstrip,tmp/$T.o) + $(call tc,objdump) -b elf32-i386 -m i8086 -M intel -dr -j .text.LzmaDecode --no-show -w tmp/$T.o | $(RTRIM) | perl -pe 's/DWORD/dword/g; s/WORD/word/g; s/BYTE/byte/g; s/PTR/ptr/g;' > $@ + +.PRECIOUS: lzma_d_cf.i lzma_d_cs.i +.PRECIOUS: tmp/lzma_d_cf.i tmp/lzma_d_cs.i + +endif +endif +endif endif -# Visual C/C++ 1.52 (8.00c) -ifneq ($(wildcard $(VC152DIR)/bin/.),) -c := tc.method-lzma.cl -$c = @$(WINEENV) CL='$(CL)' wine cmd.exe /c tmp/cl.bat -$c += -AS -Gd -$c += -Gy -$c += -O2 -Gf -Gs -G0 -$c += -W4 -CL := -nologo -CL += -D__INT_MAX__=32767 -CL += -I$(shell winepath -s z:$(realpath $(UPX_LZMADIR))) -CL += -I$(shell winepath -s z:$(realpath $(top_srcdir)/src)) -endif +lzma_d_cf.% : PP_FLAGS = -DFAST +lzma_d_cs.% : PP_FLAGS = -DSMALL +lzma_d_cf.% : LABEL_PREFIX = .Lf +lzma_d_cs.% : LABEL_PREFIX = .Ls -ifneq ($(wildcard $(WATCOM)/binl/.),) -cc_test_wc : tc_list = method-lzma arch-i086 default -cc_test_wc: cc_test.c $(CC_TEST_DEPS) - $(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T.obj $< - $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm -## cat tmp/$T.obj.disasm -endif +# /*********************************************************************** +# // cc_test +# ************************************************************************/ -ifneq ($(wildcard $(BC502DIR)/bin/.),) +ifneq ($(wildcard $(WATCOM)/binl/wdis),) + +CC_TEST_DEPS = $(MAKEFILE_LIST) $(TMP_DEPS) + +ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),) cc_test_bc : tc_list = method-lzma arch-i086 default cc_test_bc: cc_test.c $(CC_TEST_DEPS) $(call tc,bcc) $(PP_FLAGS) -c -otmp/$T.obj $< $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm -## cat tmp/$T.obj.disasm +cc_test_all: cc_test_bc endif -ifneq ($(wildcard $(DM849DIR)/bin/.),) +ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),) cc_test_dm : tc_list = method-lzma arch-i086 default cc_test_dm: cc_test.c $(CC_TEST_DEPS) $(call tc,dmc) $(PP_FLAGS) -c -otmp/$T.obj $< $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm -## cat tmp/$T.obj.disasm +cc_test_all: cc_test_dm endif -ifneq ($(wildcard $(VC152DIR)/bin/.),) +ifneq ($(wildcard $(VC152DIR)/bin/cl.exe),) cc_test_vc : tc_list = method-lzma arch-i086 default cc_test_vc: cc_test.c $(CC_TEST_DEPS) $(call tc,cl) $(PP_FLAGS) -c -Fotmp/$T.obj $< $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm -## cat tmp/$T.obj.disasm +cc_test_all: cc_test_vc endif +ifneq ($(wildcard $(WATCOM)/binl/wcl),) +cc_test_wc : tc_list = method-lzma arch-i086 default +cc_test_wc: cc_test.c $(CC_TEST_DEPS) + $(call tc,wcl) $(PP_FLAGS) -c -fo=tmp/$T.obj $< + $(call tc,wdis) tmp/$T.obj | $(RTRIM) > tmp/$T.obj.disasm +cc_test_all: cc_test_wc +endif + +.PHONY: cc_test_all + +endif # wdis + # /*********************************************************************** # // l_test # ************************************************************************/ L_TEST_DEPS = lzma_d_c.c $(MAKEFILE_LIST) $(TMP_DEPS) -DOSBOX = /usr/bin/time -v dosbox -exit -DOSBOX = dosbox -tmp/l_t_gcc_i386.% : tc_list = arch-i086 default -tmp/l_t_gcc_i386.out: l_test.c $(L_TEST_DEPS) +tmp/l_test_gcc_i386.% : tc_list = arch-i086 default +tmp/l_test_gcc_i386.out: l_test.c $(L_TEST_DEPS) $(call tc,gcc) -O0 -g -o $@ $< ./$@ +l_test_all: tmp/l_test_gcc_i386.out -tmp/l_t_bc.% : tc_list = method-lzma arch-i086 default -tmp/l_t_bc.exe: l_test.c $(L_TEST_DEPS) +ifneq ($(wildcard $(BC502DIR)/bin/bcc.exe),) +tmp/l_test_bc.% : tc_list = method-lzma arch-i086 default +tmp/l_test_bc.exe: l_test.c $(L_TEST_DEPS) $(call tc,bcc) -o$(subst /,\\,$@) $< @rm -f l_test.o l_test.obj - $(DOSBOX) $@ + cp -p $@ tmp/test.exe && $(DOSBOX) tmp/test.exe +##l_test_all: tmp/l_test_bc.exe +endif -tmp/l_t_dm.% : tc_list = method-lzma arch-i086 default -tmp/l_t_dm.exe: l_test.c $(L_TEST_DEPS) +ifneq ($(wildcard $(DM849DIR)/bin/dmc.exe),) +tmp/l_test_dm.% : tc_list = method-lzma arch-i086 default +tmp/l_test_dm.exe: l_test.c $(L_TEST_DEPS) $(call tc,dmc) -ml -o$(subst /,\\,$@) $< @rm -f l_test.o l_test.obj - $(DOSBOX) $@ + cp -p $@ tmp/test.exe && $(DOSBOX) tmp/test.exe +l_test_all: tmp/l_test_dm.exe +endif -tmp/l_t_wc.% : tc_list = method-lzma arch-i086 default -tmp/l_t_wc.exe: l_test.c $(L_TEST_DEPS) - $(call tc,wcl) -fe=$@ $< - @rm -f l_test.o l_test.obj - $(DOSBOX) $@ - -tmp/l_t_vc.% : tc_list = method-lzma arch-i086 default -tmp/l_t_vc.exe: l_test.c $(L_TEST_DEPS) +ifneq ($(wildcard $(VC152DIR)/bin/cl.exe),) +tmp/l_test_vc.% : tc_list = method-lzma arch-i086 default +tmp/l_test_vc.exe: l_test.c $(L_TEST_DEPS) $(call tc,cl) -Fe$(subst /,\\,$@) $< @rm -f l_test.o l_test.obj - $(DOSBOX) $@ + cp -p $@ tmp/test.exe && $(DOSBOX) tmp/test.exe +l_test_all: tmp/l_test_vc.exe +endif -.PHONY: tmp/l_t_gcc_i386.out tmp/l_t_bc.exe tmp/l_t_dm.exe tmp/l_t_wc.exe tmp/l_t_vc.exe +ifneq ($(wildcard $(WATCOM)/binl/wcl),) +tmp/l_test_wc.% : tc_list = method-lzma arch-i086 default +tmp/l_test_wc.exe: l_test.c $(L_TEST_DEPS) + $(call tc,wcl) -fe=$@ $< + @rm -f l_test.o l_test.obj + cp -p $@ tmp/test.exe && $(DOSBOX) tmp/test.exe +l_test_all: tmp/l_test_wc.exe +endif + +.PHONY: l_test_all diff --git a/src/stub/src/arch/i086/cleanasm.py b/src/stub/src/arch/i086/cleanasm.py index 0d2aad12..5ebd1349 100644 --- a/src/stub/src/arch/i086/cleanasm.py +++ b/src/stub/src/arch/i086/cleanasm.py @@ -63,6 +63,7 @@ def main(argv): else: assert 0, ("getopt problem:", opt, optarg, xopts, args) # + assert opts.label_prefix assert len(args) == 2 ifile = args[0] ofile = args[1]