# Makefile for GNU binary-file utilities
# Select a set of CFLAGS and PROGS, below, depending on the system type.
# Copyright (C) 1989, 1990 Free Software Foundation, Inc.
#
# This file is part of the GNU binutils.
# 
# The GNU binutils are free software; you can redistribute them and/or modify
# them under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
# 
# The GNU binutils are distributed in the hope that they will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with the GNU binutils; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# gprof.c contains `void *' and very long string constants which many
# C compilers can't handle, so you might need gcc to compile it.
GNUCC = $(CC)
# But you might need to use your old C compiler to compile the other
# programs (ld at least), if you can't run gcc without them
# (particularly on COFF systems).
CC = gcc

# Where you want to put them.
bindir=/usr/bin

# For Linux

archpfx=l-

TARGET=m68k-linux

HOSTNAME=i386-att-sysv
HOSTNAME=decstation
HOSTNAME=linux
HOSTNAME=amigados

ifeq "$(TARGET)" "m68k-linux"
TARGDEF=-Dmc68000
else
TARGDEF=-Di386
endif

ifeq "$(HOSTNAME)" "linux"

# Those 3 are not needed for Linux.
GNU_GETOPT = 
GNU_GETOPT_LONG =
SIGNAME =

# you can define AR_H and A_OUT_H for the header files you want to
# includes.
HEADERS=-DAR_H=\<ar.h\> -DA_OUT_H=\<a.out.h\>

XCFLAGS= -DSHORT_FILENAME -DHAVE_TRAILING_SLASH_IN_NAME \
	-DSTDC_HEADERS

MISCFLAGS= 

PROGS = $(archpfx)gprof $(archpfx)ld $(archpfx)size \
        $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib \
        $(archpfx)objdump

else


ifeq "$(HOSTNAME)" "i386-att-sysv"

HOST_ROOT=/local/$(TARGET)

MISCFLAGS= $(TARGDEF) -shlib -DUSG -DSYS_SIGLIST_MISSING -DSHORT_FILENAME \
                -DHOST_TARGET_ENDIANNESS_DIFFERS

MDOBJS = biglittle.o

endif

ifeq "$(HOSTNAME)" "decstation"

HOST_ROOT=/net/ren/users/hlu/local/i486-linux

MISCFLAGS= $(TARGDEF) -DHAVE_TRAILING_SLASH_IN_NAME \
		-DHOST_TARGET_ENDIANNESS_DIFFERS

MDOBJS = biglittle.o

endif

ifeq "$(HOSTNAME)" "sparc-sun-sunos4.1"

HOST_ROOT=/usr/local/$(TARGET)

MISCFLAGS= $(TARGDEF) -DHAVE_TRAILING_SLASH_IN_NAME -Usparc -Usun

endif

ifeq "$(HOSTNAME)" "hppa"

HOST_ROOT=/usr/local/$(TARGET)

MISCFLAGS= $(TARGDEF) -DSYS_SIGLIST_MISSING

endif

ifeq "$(HOSTNAME)" "amigados"

HOST_ROOT=/gcc/$(TARGET)

MISCFLAGS= $(TARGDEF) -DSTACK_DIRECTION=-1

ALLOCALIBS=alloca.o

endif

# where get those header files.
AR_H=$(HOST_ROOT)/include/ar.h
A_OUT_H=$(HOST_ROOT)/include/linux/a.out.h
HEADERS=-DAR_H=\"$(AR_H)\" -DA_OUT_H=\"$(A_OUT_H)\" -idirafter $(HOST_ROOT)/include

CROSS_AR=$(HOST_ROOT)/bin/ar

CROSS_FLAGS=-DCROSS_AR=\"$(CROSS_AR)\"

STANDARD_SEARCH_DIRS=$(HOST_ROOT)/lib

XCFLAGS=-Dlinux -DCROSS_LINKER -DNON_NATIVE $(CROSS_FLAGS) \
	-DSTANDARD_SEARCH_DIRS=\"$(STANDARD_SEARCH_DIRS)\"

GNU_GETOPT = getopt.o
GNU_GETOPT_LONG = getopt.o getopt1.o
SIGNAME = signame.o

PROGS = $(archpfx)ld $(archpfx)size \
        $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib \
        $(archpfx)objdump

endif

OFLAGS= # -Wall  -g #-O6 -fomit-frame-pointer

CFLAGS= -s $(MISCFLAGS) $(XCFLAGS) $(HEADERS)

CFLAGS= $(MISCFLAGS) $(XCFLAGS) $(HEADERS) $(OFLAGS)

# C++ demangler
CPLUS_DEM = cp-dem.o

LIBS=$(ALLOCALIBS) $(SIGNAME) $(MDOBJS)

all: $(PROGS)
	mv $(archpfx)ar ar
	if [ -f $(archpfx)gprof ]; then \
	  mv $(archpfx)gprof gprof; \
	else true; fi
	mv $(archpfx)ld ld
	mv $(archpfx)nm nm
	mv $(archpfx)objdump objdump
	mv $(archpfx)ranlib ranlib
	mv $(archpfx)size size
	mv $(archpfx)strip strip

$(archpfx)ld: ld.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)
# LIBS is used here since ld needs to use alloca.
# Alternatively, compile it with GNU C--then the compiler handles alloca.
	$(CC) $(CFLAGS) -o $(archpfx)ld ld.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)

$(archpfx)size: size.o $(LIBS)
	$(CC) $(CFLAGS) -o $(archpfx)size size.o $(MDOBJS)

$(archpfx)nm: nm.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(MALLOC) $(LIBS)
	$(CC) $(CFLAGS) -o $(archpfx)nm nm.o \
		$(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS) $(MALLOC)

$(archpfx)strip: strip.o error.o $(GNU_GETOPT_LONG) $(LIBS)
	$(CC) $(CFLAGS) -o $(archpfx)strip strip.o error.o $(GNU_GETOPT_LONG) $(LIBS)

$(archpfx)ar: ar.o $(LIBS)
	$(CC) $(CFLAGS) -o $(archpfx)ar ar.o $(LIBS)

$(archpfx)gprof: gprof.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)
	$(GNUCC) $(CFLAGS) -o $(archpfx)gprof gprof.o \
		$(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)
gprof.o: gprof.c gmon.h
	$(GNUCC) $(CFLAGS) -c gprof.c $(OUTPUT_OPTION)

$(archpfx)ranlib: ranlib.o $(GNU_GETOPT_LONG) $(LIBS)
	$(CC) $(CFLAGS) -o $(archpfx)ranlib ranlib.o $(GNU_GETOPT_LONG) $(LIBS)
ranlib.o: ranlib.c
	$(CC) -c $(CFLAGS) -DAR_PROG=\"$(bindir)/ar\" ranlib.c $(OUTPUT_OPTION)

$(archpfx)objdump: objdump.o error.o $(GNU_GETOPT_LONG) $(LIBS)
	$(CC) $(CFLAGS) -o $(archpfx)objdump objdump.o error.o \
		$(GNU_GETOPT_LONG) $(LIBS)


clean:
	-rm -f *.o core
	-rm -f $(PROGS)
	-rm -f ar ld ranlib nm objdump size strip gprof

DISTNAME = binutils-1.9
dist:
	rm -rf $(DISTNAME)
	mkdir $(DISTNAME)
	ln COPYING Makefile README a.out.gnu.h ar.c cp-dem.c \
	error.c getopt.c getopt.h getopt1.c gmalloc.c \
	gmon.h gprof.c gprof.texinfo ld.c libconvert nm.c objdump.c \
	ranlib.c ranlib.h signame.c signame.h size.c \
	stab.def stab.h strip.c symseg.h $(DISTNAME)
	tar chZf $(DISTNAME).tar.Z $(DISTNAME)
	rm -rf $(DISTNAME)
.PHONY: dist

.PHONY: install
install: $(PROGS)
	for file in $(PROGS); do \
	cp $$file $(bindir)/$${file}.new; \
	mv $(bindir)/$${file}.new $(bindir)/$$file; \
	done
