better Makefile

This commit is contained in:
theverygaming 2023-02-22 09:59:59 +01:00
parent 2235d2f5b1
commit 1d6aa605fb
3 changed files with 38 additions and 21 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
**/.vscode/ **/.vscode/
*.o
fox32.rom fox32.rom
fox32rom.h fox32rom.h

View File

@ -1,12 +1,27 @@
TARGET = linux
ifeq ($(TARGET),linux)
# default is used for CC
SDL2_CONFIG = sdl2-config SDL2_CONFIG = sdl2-config
CFLAGS = -g -Ofast -std=c99 -Wall -Wextra `$(SDL2_CONFIG) --cflags --libs` CFLAGS += -g -Ofast -std=c99 -Wall -Wextra `$(SDL2_CONFIG) --cflags`
CC_WIN = x86_64-w64-mingw32-gcc LDFLAGS += `$(SDL2_CONFIG) --libs`
CFLAGS_WIN = -g -Ofast -std=c99 -Wall -Wextra -lmingw32 -lSDL2main -lSDL2 else
CC_WASM = emcc ifeq ($(TARGET),mingw)
CFLAGS_WASM = -O3 -std=c99 -Wall -Wextra -s TOTAL_MEMORY=70057984 -sALLOW_MEMORY_GROWTH=1 -sUSE_SDL=2 --preload-file fox32os.img CC = x86_64-w64-mingw32-gcc
TARGET=fox32 CFLAGS += -g -Ofast -std=c99 -Wall -Wextra
TARGET_WIN=fox32.exe LDFLAGS += -lmingw32 -lSDL2main -lSDL2
TARGET_WASM=fox32.html TARGET_FILE_EXTENSION = .exe
else
ifeq ($(TARGET),wasm)
CC = emcc
CFLAGS += -O3 -std=c99 -Wall -Wextra
LDFLAGS += -s TOTAL_MEMORY=70057984 -sALLOW_MEMORY_GROWTH=1 -sUSE_SDL=2 --preload-file fox32os.img
TARGET_EXTRADEPS = fox32os.img
TARGET_FILE_EXTENSION = .html
else
$(error unknown TARGET)
endif
endif
endif
CFILES = src/main.c \ CFILES = src/main.c \
src/bus.c \ src/bus.c \
@ -19,23 +34,23 @@ CFILES = src/main.c \
src/screen.c \ src/screen.c \
src/serial.c src/serial.c
OBJS = $(addsuffix .o, $(basename $(CFILES)))
.PHONY: all
all: fox32$(TARGET_FILE_EXTENSION)
FOX32ROM_IN = fox32.rom FOX32ROM_IN = fox32.rom
FOX32ROM_OUT = fox32rom.h FOX32ROM_OUT = fox32rom.h
$(TARGET): $(CFILES) $(FOX32ROM_IN) $(FOX32ROM_OUT): $(FOX32ROM_IN)
xxd -i $(FOX32ROM_IN) $(FOX32ROM_OUT) xxd -i $(FOX32ROM_IN) $(FOX32ROM_OUT)
sed -i -e 's/fox32_rom/fox32rom/' fox32rom.h sed -i -e 's/fox32_rom/fox32rom/' $(FOX32ROM_OUT)
$(CC) -o $@ $(filter %.c, $^) $(CFLAGS)
$(TARGET_WIN): $(CFILES) fox32$(TARGET_FILE_EXTENSION): $(TARGET_EXTRADEPS) $(OBJS)
xxd -i $(FOX32ROM_IN) $(FOX32ROM_OUT) $(CC) -o $@ $(OBJS) $(LDFLAGS)
sed -i -e 's/fox32_rom/fox32rom/' fox32rom.h
$(CC_WIN) -o $@ $(filter %.c, $^) $(CFLAGS_WIN)
$(TARGET_WASM): $(CFILES) $(FOX32ROM_IN) %.o: %.c $(FOX32ROM_OUT)
xxd -i $(FOX32ROM_IN) $(FOX32ROM_OUT) $(CC) -o $@ -c $< $(CFLAGS)
sed -i -e 's/fox32_rom/fox32rom/' fox32rom.h
$(CC_WASM) -o $@ $(filter %.c, $^) $(CFLAGS_WASM)
clean: clean:
rm -rf $(TARGET) $(TARGET_WIN) $(TARGET_WASM) rm -rf fox32 fox32.exe fox32.wasm fox32.html fox32.data fox32.js fox32rom.h $(OBJS)

View File

@ -17,7 +17,7 @@ Prebuilt Linux binaries of the latest commit are also available on the [GitHub A
### Building ### Building
Download the latest release or commit of [**fox32rom**](https://github.com/fox32-arch/fox32rom), and place the downloaded `fox32.rom` file into the root directory of this repo. Then simply run `make`. The resulting binary will be saved as `fox32`. Download the latest release or commit of [**fox32rom**](https://github.com/fox32-arch/fox32rom), and place the downloaded `fox32.rom` file into the root directory of this repo. Then simply run `make`. The resulting binary will be saved as `fox32`. Optionally you may build for a different target with `make TARGET=<target>`, see the Makefile for details.
### Usage ### Usage