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