Help with usbasp bootloader port on Atmega328p

I have a speare Atmega328p-pu and a 16Mhz crystall + caps.I found this project USBasp - USB programmer for Atmel AVR controllers - fischl.de
How do i port the code.I know i have to set F_CPU at 16Mhz but other things might need tweaking.Also these fuses are ok -U lfuse:w:0xef:m -U hfuse:w:0xca:m -U efuse:w:0xfc:m ?
If someone could post a step by step guide it would be much easier since i do not have experience with MHV AVr or WinAVR.I have an usbtiny programmer but is useless at writing the bootloader Atmega2560 on Arduino Mega.Also sorry for late replaying.Not entering forum very often,but i hope someone can at least direct me to some usefull material.

The ATmega328P is not the same as the ATmega8.
Buy and ATmega8 or buy a USBasp version 2.

It is really not worth it to try to make the ATmega328P work as USBasp. Please forget about it.

I have read that a bootloader for an ATmega (was it the ATmega328P ?) also acts as USBasp. That is very interesting. Another very interesting thing is the Trinket Pro. The Trinket Pro is not a programmer, but it has usb without extra usb-serial chip.

Your options are:

Why not just buy a USBAsp programmer for under $5 on ebay?

So building one is out of discution (with an atmega328p).Other programmers that can write onto chips like atmega2560 i don't know.(asaide from avr isp mk2 witch is too expensive).
Instead of buying i liked if i could make one myself for diy sake.Also i have an arduino micro.I think i can use it as isp.(I don't have an uno,just a mega2560 and a micro).
Anyway thanks.I'll probably buy an Atmega8 :sunglasses:

I use the USBasp version 2 for the Arduino Mega 2560 board as well. I also bought a 10-pin to 6-pin adapter on Ebay.
Not every version of USBasp on Ebay is the same, you need a little luck to get a good one.
It is possible to use one USBasp to update the firmware of an other USBasp, but if the target USBasp is not compatible with an original USBasp, then it won't work anymore.

If you want to build a dedicated programmer, and you're using ATmega328P and some sort of FTDI-like USB interface chip, all you need to do is upload the Arduino as ISP sketch to it. That would be the easy way, and it should work well. You don't need to worry about porting the usbasp firmware.

Edit: Also, a genuine or clone Pro Micro works well as dedicated programmer, running the Arduino as ISP sketch.

As i said ,i have an arduino micro (atmega 32u4 i think).I think i'll also buy a ft232rl and build a uno clone.As for usbasp i'll definetley build it.I already built an usbtinyisp based on attiny85(i think it was the little wire project,it also has a cdc-232 frimwere but on win8 i could't get it working,the cdc-232 driver is incompatible for win8).http://littlewire.cc/

PS: Also where do i find the driver for the unknown device (Arduino Micro)?

C:\Program Files\Arduino\drivers

Sory for late posting.I made a version with an atmega 8 on a perf board.However I get the error initialization failed rc=-1.
"
avrdude: error: programm enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check."
pins on avr:16-reset
17-MOSI
18-MISO
19-SCK
I hope i haven't connected them wrong to the target arduino mega.
Also i reflashed the firmware several times with the latest version and the second last .
It is recognized by the pc and all drivers are installed and working.Currently i erased the chip completely and next days i'll take a break.I hope it just something minor.
Thank you.

PS:-B flag does not help.Tried:32,50,100
Also instead of 270 ohms resistors i used 220 ohms and 1,8 kohms for pullup,100 ohms for usb lines,and removed the leds+resistors.I have one smd ceramic cap of 100nf in parallel with a 100 microfarads electrolitic cap.