LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   compiling coreutils (https://www.linuxquestions.org/questions/programming-9/compiling-coreutils-866906/)

wakatana 03-07-2011 03:33 AM

compiling coreutils
 
Hi gurus
I am trying to compile coreutils for studying purposes. I downloaded package (exact version which target system already contains) and tried following:

Code:

./configure
make

but compiling ands with some header file dependency problem. Then I tried compile particular binary

Code:

cd src
gcc id.c -o id

also tried

Code:

export CFLAGS="-static -02 -g"
./configure
cd src
gcc -std=gnu99 -I../lib -static -O2 -g -MT uniq.o -MD -MP -MF .deps/uniq.Tpo -c -o uniq.o uniq.c

But there was also missing header files problem.

So I tried to find particular file on system and link to /usr/include location for example:
Code:

ln -s /usr/lib/syslinux/com32/include/syslinux/config.h /usr/include/config.h
ln -s /usr/lib/syslinux/com32/include/com32.h /usr/include/com32.h
ln -s /usr/lib/syslinux/com32/include/klibc/compiler.h /usr/include/klibc/compiler.h
ln -s /usr/lib/gcc/i686-pc-linux-gnu/4.5.2/plugin/include/system.h /usr/include/system.h
ln -s /usr/lib/gcc/i686-pc-linux-gnu/4.5.2/plugin/include/safe-ctype.h /usr/include/safe-ctype.h
ln -s /usr/lib/gcc/i686-pc-linux-gnu/4.5.2/plugin/include/hwint.h /usr/include/hwint.h
ln -s /usr/lib/gcc/i686-pc-linux-gnu/4.5.2/plugin/include/filenames.h /usr/include/filenames.h

maybe further more header files I dont know - but the result is the same header file problem.
I tried the metioned procedure on Archbang and Fedora (on both the coreutils was the same version whih is already installed and is working properly)

Thanks a lot

knudfl 03-07-2011 04:52 AM

Archbang may be too lightweight. Anyway, you will need a complete glibc.
( May be the headers are omitted, to make it more lightweight ? )

Fedora : # yum install glibc-devel glibc-headers kernel-headers

.. providing /usr/include/*, /usr/include/linux/*, /usr/include/asm/*

wakatana 03-08-2011 08:19 AM

Quote:

Originally Posted by knudfl (Post 4281348)
Archbang may be too lightweight. Anyway, you will need a complete glibc.
( May be the headers are omitted, to make it more lightweight ? )

Fedora : # yum install glibc-devel glibc-headers kernel-headers

.. providing /usr/include/*, /usr/include/linux/*, /usr/include/asm/*

Seems they are installed

Code:

[cepido@localhost src]$ yum list installed | grep glibc
glibc.i686          2.13-1          @updates
glibc-common.i686  2.13-1          @updates
glibc-devel.i686    2.13-1          @updates
glibc-headers.i686  2.13-1          @updates
[cepido@localhost src]$ yum list installed | grep headers
glibc-headers.i686  2.13-1          @updates
kernel-headers.i686 2.6.35.11-83.fc14


colucix 03-08-2011 08:31 AM

Quote:

Originally Posted by wakatana (Post 4281281)
but compiling ands with some header file dependency problem.

What headers? Please, can you post the relevant lines of the error message (usually the last 20-30 lines are enough)?

dwhitney67 03-08-2011 08:42 AM

It's been several years since I dealt with coreutils (version 6.9) when I was building a Linux system based on CLFS (cross-compiled linux from scratch). From what I can recall, to build coreutils, these steps were performed:

1. Untar the package;
2. Change directory into coreutils-<version>;
3. Patch any source modules as necessary (check if your version of coreutils has any available patches);
4. ./configure
5. make

The CLFS cookbook required that the following packages be built in this order:
Code:

STAGE1  = tcl-testsuite \
          expect-testsuite \
          file-testsuite \
          dejagnu-testsuite \
          tree-testsuite \
          temp-perl \
          linux-headers \
          man-pages \
          glibc \
          binutils \
          gcc \
          coreutils \
          ...

I don't think the "testsuite" and man-pages packages are relevant for your needs, however you should make sure that you have the other ones preceding coreutils.

knudfl 03-08-2011 09:23 AM

Fedora 14 : That is coreutils-8.5
http://ftp.gnu.org/gnu/coreutils/coreutils-8.5.tar.gz
> coreutils-8.5.tar.gz

cd coreutils-8.5/ && ./configure && make : No errors.

Version 8.9 : The same, no errors.
( http://ftp.gnu.org/gnu/coreutils/coreutils-8.9.tar.gz )

For the above, glibc* 2.12.90 was used. You have updated to 2.13,
but I don't know why 2.13 should be that different ( or unstable ).

..

wakatana 03-08-2011 04:09 PM

Tried that

Code:

ARCHBANG
[cepido@archbang ~]$ pacman -Q | grep coreutils
coreutils 8.10-1
[cepido@archbang ~]$ cd coreutils-8.10/src/
[cepido@archbang src]$ gcc -std=gnu99 -I../lib -static -O2 -g -MT uniq.o -MD -MP -MF .deps/uniq.Tpo -c -o uniq.o uniq.c
In file included from uniq.c:24:0:
system.h:49:24: fatal error: configmake.h: No such file or directory
compilation terminated.
[cepido@archbang src]$ gcc uniq.c -o uniq
uniq.c:19:20: fatal error: config.h: No such file or directory
compilation terminated.


FEDORA
[cepido@localhost /]$ yum list installed | grep core
coreutils.i686      8.5-7.fc14      @updates
coreutils-libs.i686 8.5-7.fc14      @updates
[cepido@localhost ~]$ cd coreutils-8.5/src/
[cepido@localhost src]$ gcc -std=gnu99 -I../lib -static -O2 -g -MT uniq.o -MD -MP -MF .deps/uniq.Tpo -c -o uniq.o uniq.c
uniq.c:19:20: fatal error: config.h: No such file or directory
compilation terminated.
[cepido@localhost src]$ gcc uniq.c -o uniq
uniq.c:19:20: fatal error: config.h: No such file or directory
compilation terminated.

also
./configure
make

has been issued before

theNbomr 03-08-2011 04:56 PM

When I scan through many of the config.h files on the system I'm writing this from, I see in most of them:
Code:

/* config.h.  Generated from config.h.in by configure.  */
This begs the question of whether your configure script is running successfully, or if it bugs out due to something it didn't like or couldn't do.

Also, it looks like you are trying to run gcc independently, whereas there should be a properly configured Makefile that will let you just build everything.

--- rod.

knudfl 03-08-2011 05:22 PM

Quote:

cd coreutils-8.5/src/
Are you actually changing directory to src/ ?
Or is that (cd coreutils-8.5/src/) from the output of 'make' ?

I'd guess, that it is a must to run make in the top directory only.

There is no /usr/include/config.h in Fedora 14 :
Anyway coreutils is compiled with no errors. (The locale config.h is used ?)

Code:

gcc -std=gnu99 -I../lib -static -O2 -g -MT uniq.o -MD -MP -MF .deps/uniq.Tpo -c -o uniq.o uniq.c
This command cannot be run as a separate command, it seems.
You have headers in lib/ and src/, some includes a header from the other folder.
( Unless you already have run 'make' with no errors in the top directory.
But then again : As the uniq.o already is present : Nothing will be created.)

The 'gcc -std=..' command will however work, if make has been run, and uniq.o deleted:
Then a new different uniq.o is created.

EDIT : I wrote the above, while theNbomr was posting.
..

wakatana 03-13-2011 05:17 AM

Hi people - sorry for long response
I tried that:
Code:

[root@localhost coreutils-8.5]# tar -xvzf coreutils-8.5.tar.gz
[root@localhost coreutils-8.5]# cd coreutils-8.5
[root@localhost coreutils-8.5]# ./configure
long output
long output
long output
configure: WARNING: libgmp development library was not found or not usable.
configure: WARNING: GNU coreutils will be built without GMP support.
long output
long output
[root@localhost coreutils-8.5]# echo $0
0
[root@localhost coreutils-8.5]# make
long utput
long utput
long utput
make[4]: Entering directory `/root/coreutils-8.5/gnulib-tests'
make[4]: Nothing to be done for `all-am'.
make[4]: Leaving directory `/root/coreutils-8.5/gnulib-tests'
make[3]: Leaving directory `/root/coreutils-8.5/gnulib-tests'
make[2]: Leaving directory `/root/coreutils-8.5/gnulib-tests'
make[2]: Entering directory `/root/coreutils-8.5'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/root/coreutils-8.5'
make[1]: Leaving directory `/root/coreutils-8.5'
[root@localhost coreutils-8.5]# echo $?
0
[root@localhost coreutils-8.5]# src/whoami
root

Seems make works. This package has been installed since last post.

Code:

[root@localhost src]# yum list installed coreutils-debuginfo
Loaded plugins: auto-update-debuginfo
Installed Packages
coreutils-debuginfo.i686                                                    8.5-7.fc14                                                    @updates-debuginfo

Also two questions
- is it possible to compile only specific binary ? (id.c uniq.c cat.c etc) and not whole package ?
- where to find another packages that I can compile from source ? for example passwd command ?

I tried to search for passwd-0.78-1.fc14.i686 tar gz but no luck

knudfl 03-13-2011 06:25 AM

Quote:

passwd-0.78-1.fc14.i686
"i686" means a binary package.

The "tar package" for passwd-0.78-1.fc14.i686.rpm ( passwd-0.78.tar.bz2 )
It is inside the Fedora 14 source package passwd-0.78-1.fc14.src.rpm
http://download.fedora.redhat.com/pu.../source/SRPMS/

wakatana 03-13-2011 07:51 AM

Quote:

Originally Posted by knudfl (Post 4288968)
"i686" means a binary package.

The "tar package" for passwd-0.78-1.fc14.i686.rpm ( passwd-0.78.tar.bz2 )
It is inside the Fedora 14 source package passwd-0.78-1.fc14.src.rpm
http://download.fedora.redhat.com/pu.../source/SRPMS/

Thank you that makes sense that i686 is binary :) but id did not comes to my mind before.
And is possible to compile only particular binary not whole package ?

knudfl 03-13-2011 08:04 AM

Quote:

Is it possible to compile only specific binary ? (id.c uniq.c cat.c)
No. Not directly.

You will have to use lots of time to rewrite files to do so. Makefile ?
Then better compile the whole package : A few minutes.

When coreutils-<version>/lib/configmake.h and ///src/version.h are generated,
just then it is possible to compile a standalone object, like :
gcc -std=gnu99 -I../lib -static -O2 -g -MT uniq.o -MD -MP -MF .deps/uniq.Tpo -c -o uniq.o uniq.c

But you can of course do make in the top directory, then you have the two files :
configmake.h, version.h, which you can use in another coreutils-<version>, same version.

..

theNbomr 03-13-2011 11:36 AM

You should be able to find source tarballs for all Gnu software. To build these packages, the usual steps are (after unpacking the tarball, and making the source code package directory you current working directory), as a normal user:
Code:

./configure
make
sudo make install
##  ... or...
su -c 'make install'

Note that only the installation step requires root privileges.

--- rod.

gnashley 03-13-2011 02:11 PM

Yes you can compile individual bins from coreutils. Jzs run configure, then cd into the various subdirs in the right order !-search the Makefile for the string 'subdir' to find the order. Probably po m4 etc, the main ones are 'lib' which needs to be done before 'src'. Once lib and all other required ones are done, cd into src and run 'make stat(or whichever pro you want). This is not always the case, but coreutils does have a separate Makefile rule for each binary.


All times are GMT -5. The time now is 10:35 AM.