Onder FreeBSD ben ik bezig met een programmeerprojectje. Ik loop echter tegen eigenzinnige Makefiles aan.
Onderdeel van het project is de statische library libc.a. Deze status gelinkt met het resultaat, omdat het hier om een OS-onafhankelijk stuk software gaat, maar dat doet niet zo ter zake. Ik heb problemen met het tot stand komen van libc.a
In de libc directory heb ik 2 subdirs: ctype en stdio.h. Beide hebben 1 of meer c-bestanden. Makefile moet die c-bestanden indien ze zijn gewijzigd compilen tot o-bestanden en updaten in libc.a.
Directory-structuur:
Makefile:
stdio/Makefile
ctype/Makefile:
Probleem: Als ik met 'make' libc.a wil maken, dan worden de o-bestanden van stdio NIET geupdate/opgenomen in libc.a.
Als ik echter opnieuw 'make' draai (zonder dat er iets is veranderd!) worden de veranderingen alsnog doorgevoerd.
Dit ziet er zo uit:
Hierdoor gaat het compilen van het gehele project uiteraard mis, omdat die make niet in een keer goed gaat, maar 2 keer achter elkaar uitgevoerd moet worden.
Nu komt het gekke: Als ik die o-bestanden in de twee subdirectories door gmake aanmaak en invoeg, dan wil het wel. In de makefile de regel "MAKE = exec make # -$(MAKEFLAGS)" veranderen in "MAKE = exec gmake # -$(MAKEFLAGS)" en het probleem is uit de wereld.
Hoe kan dat? Wat maakt dat die FreeBSD make met deze drie Makefiles niet in een keer z'n werk goed doet?
Onderdeel van het project is de statische library libc.a. Deze status gelinkt met het resultaat, omdat het hier om een OS-onafhankelijk stuk software gaat, maar dat doet niet zo ter zake. Ik heb problemen met het tot stand komen van libc.a
In de libc directory heb ik 2 subdirs: ctype en stdio.h. Beide hebben 1 of meer c-bestanden. Makefile moet die c-bestanden indien ze zijn gewijzigd compilen tot o-bestanden en updaten in libc.a.
Directory-structuur:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| Makefile ctype ctype/Makefile ctype/toupper.c stdio stdio/Makefile stdio/printf.c stdio/doprnt.c stdio/stdio_internal.h stdio/icompute.c stdio/putc.c stdio/data.c |
Makefile:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| # Makefile for the libraries
# This makefile runs make in all the subdirectories of the src/lib tree.
# See ansi/Makefile for a further explanation.
MAKE = exec make # -$(MAKEFLAGS)
all:
cd ctype && $(MAKE)
cd stdio && $(MAKE)
clean:
rm -rf libc.a
cd stdio && $(MAKE) clean
cd ctype && $(MAKE) clean |
stdio/Makefile
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| CC=gcc
CFLAGS=-Wall -ffreestanding -nostdlib -fomit-frame-pointer -nostdinc -I../../../include -O2
CC1=$(CC) $(CFLAGS) -c
LIBRARY=../libc.a
all: $(LIBRARY)
OBJECTS = \
$(LIBRARY)(data.o) \
$(LIBRARY)(icompute.o) \
$(LIBRARY)(doprnt.o) \
$(LIBRARY)(putc.o) \
$(LIBRARY)(printf.o)
$(LIBRARY): $(OBJECTS)
ar ruv $(LIBRARY) *.o
rm *.o
clean:
rm -f ./*~ $(LIBRARY) *.o |
ctype/Makefile:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| CC=gcc
CFLAGS=-Wall -ffreestanding -nostdlib -fomit-frame-pointer -nostdinc -I../../../include -O2
CC1=$(CC) $(CFLAGS) -c
LIBRARY=../libc.a
all: $(LIBRARY)
OBJECTS = \
$(LIBRARY)(toupper.o)
$(LIBRARY): $(OBJECTS)
ar ruv $(LIBRARY) *.o
rm *.o
clean:
rm -f ./*~ $(LIBRARY) *.o |
Probleem: Als ik met 'make' libc.a wil maken, dan worden de o-bestanden van stdio NIET geupdate/opgenomen in libc.a.
Als ik echter opnieuw 'make' draai (zonder dat er iets is veranderd!) worden de veranderingen alsnog doorgevoerd.
Dit ziet er zo uit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| [simon@a:~/files/Projects/YaBM/src/core/libc]$ make clean rm -rf libc.a cd stdio && exec make clean rm -f ./*~ ../libc.a *.o cd ctype && exec make clean rm -f ./*~ ../libc.a *.o [simon@a:~/files/Projects/YaBM/src/core/libc]$ make cd ctype && exec make gcc -Wall -ffreestanding -nostdlib -fomit-frame-pointer -nostdinc -I../../../include -O2 -c toupper.c ar ruv ../libc.a *.o ar: creating ../libc.a a - toupper.o rm *.o cd stdio && exec make gcc -Wall -ffreestanding -nostdlib -fomit-frame-pointer -nostdinc -I../../../include -O2 -c data.c gcc -Wall -ffreestanding -nostdlib -fomit-frame-pointer -nostdinc -I../../../include -O2 -c icompute.c gcc -Wall -ffreestanding -nostdlib -fomit-frame-pointer -nostdinc -I../../../include -O2 -c doprnt.c gcc -Wall -ffreestanding -nostdlib -fomit-frame-pointer -nostdinc -I../../../include -O2 -c putc.c gcc -Wall -ffreestanding -nostdlib -fomit-frame-pointer -nostdinc -I../../../include -O2 -c printf.c [simon@a:~/files/Projects/YaBM/src/core/libc]$ make cd ctype && exec make cd stdio && exec make ar ruv ../libc.a *.o a - data.o a - doprnt.o a - icompute.o a - printf.o a - putc.o rm *.o [simon@a:~/files/Projects/YaBM/src/core/libc]$ make cd ctype && exec make cd stdio && exec make [simon@a:~/files/Projects/YaBM/src/core/libc]$ |
Hierdoor gaat het compilen van het gehele project uiteraard mis, omdat die make niet in een keer goed gaat, maar 2 keer achter elkaar uitgevoerd moet worden.
Nu komt het gekke: Als ik die o-bestanden in de twee subdirectories door gmake aanmaak en invoeg, dan wil het wel. In de makefile de regel "MAKE = exec make # -$(MAKEFLAGS)" veranderen in "MAKE = exec gmake # -$(MAKEFLAGS)" en het probleem is uit de wereld.
Hoe kan dat? Wat maakt dat die FreeBSD make met deze drie Makefiles niet in een keer z'n werk goed doet?