OSDN Git Service

Unify the duplicated windows and other system fallback logic in stubs.h
[uclinux-h8/elf2flt.git] / Makefile.in
index 4299302..fc00851 100644 (file)
@@ -11,20 +11,29 @@ CC = @CC@
 CPU = @target_cpu@
 TARGET = @target_alias@
 CFLAGS = @CFLAGS@
-INCLUDES = @bfd_include_dir@ @binutils_include_dir@
-CPPFLAGS = @CPPFLAGS@
-LDFLAGS = @LDFLAGS@ -static
-LIBS = @LIBS@
+INCLUDES = -I$(srcdir) @bfd_include_dir@ @binutils_include_dir@ @zlib_include_dir@
+CPPFLAGS = @CPPFLAGS@ $(DEFS) $(INCLUDES)
+LDFLAGS = @LDFLAGS@
+LDLIBS = @LIBS@
 INSTALL = @INSTALL@
 DEFS = @DEFS@ -DTARGET_$(CPU)
 EXEEXT = @EXEEXT@
 OBJEXT = @OBJEXT@
 
-CCFLAGS = $(CFLAGS) $(DEFS) $(INCLUDES)
+HOST = @host_alias@
+
+ifneq (,$(findstring mingw32,$(HOST)))
+   LDLIBS += -lws2_32
+endif
+
+# force link order under cygwin to avoid getopts / libiberty clash
+ifneq ($(strip $(shell gcc -v 2>&1 | grep "cygwin")),)
+   LDLIBS := -lcygwin $(LDLIBS)
+endif
 
 LDFILE= elf2flt.ld
 ifeq ($(strip $(CPU)),e1)
-SRC_LDFILE= $(CPU)-elf2flt.ld
+SRC_LDFILE= $(srcdir)/$(CPU)-elf2flt.ld
 else 
 SRC_LDFILE= elf2flt.ld
 endif
@@ -37,16 +46,26 @@ PROG_ELF2FLT = elf2flt$(EXEEXT)
 PROG_FLTHDR = flthdr$(EXEEXT)
 PROGS = $(PROG_ELF2FLT) $(PROG_FLTHDR)
 
-all: $(PROGS)
+all: $(PROGS) ld-elf2flt
 
-$(PROG_ELF2FLT): elf2flt.c stubs.c Makefile
-       $(CC) $(CCFLAGS) $(LDFLAGS) -o $@ $(srcdir)/elf2flt.c $(srcdir)/stubs.c $(LIBS)
+# We need to declare the link explicitly because make only provides
+# implicit rules when EXEEXT is set to nothing
+link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-$(PROG_FLTHDR): flthdr.c Makefile
-       $(CC) $(CCFLAGS) $(LDFLAGS) -o $@ $(srcdir)/flthdr.c $(LIBS)
+$(PROG_ELF2FLT): elf2flt.o compress.o stubs.o
+       $(link)
+
+$(PROG_FLTHDR): flthdr.o compress.o stubs.o
+       $(link)
+
+ld-elf2flt: $(srcdir)/ld-elf2flt.in
+       ./config.status $@
+
+Makefile: $(srcdir)/Makefile.in
+       ./config.status $@
 
 clean:
-       -rm -f $(PROGS) *.$(OBJEXT)
+       -rm -f $(PROGS) *.$(OBJEXT) .deps
 
 distclean: clean
        -rm -f Makefile config.log config.status config.cache ld-elf2flt
@@ -55,16 +74,18 @@ install:
        $(INSTALL) -d $(bindir)
        $(INSTALL) -d $(target_bindir)
        $(INSTALL) -d $(target_libdir)
-       $(INSTALL) -s -m 755 $(PROG_FLTHDR) $(bindir)/$(TARGET)-$(PROG_FLTHDR)
-       $(INSTALL) -s -m 755 $(PROG_FLTHDR) $(target_bindir)/$(PROG_FLTHDR)
-       $(INSTALL) -s -m 755 $(PROG_ELF2FLT) $(bindir)/$(TARGET)-$(PROG_ELF2FLT)
-       $(INSTALL) -s -m 755 $(PROG_ELF2FLT) $(target_bindir)/$(PROG_ELF2FLT)
+       $(INSTALL) -m 755 $(PROG_FLTHDR) $(bindir)/$(TARGET)-$(PROG_FLTHDR)
+       $(INSTALL) -m 755 $(PROG_FLTHDR) $(target_bindir)/$(PROG_FLTHDR)
+       $(INSTALL) -m 755 $(PROG_ELF2FLT) $(bindir)/$(TARGET)-$(PROG_ELF2FLT)
+       $(INSTALL) -m 755 $(PROG_ELF2FLT) $(target_bindir)/$(PROG_ELF2FLT)
        [ -f $(bindir)/$(TARGET)-ld.real$(EXEEXT) ] || \
                mv $(bindir)/$(TARGET)-ld$(EXEEXT) $(bindir)/$(TARGET)-ld.real$(EXEEXT)
        [ -f $(target_bindir)/ld.real$(EXEEXT) ] || \
                mv $(target_bindir)/ld$(EXEEXT) $(target_bindir)/ld.real$(EXEEXT)
        $(INSTALL) -m 755 ld-elf2flt $(bindir)/$(TARGET)-ld
        $(INSTALL) -m 755 ld-elf2flt $(target_bindir)/ld
-       $(INSTALL) -m 644 $(srcdir)/$(SRC_LDFILE) $(target_libdir)/$(LDFILE)
-
+       $(INSTALL) -m 644 $(SRC_LDFILE) $(target_libdir)/$(LDFILE)
 
+sinclude .deps
+.deps:
+       $(CC) -MM $(CPPFLAGS) *.c > .deps