ARTIFACT         = PoolBox
make_assets      = $(MAKE) $(1) ARTIFACT=$(ARTIFACT) -C assets
make_application = $(MAKE) $(1) ARTIFACT=$(ARTIFACT) -C application
make_cd          = $(MAKE) $(1) ARTIFACT=$(ARTIFACT) -C iso

ifndef REGION
$(error REGION has to be set!)
endif

# Add regions on your own
# Extend them with what you need
ifeq ($(REGION),SCEE)
    export PSX_TV_FORMAT=PAL
    export PSX_LICENSE=LICENSEE
    export PSX_BOOT_FILE=SLES_AAA.AA
endif
ifeq ($(REGION),SCEA)
    export PSX_TV_FORMAT=NTSC
    export PSX_LICENSE=LICENSEA
    export PSX_BOOT_FILE=SLUS_AAA.AA
endif
ifeq ($(REGION),SCEI)
    export PSX_TV_FORMAT=NTSC
    export PSX_LICENSE=LICENSEJ
    export PSX_BOOT_FILE=SLJS_AAA.AA
endif

ifndef PSX_TV_FORMAT
$(error PSX_TV_FORMAT has not be set! REGION not specified?)
endif

ifndef PSX_LICENSE
$(error PSX_LICENSE has not be set! REGION not specified?)
endif

all clean rebuild: |assets_$(MAKECMDGOALS) application_$(MAKECMDGOALS) cd_$(MAKECMDGOALS)  

all_%: always
	$(call make_assets,$*)
	$(call make_application,$*)
	$(call make_cd,$*)

assets_%: always
	$(call make_assets,$*)
application_%: always
	$(call make_application,$*)
cd_%: always
	$(call make_cd,$*)
pkg_%: always
	$(call make_cd,pkg_$*)

always: ;