CFLAGS+=-Wall -Werror -fno-builtin -static -g PROGS=libcstrlen ARCH!=uname -m .if ${ARCH} == i386 PROGS+=asmstrlen .endif PROGS+=basestrlen strlen strlen2 all: ${PROGS} # Just link against libc. libcstrlen: main.c gcc ${CFLAGS} -o ${.TARGET} ${.ALLSRC} # Assembly version of strlen pulled out of libc. asmstrlen: main.c strlen.S gcc -DTESTLEN ${CFLAGS} -o ${.TARGET} ${.ALLSRC} # C version of strlen pulled out of libc. basestrlen: main.c basestrlen.c gcc -DTESTLEN ${CFLAGS} -o ${.TARGET} ${.ALLSRC} # Word-searching version of strlen. Original version. strlen: main.c strlen.c gcc -DTESTLEN ${CFLAGS} -o ${.TARGET} ${.ALLSRC} # Word-searching version of strlen. Simpler to read and about the same speed. strlen2: main.c strlen2.c gcc -DTESTLEN ${CFLAGS} -o ${.TARGET} ${.ALLSRC} # Generate random strings for testing but only during testing. .ifmake test STRLENS=1 2 3 4 5 6 7 8 9 10 14 16 18 32 64 256 .for ndx in ${STRLENS} STR[${ndx}]!=jot -r -c ${ndx} a z | rs -g 0 ${ndx} .endfor .endif # Test increasing lengths of strings against each program. test: ${PROGS} .for prog in ${PROGS} .for ndx in ${STRLENS} @./${prog} ${STR[${ndx}]} .endfor @echo "" .endfor clean: rm -f *.o *~ ${PROGS} *.core *.gmon