Diff markup
001 001
002 002
003 003
004 004
005 005
006 006
007 007
008 008
009 009
010 010
011 011
012 012
013 013
014 014
015 015
016 016
017 017
018 CC=gcc 018 CC=gcc
019 AR=ar 019 AR=ar
>> 020 CP=cp
>> 021 STRIP=strip
020 OBJCOPY=objcopy 022 OBJCOPY=objcopy
021 CFLAGS = -Wall -nostdinc -ffreestanding -I. - !! 023 CFLAGS = -Wall -nostdinc -ffreestanding -I. -I.. -O
022 LIBGCC := $(shell $(CC) -print-libgcc-file-nam !! 024 LIBGCC = $(shell $(CC) -print-libgcc-file-name)
023 LDFLAGS = -Wl,--warn-common -nostdlib -Wl,-Tld 025 LDFLAGS = -Wl,--warn-common -nostdlib -Wl,-Tldscript.lds
024 026
025 027
026 all: userprogs.kimg 028 all: userprogs.kimg
027 029
028 -include .mkvars 030 -include .mkvars
029 031
030 PROGS := myprog1 myprog2 myprog3 myprog4 mypro !! 032 PROGS := init myprog1 myprog2 myprog3 myprog4 myprog5 myprog6 \
>> 033 myprog7 myprog8 myprog9 myprog10 myprog11 myprog12 \
>> 034 myprog13 myprog14 banner fstest chartest blktest shell
031 035
032 # Build dependencies of the programs 036 # Build dependencies of the programs
>> 037 init: fstest_utils.o
>> 038 fstest: fstest_utils.o
>> 039 chartest: fstest_utils.o
>> 040 blktest: fstest_utils.o
>> 041 shell: fstest_utils.o
033 $(PROGS) : % : %.o crt.o libc.a 042 $(PROGS) : % : %.o crt.o libc.a
034 043
035 PWD := $(shell pwd) !! 044 PWD := $(shell pwd | sed 's/"/\\\"/g;s/\$$/\\\$$/g')
036 045
037 046
038 $(PROGS): 047 $(PROGS):
039 $(CC) -static $(LDFLAGS) -o $@ $^ $(LI 048 $(CC) -static $(LDFLAGS) -o $@ $^ $(LIBGCC)
040 049
041 050
042 libc.a: libc.o string.o stdarg.o debug.o 051 libc.a: libc.o string.o stdarg.o debug.o
043 052
044 053
045 userprogs.kimg: $(PROGS) 054 userprogs.kimg: $(PROGS)
046 @echo "# Generating ELF images for inc 055 @echo "# Generating ELF images for inclusion into the kernel image: $@"
047 @echo "SECTIONS { .userprogs . : { " > 056 @echo "SECTIONS { .userprogs . : { " > .userprogs.lds
048 @i=0 ; 057 @i=0 ; \
049 for f in $^ ; do 058 for f in $^ ; do \
050 i=`expr $$i + 1` ; 059 i=`expr $$i + 1` ; \
051 echo "extern char _begin_userprog$$ 060 echo "extern char _begin_userprog$$i, _end_userprog$$i;" \
052 > .userprog$$i.c ; 061 > .userprog$$i.c ; \
053 echo "char *_userprog"$$i"_entry[]" 062 echo "char *_userprog"$$i"_entry[]" >> .userprog$$i.c ; \
054 echo " __attribute__((section(\".u 063 echo " __attribute__((section(\".userprogs_table\")))" \
055 >> .userprog$$i.c ; 064 >> .userprog$$i.c ; \
056 echo " = { \"$$f\", &_begin_userpr 065 echo " = { \"$$f\", &_begin_userprog$$i, &_end_userprog$$i };" \
057 >> .userprog$$i.c ; 066 >> .userprog$$i.c ; \
058 $(CC) $(CFLAGS) -c .userprog$$i.c - 067 $(CC) $(CFLAGS) -c .userprog$$i.c -o .userprog$$i.o ; \
059 $(OBJCOPY) --add-section .userprog$ !! 068 $(CP) $$f $$f.strip && $(STRIP) -sx $$f.strip ; \
>> 069 $(OBJCOPY) --add-section .userprog$$i=$$f.strip .userprog$$i.o \
060 .userprog$$i.kimg ; 070 .userprog$$i.kimg ; \
061 echo " . = ALIGN(4096);" >> .userp 071 echo " . = ALIGN(4096);" >> .userprogs.lds ; \
062 echo " _begin_userprog$$i = .;" >> 072 echo " _begin_userprog$$i = .;" >> .userprogs.lds ; \
063 echo " .userprog$$i.kimg(.userprog 073 echo " .userprog$$i.kimg(.userprog$$i);" >> .userprogs.lds ; \
064 echo " _end_userprog$$i = .;" >> . 074 echo " _end_userprog$$i = .;" >> .userprogs.lds ; \
065 echo " .userprog$$i.kimg(.rodata); 075 echo " .userprog$$i.kimg(.rodata); .userprog$$i.kimg(.data);" \
066 >> .userprogs.lds ; 076 >> .userprogs.lds ; \
067 done 077 done
068 @echo " _userprogs_table = .; *(.user 078 @echo " _userprogs_table = .; *(.userprogs_table) ; LONG(0);" \
069 >> .userprogs.lds 079 >> .userprogs.lds
070 @echo "} /DISCARD/ : { *(.text) *(.dat 080 @echo "} /DISCARD/ : { *(.text) *(.data) *(.bss) } }" \
071 >> .userprogs.lds 081 >> .userprogs.lds
072 @$(LD) -r -o $@ -T.userprogs.lds 082 @$(LD) -r -o $@ -T.userprogs.lds
073 083
074 084
075 %.a: 085 %.a:
076 $(AR) rcv $@ $^ 086 $(AR) rcv $@ $^
077 087
078 088
079 %.o: %.c 089 %.o: %.c
080 $(CC) -I$(PWD) -c $< $(CFLAGS) -o $@ !! 090 $(CC) "-I$(PWD)" -c "$<" $(CFLAGS) -o "$@"
081 091
082 092
083 %.o: %.S 093 %.o: %.S
084 $(CC) -I$(PWD) -c $< $(CFLAGS) -DASM_S !! 094 $(CC) "-I$(PWD)" -c "$<" $(CFLAGS) -DASM_SOURCE=1 -o "$@"
085 095
086 096
087 clean: 097 clean:
088 $(RM) *.o *.a *~ $(PROGS) *.kimg !! 098 $(RM) *.o *.a *~ $(PROGS) *.kimg *.strip
089 $(RM) .userprog* 099 $(RM) .userprog*