This depends entirely on your country, but in most cases adrafinil is unscheduled and thus legal to purchase. The legal status of adrafinil by country is as follows:
US - Unscheduled
Canada - Unregulated
United Kingdom - Unscheduled
Australia - Schedule 4 - POM (Prescription Only Medicine)
Japan - Unscheduled according to some people[1]