1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00
upx/src/Makedefs.upx
Markus F.X.J. Oberhumer b2949259c5 Portability updates.
committer: mfx <mfx> 1054071025 +0000
2003-05-27 21:30:25 +00:00

566 lines
10 KiB
Plaintext

# /***********************************************************************
# // setup
# ************************************************************************/
SHELL = /bin/sh
.SUFFIXES:
.SUFFIXES: .a .c .cpp .exe .lib .o .obj .rc .res .ttp
ifeq ($(srcdir),)
srcdir = .
endif
VPATH = $(srcdir)
# auto-detect the target unless given on the commandline
ifeq ($(strip $(target)),)
# try environment variable UPX_TARGET
target := $(UPX_TARGET)
endif
ifeq ($(strip $(target)),)
ifneq ($(strip $(wildcard /usr/include/linux)),)
target = linux
endif
##ifneq ($(strip $(wildcard /platform/sun4?/kernel/unix)),)
##target = sparc-sun-solaris
##endif
endif
ifeq ($(strip $(target)),)
include please_specify_a_target
endif
# util var for use in the rules - basename of the current target
override T = $(basename $@)
# /***********************************************************************
# // compiler defaults
# ************************************************************************/
CC_COMPILE = $(CC) $(CCARCH) $(DEFS) $(EXTRA_DEFS) $(INCLUDES) $(EXTRA_INCLUDES) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_OUTPUT) -c $<
CXX_COMPILE = $(CXX) $(CXXARCH) $(DEFS) $(EXTRA_DEFS) $(INCLUDES) $(EXTRA_INCLUDES) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(CXXFLAGS_OUTPUT) -c $<
CXX_LINK_EXE = $(CXXLD) $(CXXLDARCH) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LINK_EXE_OUTPUT) $^ $(LDLIBS) $(EXTRA_LDLIBS) $(LINK_EXE_LDFLAGS)
STUBEDIT_EXE =
STUBIFY_EXE =
CHMOD_EXE =
# set defaults
o = .o
a = .a
e =
DEFS =
INCLUDES =
LIBDIRS =
DOS_LDLIBS =
DOS_LIBDIRS =
# set CC defaults
CC = INVALID_TARGET_CC
CCARCH =
CFLAGS =
CFLAGS_OUTPUT =
# set CXX defaults
CXX = $(CC)
CXXARCH = $(CCARCH)
CXXFLAGS = $(CFLAGS)
CXXFLAGS_OUTPUT = $(CFLAGS_OUTPUT)
# set CXXLD defaults
CXXLD = $(CXX)
CXXLDARCH = $(CXXARCH)
LDFLAGS =
LINK_EXE_OUTPUT =
LDLIBS =
LINK_EXE_LDFLAGS =
# update defaults
ifeq ($(DEBUG),1)
DEFS += -DDEBUG
## DEFS += -DTESTING
endif
# /***********************************************************************
# // compression library
# ************************************************************************/
ifeq ($(WITH_ZLIB),1)
DOS_LDLIBS += zlib114.lib
endif
UCLDIR:=$(strip $(subst \,/,$(UCLDIR)))
NRVDIR:=$(strip $(subst \,/,$(NRVDIR)))
u = ucl
U = UCL
upx_exe_tail =
include $(srcdir)/Makedefs.inc
ifneq ($(strip $(wildcard $(NRVDIR)/include/nrv)),)
u = nrv
U = NRV
upx_exe_tail = _$(u)
include $(srcdir)/Makedefs.inc
endif
upx_exe = upx$(upx_exe_tail)$(e)
override tmp := -Wl,--rpath,
LDRPATH := $(addprefix $(tmp),$(LIBDIRS))
LIBDIRS += .
LDLIBDIRS := $(addprefix -L,$(LIBDIRS))
##LDFLAGS += $(LDRPATH)
LDFLAGS += $(LDLIBDIRS)
# /***********************************************************************
# // compiler settings
# ************************************************************************/
###
### generic gcc
###
ifeq ($(target),gcc)
include $(srcdir)/Makedefs.gcc
endif
###
### linux
###
ifeq ($(target),linux)
override arch := $(shell uname -m | sed -e 's/^i[3456789]86$$/i386/')
include $(srcdir)/Makedefs.gcc
ifeq ($(arch),i386)
CCARCH += -march=i386 -mcpu=i686
endif
DEFS += -D_FILE_OFFSET_BITS=64
LDLIBS += -lmcheck
##CFLAGS_WERROR = -Werror
ifeq ($(DEBUG),0)
##LDFLAGS += -static
STUBEDIT_EXE = objcopy -S -R .comment -R .note $@
ifeq ($(arch),i386)
## STUBIFY_EXE = perl $(srcdir)/stub/scripts/brandelf.pl $@
endif
endif
CHMOD_EXE = chmod 755 $@
endif # linux
###
### linux/i386 - Intel C++ 7.x
###
ifeq ($(target),linux-intelc70)
DEPMODE := intelc_linux
CC = icc
CXX = icpc
CCARCH += -march=i386 -mcpu=i686
CFLAGS_OUTPUT = -o $@
LINK_EXE_OUTPUT = -o $@
ifeq ($(WITH_ZLIB),1)
LDLIBS += -lz
endif
CFLAGS = $(CFLAGS_WERROR)
ifeq ($(DEBUG),1)
CFLAGS += -g -O0
else
CFLAGS += -O2
endif
LDFLAGS += -Wl,-Map,$T.map
endif
###
### linux/i386 - Borland C++ 5.7 (Kylix 3)
###
ifeq ($(target),linux-bc57)
##DEPMODE := XXX_linux
CC = bc++ -q -3
CFLAGS = -w -w-aus -w-inl -w!
CFLAGS_OUTPUT = -o$@
LDFLAGS += -ls
LINK_EXE_OUTPUT = -e$@
ifeq ($(WITH_ZLIB),1)
LDLIBS += -lz
endif
ifeq ($(DEBUG),1)
CFLAGS += -Od -d
else
CFLAGS += -O2 -d
endif
# transform `-lxx -lyy' into `libxx.a libyy.a'
LDLIBS := $(shell echo "$(LDLIBS)" | perl -pe 's/-l(.*?)\b/lib\1.a/g')
endif
###
### Linux cross compilers
###
ifeq ($(target),cross-m68k-linux)
include $(srcdir)/Makedefs.gcc
CC = m68k-linux-gcc
CXX = m68k-linux-g++
##LDLIBS += -lmcheck
endif # cross-m68k-linux
###
### sparc-sun-solaris2.8
###
ifeq ($(target),sparc-sun-solaris)
include $(srcdir)/Makedefs.gcc
endif
###
### Atari cross compiler
###
ifeq ($(target),cross-mint)
include $(srcdir)/Makedefs.gcc
e = .ttp
CC = m68k-atari-mint-gcc
CXX = m68k-atari-mint-g++
CCARCH += -m68000
endif
ifeq ($(target),cross-mint-m68040)
include $(srcdir)/Makedefs.gcc
e = .ttp
CC = m68k-atari-mint-gcc
CXX = m68k-atari-mint-g++
CCARCH += -m68040
endif
ifeq ($(target),cross-mint-m68020-60)
include $(srcdir)/Makedefs.gcc
e = .ttp
CC = m68k-atari-mint-gcc
CXX = m68k-atari-mint-g++
CCARCH += -m68020-60 -m68881
endif
###
### dos32 - djgpp2
###
ifeq ($(target),djgpp2)
include $(srcdir)/Makedefs.gcc
e = .exe
CXX = gxx
CCARCH += -march=i386 -mcpu=i686
CFLAGS_WERROR = -Werror
STUBEDIT_EXE = stubedit $@ bufsize=0xfc00
ifneq ($(strip $(wildcard $(DJDIR)/bin/mfxdjstubify.ex[eE])),)
ifneq ($(strip $(wildcard $(DJDIR)/bin/cwsdstub.ex[eE])),)
STUBIFY_EXE = mfxdjstubify -v -s $(DJDIR)/bin/cwsdstub.exe $(upx_exe)
endif
endif
endif # djgpp2
###
### win32 - cygwin / mingw32
###
ifeq ($(target),cygwin)
include $(srcdir)/Makedefs.gcc
e = .exe
CCARCH += -mcygwin -march=i386 -mcpu=i686
endif
ifeq ($(target),mingw32)
include $(srcdir)/Makedefs.gcc
e = .exe
CCARCH += -mno-cygwin -march=i386 -mcpu=i686
endif
# mingw32 as included in cygwin
ifeq ($(target),no-cygwin)
include $(srcdir)/Makedefs.gcc
e = .exe
CCARCH += -mno-cygwin -march=i386 -mcpu=i686
endif
# mingw32 cross compiler
ifeq ($(target),cross-mingw32)
include $(srcdir)/Makedefs.gcc
e = .exe
CC = i586-mingw32msvc-gcc
CXX = i586-mingw32msvc-g++
CCARCH += -march=i386 -mcpu=i686
endif
# rsxnt (g++ 2.8.1)
ifeq ($(target),rsxnt)
include $(srcdir)/Makedefs.gcc
e = .exe
CXX = gcc
CFLAGS_O = -O0
CCARCH += -Zwin32 -Zsys -mno-probe
LDFLAGS = -s
STUBEDIT_EXE = pestack -s1024 -c1024 $@
endif
###
### win32 - Borland C++
###
ifeq ($(target),bc)
o = .obj
a = .lib
e = .exe
CC = bcc32 -q -6
CFLAGS = -w -w-aus -w-inl -g1
CFLAGS_OUTPUT = -o$@
LDFLAGS = -ls
LINK_EXE_OUTPUT = -e$@
LDLIBS = $(DOS_LDLIBS)
ifneq ($(strip $(DOS_LIBDIRS)),)
LIB := $(DOS_LIBDIRS);$(LIB)
endif
export LIB
ifeq ($(DEBUG),1)
CFLAGS += -Od -d
else
CFLAGS += -O2 -d
endif
endif # bc
###
### win32 - Digital Mars C++
###
ifeq ($(target),dm)
o = .obj
a = .lib
e = .exe
CC = dmc -mn
CFLAGS = -w- -wx
CXXFLAGS = $(CFLAGS) -Aa -Ab -Ae -Ar
CFLAGS_OUTPUT = -o$@
LDFLAGS = -L/map
LINK_EXE_OUTPUT = -o$@
LDLIBS = $(DOS_LDLIBS)
ifneq ($(strip $(DOS_LIBDIRS)),)
LIB := $(DOS_LIBDIRS);$(LIB)
endif
export LIB
ifeq ($(DEBUG),1)
CFLAGS += -o- -g -s
else
CFLAGS += -o
endif
endif # dm
###
### win32 - Intel C++
###
ifeq ($(target),ic)
o = .obj
a = .lib
e = .exe
CC = icl -nologo -MD
CFLAGS = -W3 -WX
CXXFLAGS = $(CFLAGS) -EHac -GR
LDFLAGS =
LINK_EXE_OUTPUT = -Fe$@
LDLIBS = $(DOS_LDLIBS) setargv.obj
LINK_EXE_LDFLAGS = /link /map:$T.map
##LINK_EXE_LDFLAGS += /verbose
ifneq ($(strip $(DOS_LIBDIRS)),)
LIB := $(DOS_LIBDIRS);$(LIB)
endif
export LIB
ifeq ($(DEBUG),1)
CFLAGS += -Od -ZI
LINK_EXE_LDFLAGS += /debug
else
CFLAGS += -O1 -GF
LINK_EXE_LDFLAGS += /release
endif
RESOURCES = upx.res
endif # ic
###
### win32 - Visual C++
###
ifeq ($(target),vc)
o = .obj
a = .lib
e = .exe
CC = cl -nologo
CFLAGS = -W4 -WX
CXXFLAGS = $(CFLAGS) -EHac -GR
LDFLAGS =
LINK_EXE_OUTPUT = -Fe$@
LINK_EXE_LDFLAGS = /link /map:$T.map
##LINK_EXE_LDFLAGS += /verbose
ifneq ($(strip $(DOS_LIBDIRS)),)
LIB := $(DOS_LIBDIRS);$(LIB)
endif
export LIB
ifeq (1,2)
# statically link libc.lib
CC += -ML
LDLIBS = $(DOS_LDLIBS:.lib=_ml.lib) setargv.obj
else
# link against msvcrt.dll
CC += -MD
LDLIBS = $(DOS_LDLIBS) setargv.obj
endif
ifeq ($(DEBUG),1)
CFLAGS += -Od -ZI
LINK_EXE_LDFLAGS += /debug
else
CFLAGS += -O1 -GF
LINK_EXE_LDFLAGS += /release
endif
RESOURCES = upx.res
endif # vc
###
### win32 - Watcom C++ 11.0c / Open Watcom C++ 1.0
###
ifeq ($(target),wc)
o = .obj
a = .lib
e = .exe
CC = wcl386 -zq -bt=nt -mf -5r
CFLAGS = -zc -w5 -we
CXXFLAGS = $(CFLAGS) -xs -xr
CFLAGS_OUTPUT = -fo=$@
LDFLAGS = -k0x100000 -fm
LINK_EXE_OUTPUT = -fe=$@
LDLIBS = $(DOS_LDLIBS)
INCLUDES:=$(strip $(subst /,\\,$(INCLUDES)))
ifeq (1,2)
WCL386:=$(INCLUDES)
export WCL386
INCLUDES:=
endif
ifneq ($(strip $(DOS_LIBDIRS)),)
LIB := $(DOS_LIBDIRS);$(LIB)
endif
export LIB
ifeq ($(DEBUG),1)
CFLAGS +=
else
# note: it seems that the optimizer is generating bad code with `-ox'
CFLAGS += -olr
endif
endif # wc
# /***********************************************************************
# // malloc debuggers and memory checkers - somewhat obsolete, use valgrind
# ************************************************************************/
ifeq (1,2)
# compile in extra valgrind support
DEFS += -DWITH_VALGRIND
endif
ifeq (1,2)
LDLIBS += -lefence
endif
ifeq (1,2)
DEFS += -DWITH_DMALLOC
LDLIBS += -ldmalloc
endif
ifeq (1,2)
DEFS += -DWITH_GC -DLINUX_THREADS -D_REENTRANT
LDLIBS += -lgc -lpthread
# only needed when using -static:
##LDFLAGS += -Wl,-defsym,_DYNAMIC=0
endif
# /***********************************************************************
# // main targets
# ************************************************************************/
all: $(upx_exe)
.PHONY: all mostlyclean clean distclean maintainer-clean untabify tags
$(upx_exe): $(OBJECTS) $(LIBS) $(RESOURCES)
$(strip $(CXX_LINK_EXE))
$(STUBEDIT_EXE)
$(STUBIFY_EXE)
$(CHMOD_EXE)
mostlyclean:
-rm -f *.d *.err *.i *.log *.map *~ gdb-trans*
clean: mostlyclean
-rm -f *.a *.lib *.o *.obj *.res *.tds tags TAGS ID
-rm -f *.idb *.pdb
-rm -f $(upx_exe) upx upx.exe upx.ttp upx_nrv upx_nrv.exe upx_nrv.ttp upx_ucl upx_ucl.exe upx_ucl.ttp
-rm -rf .deps
distclean: clean
maintainer-clean: distclean
# /***********************************************************************
# // rules
# ************************************************************************/
%$o : %.c
$(strip $(CC_COMPILE))
%$o : %.cpp
$(strip $(CXX_COMPILE))
%.res : %.rc
rc -l 0x409 -fo$@ $<
# vi:nowrap