How to generate Linux version flag at compile time, run time, fromrpm spec. - Linux

This is a discussion on How to generate Linux version flag at compile time, run time, fromrpm spec. - Linux ; I am writing a user space utility which would run on RHEL4, RHEL5 and SLES10. This utility has common source and there are few section of code are specific to OS version. In order to differentiate I am thinking I ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: How to generate Linux version flag at compile time, run time, fromrpm spec.

  1. How to generate Linux version flag at compile time, run time, fromrpm spec.

    I am writing a user space utility which would run on RHEL4, RHEL5 and
    SLES10. This utility has common source and there are few section of
    code are specific to OS version. In order to differentiate I am
    thinking I could use Linux kernel version. Tha means I need a Linux
    version flag
    1) at compile time ( in Makefile, in C source )
    2) at run time ( from c source)
    3) From rpm spec file to build rpms.

    I do not use GNU autotool. Kindly suggest methods. Appreciate your
    help.
    -Adar.

  2. Re: How to generate Linux version flag at compile time, run time,from rpm spec.

    On Jan 24, 9:29*am, adar wrote:
    > I am writing a user space utility which would run on RHEL4, RHEL5 and
    > SLES10. *This utility has common source and there are few section of
    > code are specific to OS version. In order to differentiate I am
    > thinking I could use Linux kernel version. Tha means I need a Linux
    > version flag
    > 1) at compile time ( in Makefile, in C source )
    > 2) at run time *( from c source)
    > 3) From rpm spec file to build rpms.
    >
    > I do not use GNU autotool. Kindly suggest methods. Appreciate your
    > help.
    > -Adar.



    From makefile I'm planning on using uname, for example
    OS=$(shell uname -s)
    OSVER=$(shell uname -r | ` cut -f1 -d"-"`)
    OSARCH=$(shell uname -i)

    and then say
    ifeq ($(OSVER), 2.6.16)
    C_FLAGS = -DLinux_2_6_16
    endif

    Are there any different methods ?










  3. Re: How to generate Linux version flag at compile time, run time, from rpm spec.

    adar (whoever) schrieb:

    > I am writing a user space utility which would run on RHEL4, RHEL5 and
    > SLES10. This utility has common source and there are few section of
    > code are specific to OS version. In order to differentiate I am
    > thinking I could use Linux kernel version. Tha means I need a Linux
    > version flag


    > 1) at compile time ( in Makefile, in C source )


    #include
    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
    "do something special"
    #else
    "do some other special things"
    #endif

    > 2) at run time ( from c source)


    man 3 uname, man utsname.h

    > 3) From rpm spec file to build rpms.


    Should not be necessary if you use options 1) and 2).

    Guido


    --
    http://www.bayernline.de/~gscholz/
    http://www.lug-burghausen.org/

+ Reply to Thread