[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Generating Makefile.in's for specific target platforms (os, cpu)
From: |
BRM |
Subject: |
Re: Generating Makefile.in's for specific target platforms (os, cpu) |
Date: |
Tue, 20 Dec 2005 07:20:11 -0800 (PST) |
Thanks - that works wonderfully for linux. I have
another question, but I'll reserve that for another
thread.
Thanks,
Ben
--- Simon Richter <address@hidden> wrote:
> Hello,
>
> BRM schrieb:
>
> > Version 1: http://tinyurl.com/bhp9v
>
> I've based my changes upon that one. These are in
> (messed up due to line
> breaks) patch format, with comments in the middle.
>
> | --- hello_world_3.orig/arch/Makefile.am 2005-12-20
> 01:57:23.000000000
> +0100
> | +++ hello_world_3/arch/Makefile.am 2005-12-20
> 02:22:55.000000000
> +0100
> | @@ -9,6 +9,8 @@
> | COMPILE_FOR_CPU = ppc
> | endif
> |
> | +noinst_HEADERS = arch.h
> | +
> | # Add it to the subdirectory list
> | SUBDIRS = $(COMPILE_FOR_CPU)
>
> In order for "make dist" to work, you need to list
> all the files that
> you use in the build, even if they are not going to
> be installed.
>
> | --- hello_world_3.orig/arch/ppc/arch.c 2005-12-20
> 01:57:23.000000000
> +0100
> | +++ hello_world_3/arch/ppc/arch.c 2005-12-20
> 02:17:20.000000000
> +0100
> | @@ -1,10 +1,10 @@
> | #include <stdio.h>
> |
> | #ifndef ARCH_H__
> | - #include <arch\arch.h>
> | +# include <arch/arch.h>
> | #endif
> |
> | void Print_Arch(FILE* _output)
> | {
> | - fprintf(_output,"\tProcessor Architecture:
> i686\n");
> | + fprintf(_output,"\tProcessor Architecture:
> powerpc\n");
> | }
>
> It is perfectly acceptable to use forward slashes
> under Windows, while
> it is not a good idea to use backslashes under
> Linux. Also, your program
> should not lie (the ppc/arch.c file should not say
> 686).
>
> | --- hello_world_3.orig/arch/ppc/Makefile.am
> 2005-12-20
> 01:57:23.000000000 +0100
> | +++ hello_world_3/arch/ppc/Makefile.am 2005-12-20
> 02:20:47.000000000
> +0100
> | @@ -1,8 +1,9 @@
> | -bin_PROGRAMS = hello_world
> | -hello_world_SOURCES = arch.c
> | +noinst_LIBRARIES = libarch.a
> | +libarch_a_SOURCES = arch.c
> |
> | if TARGET_MSWINDOWS
> | WINDOWS_CLEANFILES = *.suo *.ncb *.pdb
> *.idb *.ilk *.res *.chm
> | endif
> | CLEANFILES = $(WINDOWS_CLEANFILES)
> |
> | +INCLUDES = -I${top_srcdir}
>
> The idea here is to build a (static) library with a
> fixed name in the
> subdirectory and let the main program reference that
> library. That
> allows you to add more sources inside a subdirectory
> without telling the
> main program.
>
> Also, you want to have the INCLUDES variable contain
> a list of paths to
> include (in this case, since you have your include
> files scattered along
> the sources, the top source directory). If your
> program gets bigger, you
> will probably want to move all those headers to a
> separate directory;
> here is where you tell the compiler where to look.
>
> | --- hello_world_3.orig/configure.ac 2005-12-20
> 01:57:23.000000000
> +0100
> | +++ hello_world_3/configure.ac 2005-12-20
> 02:24:41.000000000 +0100
> | @@ -1,5 +1,5 @@
> | # Initialize AutoConf
> |
>
-AC_INIT([hello_world],[2.0],address@hidden,[hello.tar])
> |
>
+AC_INIT([hello_world],[2.0],address@hidden,[hello])
> | AC_PREREQ(2.56)
> |
> | # We want AutoConf to include the
> host/build/target triplets that
> | @@ -8,26 +8,26 @@
> | AC_CANONICAL_SYSTEM
> |
> | # Initialize AutoMake
> | -AM_INIT_AUTOMAKE([hello_world],[2.0])
> | +AM_INIT_AUTOMAKE([1.6 gnu])
> |
> | # Use the config.h header to include all compiler
> directives
> | AM_CONFIG_HEADER([config.h])
> |
> | # Check for required programs
> | AC_PROG_CC
> | +AC_PROG_RANLIB
> |
> | # Check for required headers
> | AC_CHECK_HEADERS([stdio.h])
> |
> | # Determine the OS that is being targetted:
> | -AM_CONDITIONAL([TARGET_MSWINDOWS],[test
> <A8>$target_os<A8> =
> <A8>mingw32<A8>])
> | -AM_CONDITIONAL([TARGET_LINUX],[test
> <A8>$target_os<A8> =
> <A8>linux-gnu<A8>])
> | -AM_CONDITIONAL([TARGET_LINUX],[test "$test_os" =
> "linux"])
> | +AM_CONDITIONAL([TARGET_MSWINDOWS],[test
> "${host_os}" = "mingw32"])
> | +AM_CONDITIONAL([TARGET_LINUX],[test "${host_os}"
> = "linux-gnu" ||
> test "${host_os}" = "linux"])
> |
> | # Determine the CPU that is being targetted:
> | -AM_CONDITIONAL([TARGET_I386],[test
> <A8>$test_cpu<A8> = <A8>i386<A8>])
> | -AM_CONDITIONAL([TARGET_I686],[test
> <A8>$test_cpu<A8> = <A8>i686<A8>])
> | -AM_CONDITIONAL([TARGET_PPC],[test
> <A8>$test_cpu<A8> = <A8>ppc<A8>])
> | +AM_CONDITIONAL([TARGET_I386],[test "${host_cpu}"
> = "i386"])
> | +AM_CONDITIONAL([TARGET_I686],[test "${host_cpu}"
> = "i686"])
> | +AM_CONDITIONAL([TARGET_PPC],[test "${host_cpu}" =
> "powerpc"])
> |
> | # Makefile to output
> | AC_CONFIG_FILES([Makefile os/Makefile
> os/linux/Makefile
> os/mingw32/Makefile arch/Makefile arch/i386/Makefile
> arch/i686/Makefile
> arch/ppc/Makefile])
>
> As you can see, the double quotes you used were
> pretty weird (you
> probably have some program running to change them to
> "nicer" ones).
> Also, you do not want to check the target_*
> variables as those are meant
> for toolchain packages only (build == where you
> compile; host == where
> it runs; target == where code generated by this tool
> will run). Also,
> the PPC is named "powerpc". You will also see that I
> concatenated the
> two test commands with || to mean "or"; if you have
> two AM_CONDITIONAL
> lines following each other, the second will
> overwrite the result from
> the first.
>
> Also changed: new AM_INIT_AUTOMAKE syntax, and call
> to find the ranlib
> binary, as this is needed for the static libraries;
> and the tarname does
> not need to include ".tar".
>
> | --- hello_world_3.orig/Makefile.am 2005-12-20
> 01:57:23.000000000
> +0100
> | +++ hello_world_3/Makefile.am 2005-12-20
> 02:23:57.000000000 +0100
> | @@ -8,7 +8,7 @@
> | hello_world_LDADD += os/mingw32/os$(OBJEXT)
> | endif
> | if TARGET_LINUX
> | -hello_world_LDADD += os/linux/os$(OBJEXT)
> | +hello_world_LDADD += os/linux/libos.a
> | endif
> |
> | if TARGET_I386
> | @@ -18,9 +18,11 @@
> | hello_world_LDADD += arch/i686/arch$(OBJEXT)
> | endif
> | if TARGET_PPC
> | -hello_world_LDADD += arch/ppc/arch$(OBJEXT)
> | +hello_world_LDADD += arch/ppc/libarch.a
> | endif
> |
> | +noinst_HEADERS = hello.h
> | +
> | if TARGET_MSWINDOWS
> | WINDOWS_CLEANFILES = *.suo *.ncb *.pdb
> *.idb *.ilk *.res *.chm
> | endif
>
> Again, you need to add all files for the "dist"
> target. It could be
> considered good style to also define INCLUDES here;
> also the names of
> the static libraries are pretty much fixed now.
>
> | --- hello_world_3.orig/os/linux/Makefile.am
> 2005-12-20
> 01:57:23.000000000 +0100
> | +++ hello_world_3/os/linux/Makefile.am 2005-12-20
> 02:22:24.000000000
> +0100
> | @@ -1,2 +1,4 @@
> | -bin_PROGRAMS = hello_world
> | -hello_world_SOURCES = os.c
> | +noinst_LIBRARIES = libos.a
> | +libos_a_SOURCES = os.c
> | +
> | +INCLUDES = -I$(top_srcdir)
>
> This is much like arch/ppc/Makefile.am.
>
> | --- hello_world_3.orig/os/Makefile.am 2005-12-20
> 01:57:23.000000000
> +0100
> | +++ hello_world_3/os/Makefile.am 2005-12-20
> 02:22:40.000000000
> +0100
> | @@ -6,5 +6,7 @@
> | COMPILE_FOR_OS = linux
> | endif
> |
> | +noinst_HEADERS = os.h
> | +
> | # And add it to the sub-directory list
> | SUBDIRS = $(COMPILE_FOR_OS)
>
> This is similar to arch/Makefile.am.
>
> I have obviously only fixed powerpc/Linux, as this
> is what I have here.
> Your mission, should you choose to accept it, will
> be to
>
> a) fix the other combinations as well
> b) have the configure script fall back to 386 for
> 486/586 and 686 for
> all the higher ones.
> c) implement a way to dynamically switch CPU support
> at runtime among
> compatible CPUs (so you have a single binary that
> works on all Intel
> compatibles and will use optimized assembler when it
> detects an 686 or
> higher)
>
> $ ./hello_world
> Hello World
> Operating System: Linux
> Processor Architecture: powerpc
>
> With the changes above, the package passes "make
> distcheck" for me. If
> you call that you will notice that it descends into
> all directories, as
> I described.
>
> Have fun,
>
> Simon
>
TCP/IP Evil-bit RFC
ftp://ftp.rfc-editor.org/in-notes/rfc3514.txt