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