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