[RFC] build system replacement
Denys Vlasenko
vda.linux at googlemail.com
Fri May 30 15:42:06 PDT 2008
On Thursday 29 May 2008 19:31, Bernd Schmidt wrote:
> Denys Vlasenko wrote:
> > I noticed that uclibc build system is broken.
> > After I touch a file, running make won't rebuild it.
>
> As far as I can tell, only files that go into libc.so and not into
> libc.a, such as forward.c from libpthread, are affected. This seems to
> have been broken by revision 12519, which changed some Makefiles to give
> rules to build lib/libc.so, but the target we're trying to build is
> still lib/libc.so.0.
>
> > So I decided to replace build system, using my
> > experience in replacing build system for busybox.
>
> We can't rewrite entire subsystems everytime we find a bug. Better to
> understand what's wrong: in this case the fix is quite simple. Try the
> patch below.
Of course. I am actually not a kind of guy who likes rewriting stuff.
(Rob Landley, for example, is that kind of guy).
I just looked into existing build system and found it to differ significantly
from kernel's and to look too complex. Why every directory has two Makefiles,
isn't one enough? The Makefiles look more complex than e.g. in kernel.
The new system I have worked on simplifies these Makefiles.
Example 1: makefiles in libc/termios:
Current system (comments are not shown):
Makefile:
=========
top_srcdir=../../
top_builddir=../../
all: objs
include $(top_builddir)Rules.mak
include Makefile.in
include $(top_srcdir)Makerules
Makefile.in:
============
TERMIOS_DIR := $(top_srcdir)libc/termios
TERMIOS_OUT := $(top_builddir)libc/termios
TERMIOS_SRC := $(wildcard $(TERMIOS_DIR)/*.c)
TERMIOS_OBJ := $(patsubst $(TERMIOS_DIR)/%.c,$(TERMIOS_OUT)/%.o,$(TERMIOS_SRC))
libc-y += $(TERMIOS_OBJ)
objclean-y += termios_objclean
termios_objclean:
$(RM) $(TERMIOS_OUT)/*.{o,os}
New system needs single, one-line makefile:
Kbuild:
=======
klib-y := $(notdir $(wildcard $(obj)/*.c))
Example 2 (more complex): libc/stdlib. Sizes of files:
# wc Makefile Makefile.in
13 37 297 Makefile
93 300 3033 Makefile.in
106 337 3330 total
# wc Kbuild
59 231 2229 Kbuild
Makefile:
=========
top_srcdir=../../
top_builddir=../../
all: objs
include $(top_builddir)Rules.mak
include Makefile.in
include $(top_srcdir)Makerules
Makefile.in
===========
include $(top_srcdir)libc/stdlib/malloc/Makefile.in
include $(top_srcdir)libc/stdlib/malloc-simple/Makefile.in
include $(top_srcdir)libc/stdlib/malloc-standard/Makefile.in
CSRC := \
abort.c getenv.c mkdtemp.c mktemp.c realpath.c mkstemp.c \
rand.c random.c random_r.c setenv.c system.c div.c ldiv.c lldiv.c \
getpt.c ptsname.c grantpt.c unlockpt.c drand48-iter.c jrand48.c \
jrand48_r.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \
nrand48_r.c rand_r.c srand48.c srand48_r.c seed48.c seed48_r.c \
valloc.c posix_memalign.c a64l.c l64a.c __uc_malloc.c
ifeq ($(UCLIBC_HAS_ARC4RANDOM),y)
CSRC += arc4random.c
endif
ifeq ($(UCLIBC_HAS_LFS),y)
CSRC += mkstemp64.c
endif
ifeq ($(UCLIBC_HAS_FLOATS),y)
CSRC += drand48.c drand48_r.c erand48.c erand48_r.c
ifeq ($(UCLIBC_SUSV3_LEGACY),y)
CSRC += gcvt.c
endif
endif
# multi source stdlib.c
CSRC += abs.c labs.c atoi.c atol.c strtol.c strtoul.c _stdlib_strto_l.c \
qsort.c bsearch.c \
llabs.c atoll.c strtoll.c strtoull.c _stdlib_strto_ll.c
# (aliases) strtoq.o strtouq.o
ifeq ($(UCLIBC_HAS_FLOATS),y)
CSRC += atof.c
endif
ifeq ($(UCLIBC_HAS_XLOCALE),y)
CSRC += strtol_l.c strtoul_l.c _stdlib_strto_l_l.c \
strtoll_l.c strtoull_l.c _stdlib_strto_ll_l.c
endif
ifeq ($(UCLIBC_HAS_WCHAR),y)
CSRC += mblen.c mbtowc.c wctomb.c mbstowcs.c wcstombs.c \
_stdlib_mb_cur_max.c _stdlib_wcsto_l.c _stdlib_wcsto_ll.c \
wcstol.c wcstoul.c wcstoll.c wcstoull.c
ifeq ($(UCLIBC_HAS_XLOCALE),y)
CSRC +=_stdlib_wcsto_l_l.c _stdlib_wcsto_ll_l.c \
wcstol_l.c wcstoul_l.c wcstoll_l.c wcstoull_l.c
endif
endif
# multi source _strtod.c
ifeq ($(UCLIBC_HAS_FLOATS),y)
CSRC += strtod.c strtof.c strtold.c __strtofpmax.c __fp_range_check.c
ifeq ($(UCLIBC_HAS_XLOCALE),y)
CSRC += strtod_l.c strtof_l.c strtold_l.c __strtofpmax_l.c
endif
ifeq ($(UCLIBC_HAS_WCHAR),y)
CSRC += wcstod.c wcstof.c wcstold.c __wcstofpmax.c
ifeq ($(UCLIBC_HAS_XLOCALE),y)
CSRC += wcstod_l.c wcstof_l.c wcstold_l.c __wcstofpmax_l.c
endif
endif
endif
# (aliases) wcstoq.o wcstouq.o
# wcstod wcstof wcstold
# multi source _atexit.c
CSRC += __cxa_atexit.c __cxa_finalize.c __exit_handler.c exit.c on_exit.c
ifeq ($(COMPAT_ATEXIT),y)
CSRC += old_atexit.c
endif
STDLIB_DIR := $(top_srcdir)libc/stdlib
STDLIB_OUT := $(top_builddir)libc/stdlib
STDLIB_SRC := $(patsubst %.c,$(STDLIB_DIR)/%.c,$(CSRC))
STDLIB_OBJ := $(patsubst %.c,$(STDLIB_OUT)/%.o,$(CSRC))
libc-y += $(STDLIB_OBJ)
libc-static-y += $(STDLIB_OUT)/atexit.o
# this should always be the PIC version, because it could be used in shared libs
libc-nonshared-y += $(STDLIB_OUT)/atexit.os
libc-nomulti-y += $(STDLIB_OUT)/labs.o $(STDLIB_OUT)/atol.o $(STDLIB_OUT)/_stdlib_strto_l.o $(STDLIB_OUT)/_stdlib_strto_ll.o
libc-nomulti-$(UCLIBC_HAS_XLOCALE) += $(STDLIB_OUT)/_stdlib_strto_l_l.o $(STDLIB_OUT)/_stdlib_strto_ll_l.o
objclean-y += stdlib_objclean
stdlib_objclean:
$(RM) $(STDLIB_OUT)/*.{o,os,oS}
New system:
Kbuild:
=======
klib-y += malloc/
klib-y += malloc-simple/
klib-y += malloc-standard/
klib-y += \
abort.c getenv.c mkdtemp.c mktemp.c realpath.c mkstemp.c \
rand.c random.c random_r.c setenv.c system.c div.c ldiv.c lldiv.c \
getpt.c ptsname.c grantpt.c unlockpt.c drand48-iter.c jrand48.c \
jrand48_r.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \
nrand48_r.c rand_r.c srand48.c srand48_r.c seed48.c seed48_r.c \
valloc.c posix_memalign.c a64l.c l64a.c __uc_malloc.c
klib-$(UCLIBC_HAS_ARC4RANDOM) += arc4random.c
klib-$(UCLIBC_HAS_LFS) += mkstemp64.c
klib-$(UCLIBC_HAS_FLOATS) += drand48.c drand48_r.c erand48.c erand48_r.c
klib-$(UCLIBC_SUSV3_LEGACY) += gcvt.c
# multi source stdlib.c
klib-y += \
abs.c labs.c atoi.c atol.c strtol.c strtoul.c _stdlib_strto_l.c \
qsort.c bsearch.c \
llabs.c atoll.c strtoll.c strtoull.c _stdlib_strto_ll.c
# (aliases) strtoq.o strtouq.o
klib-$(UCLIBC_HAS_FLOATS) += atof.c
klib-$(UCLIBC_HAS_XLOCALE) += strtol_l.c strtoul_l.c _stdlib_strto_l_l.c \
strtoll_l.c strtoull_l.c _stdlib_strto_ll_l.c
ifeq ($(UCLIBC_HAS_WCHAR),y)
klib-y += \
mblen.c mbtowc.c wctomb.c mbstowcs.c wcstombs.c \
_stdlib_mb_cur_max.c _stdlib_wcsto_l.c _stdlib_wcsto_ll.c \
wcstol.c wcstoul.c wcstoll.c wcstoull.c
klib-$(UCLIBC_HAS_XLOCALE) +=_stdlib_wcsto_l_l.c _stdlib_wcsto_ll_l.c \
wcstol_l.c wcstoul_l.c wcstoll_l.c wcstoull_l.c
endif
# multi source _strtod.c
ifeq ($(UCLIBC_HAS_FLOATS),y)
klib-y += strtod.c strtof.c strtold.c __strtofpmax.c __fp_range_check.c
klib-$(UCLIBC_HAS_XLOCALE) += strtod_l.c strtof_l.c strtold_l.c __strtofpmax_l.c
ifeq ($(UCLIBC_HAS_WCHAR),y)
klib-y += wcstod.c wcstof.c wcstold.c __wcstofpmax.c
klib-$(UCLIBC_HAS_XLOCALE) += wcstod_l.c wcstof_l.c wcstold_l.c __wcstofpmax_l.c
endif
endif
# (aliases) wcstoq.o wcstouq.o
# wcstod wcstof wcstold
# multi source _atexit.c
klib-y += __cxa_atexit.c __cxa_finalize.c __exit_handler.c exit.c on_exit.c
klib-$(COMPAT_ATEXIT) += old_atexit.c
# This goes only into libc.a, not libc_so.a
klib-nonshared-y += atexit.o
More information about the uClibc
mailing list