From c42fb54bc6ac4f2bb11e0baaebd914c6de98568b Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sat, 17 Jun 2006 18:54:11 +0200 Subject: [PATCH] Assorted cleanups. --- .hgignore | 7 ++++- Makefile | 28 +++++++++++--------- doc/Makefile | 43 +++++++++++++------------------ src/Makefile | 6 ++--- src/stub/Makefile | 54 ++++++++++++++++++++++----------------- src/stub/scripts/bin2h.py | 47 +++++++++++++++++++++++++++------- 6 files changed, 111 insertions(+), 74 deletions(-) diff --git a/.hgignore b/.hgignore index 67017746..08f87982 100644 --- a/.hgignore +++ b/.hgignore @@ -18,19 +18,24 @@ syntax: glob *.py[cdo] *.so *.res +*.swp *.ttp doc/*.1 doc/*.doc doc/*.html +doc/*.man +doc/*.ps +doc/*.tex src/MMakefile src/compress_nrv* src/*.rc stub/MMakefile +stub/**.*stamp stub/tmp* -stub/.*stamp +stub/**/tmp* stub/tools/armpe/armpe_tester diff --git a/Makefile b/Makefile index 570295c9..30360212 100644 --- a/Makefile +++ b/Makefile @@ -8,28 +8,32 @@ srcdir = . top_srcdir = . +# info: src/stub needs GNU make 3.81 and special build tools +BUILD_STUB = 0 +ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),) +BUILD_STUB = 1 +endif +ifneq ($(wildcard $(HOME)/bin/bin-upx/.),) +BUILD_STUB = 1 +endif +ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.79 3.79.1 3.80),) +BUILD_STUB = 0 +endif + + default: @echo "UPX info: please choose a target for 'make'" all mostlyclean clean distclean maintainer-clean: -ifneq ($(wildcard $(HOME)/local/bin/bin-upx),) - # this needs special build tools +ifeq ($(BUILD_STUB),1) $(MAKE) -C src/stub $@ -else -ifneq ($(wildcard $(HOME)/bin/bin-upx),) - # this needs special build tools - $(MAKE) -C src/stub $@ -endif endif $(MAKE) -C src $@ $(MAKE) -C doc $@ -dist: distclean - false - # automatically generate ChangeLog from Mercurial repo ChangeLog: -ifneq ($(wildcard .hg/data),) +ifneq ($(wildcard .hg/data/.),) hg log --style=changelog > $@ else @echo "UPX info: no hg repo found" @@ -37,5 +41,5 @@ endif .PHONY: default all mostlyclean clean distclean maintainer-clean -.PHONY: dist ChangeLog +.PHONY: ChangeLog diff --git a/doc/Makefile b/doc/Makefile index 301db620..05ead0a2 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -8,29 +8,21 @@ PACKAGE = upx VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h) VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h) -TRIMSPACE = cat -TRIMSPACE = sed -e 's/ *$$//' +TRIMSPACE = sed -e 's/[ ]*$$//' +DETAB2 = sed -e 's/ / /g' BUILT_SOURCES = upx.1 upx.doc upx.html upx.man upx.ps upx.tex BUILT_SOURCES = upx.1 upx.doc upx.html ### -### +### targets ### all: $(BUILT_SOURCES) -mostlyclean: - -rm -f $(BUILT_SOURCES) pod2htm* - -clean: mostlyclean - -distclean: clean - -maintainer-clean: distclean - -.SUFFIXES: .1 .doc .html .man .pod .ps .tex .texi +mostlyclean clean distclean maintainer-clean: + rm -f $(BUILT_SOURCES) pod2htm* .PHONY: all mostlyclean clean distclean maintainer-clean @@ -39,26 +31,27 @@ maintainer-clean: distclean ### rules ### -.pod.1: +.SUFFIXES: .1 .doc .html .man .pod .ps .tex + +%.1 : %.pod pod2man --center=" " --release="$(PACKAGE) $(VERSION)" --date="$(VERSION_DATE)" $< | $(TRIMSPACE) > $@ -.pod.html: -### pod2html $< | $(TRIMSPACE) > $@ - pod2html --noindex $< | $(TRIMSPACE) > $@ - @-rm -f pod2htm* - -.pod.tex: - pod2latex $< - -.pod.doc: +%.doc : %.pod pod2text < $< | $(TRIMSPACE) > $@ -.1.man: +%.html : %.pod + pod2html --noindex $< | $(TRIMSPACE) | $(DETAB2) > $@ + @rm -f pod2htm* + +%.man : %.1 nroff -man $< | $(TRIMSPACE) > $@ -.1.ps: +%.ps : %.1 groff -man $< | $(TRIMSPACE) > $@ +%.tex : %.pod + pod2latex $< + ### ### dependencies diff --git a/src/Makefile b/src/Makefile index c214552c..bedb5ed8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -21,8 +21,8 @@ ifeq ($(firstword $(CXX)),g++) USE_GNUC ?= 1 endif ifeq ($(USE_GNUC),1) -#CXXFLAGS += -O2 -MMD -CXXFLAGS += -g -MMD +CXXFLAGS += -O2 -MMD +##CXXFLAGS += -O0 -g -MMD CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror endif CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) @@ -39,7 +39,7 @@ LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLD endif LIBS += -lucl -lz # you should set envvar UPX_LZMADIR to point to your unpacked lzma443.tar.bz2 -ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip),) +ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),) DEFS += -DWITH_LZMA INCLUDES += -I$(UPX_LZMADIR) endif diff --git a/src/stub/Makefile b/src/stub/Makefile index a85d8ab3..4e9a1275 100644 --- a/src/stub/Makefile +++ b/src/stub/Makefile @@ -17,10 +17,10 @@ $(error GNU make 3.81 or better is required) endif # update $PATH for our special stub build tools -ifneq ($(wildcard $(HOME)/local/bin/bin-upx),) +ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),) export PATH := $(HOME)/local/bin/bin-upx:$(PATH) endif -ifneq ($(wildcard $(HOME)/bin/bin-upx),) +ifneq ($(wildcard $(HOME)/bin/bin-upx/.),) export PATH := $(HOME)/bin/bin-upx:$(PATH) endif @@ -72,14 +72,19 @@ STUBS += powerpc-linux.elf-entry.h STUBS += powerpc-linux.elf-fold.h +ifndef default.targets ifeq ($(wildcard .all-stamp),) -default: +default.targets = +default: $(default.targets) @echo "UPX info: type 'make all' if you have all the required build tools." else -default: all +default.targets = all +default: $(default.targets) +endif endif -all: tmp/.tmp-stamp .all-stamp +all.targets ?= tmp/.tmp-stamp .all-stamp +all: $(all.targets) tmp/.tmp-stamp: @mkdir -p $(dir $@) @echo "timestamp" > $@ @@ -120,6 +125,7 @@ tc.default.nasm += -I$(srcdir)/ -I$(srcdir)/src/ tc.default.nasm += -O99 -w+macro-params -w+macro-selfref -w+number-overflow -w+orphan-labels tc.default.pp-asm = i386-linux-gcc-2.95.3 -E -nostdinc -x assembler-with-cpp -Wall -Wp,-P,-C,-traditional tc.default.pp-nasm = $(tc.default.gpp_inc) --mode=nasm -I$(srcdir)/ -I$(srcdir)/src/ +tc.default.readelf = readelf tc.default.sstrip = sstrip # some common settings for $(tc_list) @@ -242,7 +248,7 @@ i086-dos16.com% : tc_list = i086 default i086-dos16.com.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=nrv2b_loader tmp/$T.bin $@ @@ -255,7 +261,7 @@ i086-dos16.exe% : tc_list = i086 default i086-dos16.exe.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=nrv_loader tmp/$T.bin $@ @@ -268,7 +274,7 @@ i086-dos16.sys% : tc_list = i086 default i086-dos16.sys.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=nrv2b_loader tmp/$T.bin $@ @@ -281,7 +287,7 @@ i386-dos32.djgpp2% : tc_list = i386 default i386-dos32.djgpp2.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=nrv_loader tmp/$T.bin $@ i386-dos32.djgpp2-stubify.h : $(srcdir)/src/$$T.asm @@ -298,7 +304,7 @@ i386-dos32.tmt% : tc_list = i386 default i386-dos32.tmt.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=nrv_loader tmp/$T.bin $@ @@ -311,7 +317,7 @@ i386-dos32.watcom.le% : tc_list = i386 default i386-dos32.watcom.le.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=nrv_loader tmp/$T.bin $@ @@ -337,7 +343,7 @@ tc.i386-linux.elf.objstrip = $(call tc,objcopy) -R .comment -R .note i386-linux.elf-entry.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=linux_i386elf_loader tmp/$T.bin $@ i386-linux.elf-fold.h : tmp/$$T.o tmp/i386-linux.elf-main.o @@ -348,7 +354,7 @@ i386-linux.elf-fold.h : tmp/$$T.o tmp/i386-linux.elf-main.o $(call tc,bin2h) --ident=linux_i386elf_fold tmp/$T.bin $@ tmp/i386-linux.elf-fold.o : $(srcdir)/src/$$T.asm - $(call tc,nasm) -f elf $< -o $@ + $(call tc,nasm) -f elf -l $@.lst $< -o $@ $(call tc,objstrip) $@ tmp/i386-linux.elf-main.o : $(srcdir)/src/$$T.c @@ -365,7 +371,7 @@ tmp/i386-linux.elf-main.o : $(srcdir)/src/$$T.c i386-linux.elf.execve-entry.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=linux_i386exec_loader tmp/$T.bin $@ i386-linux.elf.execve-fold.h : tmp/$$T.o tmp/i386-linux.elf.execve-main.o tmp/i386-linux.elf.execve-upx_itoa.o @@ -376,7 +382,7 @@ i386-linux.elf.execve-fold.h : tmp/$$T.o tmp/i386-linux.elf.execve-main.o tmp/i3 $(call tc,bin2h) --ident=linux_i386exec_fold tmp/$T.bin $@ tmp/i386-linux.elf.execve-fold.o : $(srcdir)/src/$$T.asm - $(call tc,nasm) -f elf $< -o $@ + $(call tc,nasm) -f elf -l $@.lst $< -o $@ $(call tc,objstrip) $@ tmp/i386-linux.elf.execve-main.o : $(srcdir)/src/$$T.c @@ -384,7 +390,7 @@ tmp/i386-linux.elf.execve-main.o : $(srcdir)/src/$$T.c $(call tc,objstrip) $@ tmp/i386-linux.elf.execve-upx_itoa.o: $(srcdir)/src/$$T.asm - $(call tc,nasm) -f elf $< -o $@ + $(call tc,nasm) -f elf -l $@.lst $< -o $@ $(call tc,objstrip) $@ @@ -397,7 +403,7 @@ tmp/i386-linux.elf.execve-upx_itoa.o: $(srcdir)/src/$$T.asm i386-linux.elf.interp-entry.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=linux_i386pti_loader tmp/$T.bin $@ i386-linux.elf.interp-fold.h : tmp/$$T.o tmp/i386-linux.elf.interp-main.o @@ -408,7 +414,7 @@ i386-linux.elf.interp-fold.h : tmp/$$T.o tmp/i386-linux.elf.interp-main.o $(call tc,bin2h) --ident=linux_i386pti_fold tmp/$T.bin $@ tmp/i386-linux.elf.interp-fold.o : $(srcdir)/src/$$T.asm - $(call tc,nasm) -f elf $< -o $@ + $(call tc,nasm) -f elf -l $@.lst $< -o $@ $(call tc,objstrip) $@ tmp/i386-linux.elf.interp-main.o : $(srcdir)/src/$$T.c @@ -425,7 +431,7 @@ tmp/i386-linux.elf.interp-main.o : $(srcdir)/src/$$T.c i386-linux.elf.shell-entry.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=linux_i386sh_loader tmp/$T.bin $@ i386-linux.elf.shell-fold.h : tmp/$$T.o tmp/i386-linux.elf.shell-main.o @@ -436,7 +442,7 @@ i386-linux.elf.shell-fold.h : tmp/$$T.o tmp/i386-linux.elf.shell-main.o $(call tc,bin2h) --ident=linux_i386sh_fold tmp/$T.bin $@ tmp/i386-linux.elf.shell-fold.o : $(srcdir)/src/$$T.asm - $(call tc,nasm) -f elf $< -o $@ + $(call tc,nasm) -f elf -l $@.lst $< -o $@ $(call tc,objstrip) $@ tmp/i386-linux.elf.shell-main.o : $(srcdir)/src/$$T.c @@ -454,7 +460,7 @@ i386-linux.kernel.vmlin% : tc_list = i386 default i386-linux.kernel%.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=nrv_loader tmp/$T.bin $@ @@ -467,7 +473,7 @@ i386-win32.pe% : tc_list = i386 default i386-win32.pe.h : $(srcdir)/src/$$T.asm $(call tc,pp-nasm) --MMD=$@ $< -o tmp/$T.tmp1 $(call tc,app-nasm) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,nasm) -f bin tmp/$T.tmp2 -o tmp/$T.bin + $(call tc,nasm) -f bin -l tmp/$T.bin.lst tmp/$T.tmp2 -o tmp/$T.bin $(call tc,bin2h) --ident=nrv_loader tmp/$T.bin $@ @@ -482,7 +488,7 @@ tc.m68k-atari.tos.asm-a68k = a68k m68k-atari.tos-nrv%.h : $(srcdir)/src/m68k-atari.tos.asm # call gpp_inc to generate .d file - $(call tc,gpp_inc) --MMD=$@ --MF=tmp/$T.i.d $< -o /dev/null + $(call tc,gpp_inc) --mode=c --MMD=$@ --MF=tmp/$T.i.d $< -o /dev/null $(call tc,pp-asm) -D__A68K__ $(PP_FLAGS) $< -o tmp/$T.i $(call tc,asm-a68k) -q -ltmp/$T.o.lst tmp/$T.i -otmp/$T.o $(call tc,o2bin) tmp/$T.o tmp/$T.bin 'UPX1' 'UPX9' @@ -510,7 +516,7 @@ tc.mipsel.r3000-ps1.asm5900 = asm5900 mipsel.r3000-ps1-%.h : $(srcdir)/src/mipsel.r3000-ps1.asm # call gpp_inc to generate .d file - $(call tc,gpp_inc) --MMD=$@ --MF=tmp/$T.tmp1.d $< -o /dev/null + $(call tc,gpp_inc) --mode=c --MMD=$@ --MF=tmp/$T.tmp1.d $< -o /dev/null $(call tc,pp-asm) $(PP_FLAGS) $< -o tmp/$T.tmp1 $(call tc,app-asm5900) tmp/$T.tmp1 tmp/$T.tmp2 $(call tc,asm5900) --nologo -q -ltmp/$T.bin.lst tmp/$T.tmp2 -otmp/$T.bin diff --git a/src/stub/scripts/bin2h.py b/src/stub/scripts/bin2h.py index 214aff1f..4cca09b6 100644 --- a/src/stub/scripts/bin2h.py +++ b/src/stub/scripts/bin2h.py @@ -34,10 +34,11 @@ import getopt, os, re, sys, zlib class opts: dry_run = 0 ident = None + mode = "c" verbose = 0 -def w_header(w, ifile, ofile, n): +def w_header_c(w, ifile, ofile, n): w("/* %s -- created from %s, %d (0x%x) bytes\n" % (os.path.basename(ofile), os.path.basename(ifile), n, n)) w("""\n\ This file is part of the UPX executable compressor. @@ -67,14 +68,14 @@ def w_header(w, ifile, ofile, n): */\n\n\n""") -def w_checksum(w, s, data): +def w_checksum_c(w, s, data): w("#define %s_SIZE %d\n" % (s, len(data))) w("#define %s_ADLER32 0x%08x\n" % (s, 0xffffffffL & zlib.adler32(data))) w("#define %s_CRC32 0x%08x\n" % (s, 0xffffffffL & zlib.crc32(data))) w("\n") -def w_data(w, data): +def w_data_c(w, data): def w_eol(w, i): if i > 0: w(" /* 0x%4x */" % (i - 16)) @@ -93,8 +94,29 @@ def w_data(w, data): w_eol(w, i) +def w_data_nasm(w, data): + def w_eol(w, i): + if i > 0: + w(" ; 0x%04x" % (i - 16)) + w("\n") + + n = len(data) + for i in range(n): + if i % 16 == 0: + w_eol(w, i) + w("db ") + else: + w(",") + w("%3d" % ord(data[i])) + i = n + while i % 16 != 0: + i += 1 + w(" ") + w_eol(w, i) + + def main(argv): - shortopts, longopts = "qv", ["dry-run", "ident=", "quiet", "verbose"] + shortopts, longopts = "qv", ["dry-run", "ident=", "mode=", "quiet", "verbose"] xopts, args = getopt.gnu_getopt(argv[1:], shortopts, longopts) for opt, optarg in xopts: if 0: pass @@ -102,6 +124,7 @@ def main(argv): elif opt in ["-v", "--verbose"]: opts.verbose = opts.verbose + 1 elif opt in ["--dry-run"]: opts.dry_run = opts.dry_run + 1 elif opt in ["--ident"]: opts.ident = optarg + elif opt in ["--mode"]: opts.mode = optarg.lower() else: assert 0, ("getopt problem:", opt, optarg, xopts, args) assert len(args) == 2 @@ -129,13 +152,19 @@ def main(argv): fp = open(ofile, "wb") w = fp.write if opts.verbose >= 0: - w_header(w, ifile, ofile, len(data)) + if opts.mode == "c": + w_header_c(w, ifile, ofile, len(data)) if opts.ident: - w_checksum(w, opts.ident.upper(), data) - w("unsigned char %s[%d] = {\n" % (opts.ident, len(data))) - w_data(w, data) + if opts.mode == "c": + w_checksum_c(w, opts.ident.upper(), data) + w("unsigned char %s[%d] = {\n" % (opts.ident, len(data))) + if opts.mode == "c": + w_data_c(w, data) + elif opts.mode == "nasm": + w_data_nasm(w, data) if opts.ident: - w("};\n") + if opts.mode == "c": + w("};\n") fp.close()