Merge pull request #60 from osnr/osnr/fix-mac-build
Add support for macOS and Emscripten builds
This commit is contained in:
@@ -37,7 +37,7 @@ ifeq ($(OS),Windows_NT)
|
|||||||
TEST_FILE := $(DIST_DIR)/run-test.exe
|
TEST_FILE := $(DIST_DIR)/run-test.exe
|
||||||
endif
|
endif
|
||||||
|
|
||||||
DUMMY != mkdir -p $(ALL_DIRS) build/test build/test/gl33core build/test/gl20 src/decomp/mario $(DIST_DIR)/include
|
DUMMY := $(shell mkdir -p $(ALL_DIRS) build/test build/test/gl33core build/test/gl20 src/decomp/mario $(DIST_DIR)/include)
|
||||||
|
|
||||||
|
|
||||||
$(filter-out src/decomp/mario/geo.inc.c,$(IMPORTED)): src/decomp/mario/geo.inc.c
|
$(filter-out src/decomp/mario/geo.inc.c,$(IMPORTED)): src/decomp/mario/geo.inc.c
|
||||||
@@ -45,11 +45,11 @@ src/decomp/mario/geo.inc.c: ./import-mario-geo.py
|
|||||||
./import-mario-geo.py
|
./import-mario-geo.py
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: %.c $(IMPORTED)
|
$(BUILD_DIR)/%.o: %.c $(IMPORTED)
|
||||||
@$(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
|
@$(CC) $(CFLAGS) -I src/decomp/include -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
|
||||||
$(CC) -c $(CFLAGS) -I src/decomp/include -o $@ $<
|
$(CC) -c $(CFLAGS) -I src/decomp/include -o $@ $<
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: %.cpp $(IMPORTED)
|
$(BUILD_DIR)/%.o: %.cpp $(IMPORTED)
|
||||||
@$(CXX) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
|
@$(CXX) $(CFLAGS) -I src/decomp/include -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
|
||||||
$(CXX) -c $(CFLAGS) -I src/decomp/include -o $@ $<
|
$(CXX) -c $(CFLAGS) -I src/decomp/include -o $@ $<
|
||||||
|
|
||||||
$(LIB_FILE): $(O_FILES)
|
$(LIB_FILE): $(O_FILES)
|
||||||
@@ -70,6 +70,8 @@ $(BUILD_DIR)/test/%.o: test/%.c
|
|||||||
$(TEST_FILE): $(LIB_FILE) $(TEST_OBJS)
|
$(TEST_FILE): $(LIB_FILE) $(TEST_OBJS)
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
$(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -lglew32 -lopengl32 -lSDL2 -lSDL2main -lm
|
$(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -lglew32 -lopengl32 -lSDL2 -lSDL2main -lm
|
||||||
|
else ifeq ($(shell uname -s),Darwin)
|
||||||
|
$(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -framework OpenGL -lGLEW -lSDL2 -lSDL2main -lm -lpthread
|
||||||
else
|
else
|
||||||
$(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -lGLEW -lGL -lSDL2 -lSDL2main -lm -lpthread
|
$(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -lGLEW -lGL -lSDL2 -lSDL2main -lm -lpthread
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ project under the `test` directory as well, demonstrating usage of the library.
|
|||||||
- [Godot add-on](https://github.com/Brawmario/libsm64-godot)
|
- [Godot add-on](https://github.com/Brawmario/libsm64-godot)
|
||||||
- [Game Maker 8 extension](https://github.com/headshot2017/libsm64-gm8)
|
- [Game Maker 8 extension](https://github.com/headshot2017/libsm64-gm8)
|
||||||
|
|
||||||
## Building on Linux
|
## Building on Mac and Linux
|
||||||
|
|
||||||
- Ensure python3 is installed.
|
- Ensure python3 is installed.
|
||||||
- Ensure the SDL2 and GLEW libraries are installed if you're building the test program (on Ubuntu: libsdl2-dev, libglew-dev).
|
- Ensure the SDL2 and GLEW libraries are installed if you're building the test program (on Ubuntu: libsdl2-dev, libglew-dev).
|
||||||
@@ -34,6 +34,17 @@ project under the `test` directory as well, demonstrating usage of the library.
|
|||||||
- Run `make` to build
|
- Run `make` to build
|
||||||
- To run the test program you'll need a SM64 US ROM in the root of the repository with the name `baserom.us.z64`.
|
- To run the test program you'll need a SM64 US ROM in the root of the repository with the name `baserom.us.z64`.
|
||||||
|
|
||||||
|
## Building for Emscripten (Web) (WIP)
|
||||||
|
|
||||||
|
Run `emmake make CC=emcc`.
|
||||||
|
|
||||||
|
If you want libsm64 standalone to call from JS (may not be that
|
||||||
|
useful?), then run `emcc dist/libsm64.so -o libsm64.js` afterward to
|
||||||
|
emit `libsm64.wasm` and `libsm64.js`.
|
||||||
|
|
||||||
|
Otherwise, `dist/libsm64.so` should be a compiled WebAssembly object
|
||||||
|
that you can link into your own C project.
|
||||||
|
|
||||||
## Make targets (all platforms)
|
## Make targets (all platforms)
|
||||||
|
|
||||||
- `make lib`: (Default) Build the `dist` directory, containing the shared object or DLL and public-facing header.
|
- `make lib`: (Default) Build the `dist` directory, containing the shared object or DLL and public-facing header.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
// #include "object_list_processor.h"
|
// #include "object_list_processor.h"
|
||||||
// #include "print.h"
|
// #include "print.h"
|
||||||
#include "save_file.h"
|
#include "save_file.h"
|
||||||
// #include "sound_init.h"
|
#include "sound_init.h"
|
||||||
// #include "thread6.h"
|
// #include "thread6.h"
|
||||||
#include "../../load_anim_data.h"
|
#include "../../load_anim_data.h"
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <seq_ids.h>
|
#include <seq_ids.h>
|
||||||
#include <sm64.h>
|
#include <sm64.h>
|
||||||
#include "sound_init.h"
|
#include "sound_init.h"
|
||||||
|
#include "../../play_sound.h"
|
||||||
//#include "rumble_init.h"
|
//#include "rumble_init.h"
|
||||||
|
|
||||||
#define MUSIC_NONE 0xFFFF
|
#define MUSIC_NONE 0xFFFF
|
||||||
|
|||||||
@@ -3,8 +3,13 @@
|
|||||||
|
|
||||||
#include "ultratypes.h"
|
#include "ultratypes.h"
|
||||||
|
|
||||||
|
// These are defined in macOS (BSD?), so we want to def them out.
|
||||||
|
#ifndef __APPLE__
|
||||||
|
|
||||||
// Old deprecated functions from strings.h, replaced by memcpy/memset.
|
// Old deprecated functions from strings.h, replaced by memcpy/memset.
|
||||||
extern void bcopy(const void *, void *, size_t);
|
extern void bcopy(const void *, void *, size_t);
|
||||||
extern void bzero(void *, size_t);
|
extern void bzero(void *, size_t);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !_OS_LIBC_H_ */
|
#endif /* !_OS_LIBC_H_ */
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
#include "convUtils.h"
|
#include "convUtils.h"
|
||||||
#include "convTypes.h"
|
#include "convTypes.h"
|
||||||
|
|
||||||
@@ -41,18 +42,18 @@ struct seqFile* parse_seqfile(unsigned char* seq){ /* Read SeqFile data */
|
|||||||
for (int i = 0; i < bankCount; i++){
|
for (int i = 0; i < bankCount; i++){
|
||||||
uintptr_t start = pos;
|
uintptr_t start = pos;
|
||||||
struct CTL* ptr = parse_ctl_data(seq+(seqFile->seqArray[i].offset), &pos);
|
struct CTL* ptr = parse_ctl_data(seq+(seqFile->seqArray[i].offset), &pos);
|
||||||
seqFile->seqArray[i].offset = ptr;
|
seqFile->seqArray[i].offset = (uintptr_t)ptr;
|
||||||
seqFile->seqArray[i].len = (unsigned int)(pos - start);
|
seqFile->seqArray[i].len = (unsigned int)(pos - start);
|
||||||
}
|
}
|
||||||
}else if (revision == TYPE_TBL){
|
}else if (revision == TYPE_TBL){
|
||||||
// TBL file, contains raw audio data
|
// TBL file, contains raw audio data
|
||||||
for (int i = 0; i < bankCount; i++){
|
for (int i = 0; i < bankCount; i++){
|
||||||
seqFile->seqArray[i].offset = seq+(seqFile->seqArray[i].offset);
|
seqFile->seqArray[i].offset = (uintptr_t)(seq+(seqFile->seqArray[i].offset));
|
||||||
}
|
}
|
||||||
}else if (revision == TYPE_SEQ){
|
}else if (revision == TYPE_SEQ){
|
||||||
// SEQ file, contains music files (*.m64)
|
// SEQ file, contains music files (*.m64)
|
||||||
for (int i = 0; i < bankCount; i++){
|
for (int i = 0; i < bankCount; i++){
|
||||||
seqFile->seqArray[i].offset = seq+(seqFile->seqArray[i].offset);
|
seqFile->seqArray[i].offset = (uintptr_t)(seq+(seqFile->seqArray[i].offset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,8 +157,8 @@ struct CSample* parse_sample(unsigned char* sample,unsigned char* ctl, uintptr_t
|
|||||||
*pos = ALIGN16(*pos);
|
*pos = ALIGN16(*pos);
|
||||||
samp->zero=read_u32_be(sample);
|
samp->zero=read_u32_be(sample);
|
||||||
samp->addr=read_u32_be(sample+4);
|
samp->addr=read_u32_be(sample+4);
|
||||||
samp->loop=read_u32_be(sample+8);// loop address
|
samp->loop=(struct CLoop*)read_u32_be(sample+8);// loop address
|
||||||
samp->book=read_u32_be(sample+12);// book address
|
samp->book=(struct CBook*)read_u32_be(sample+12);// book address
|
||||||
samp->sample_size=read_u32_be(sample+16);
|
samp->sample_size=read_u32_be(sample+16);
|
||||||
|
|
||||||
samp->book=parse_book(ctl+((uintptr_t)samp->book), pos);
|
samp->book=parse_book(ctl+((uintptr_t)samp->book), pos);
|
||||||
@@ -167,7 +168,7 @@ struct CSample* parse_sample(unsigned char* sample,unsigned char* ctl, uintptr_t
|
|||||||
|
|
||||||
struct CSound* parse_sound(unsigned char* sound,unsigned char* ctl, uintptr_t* pos, uintptr_t sndPos, struct SampleList* samples){
|
struct CSound* parse_sound(unsigned char* sound,unsigned char* ctl, uintptr_t* pos, uintptr_t sndPos, struct SampleList* samples){
|
||||||
struct CSound* snd = (struct CSound*)(sndPos);
|
struct CSound* snd = (struct CSound*)(sndPos);
|
||||||
snd->sample_addr=read_u32_be(sound);
|
snd->sample_addr=(struct CSample*)read_u32_be(sound);
|
||||||
snd->tuning = (float)read_f32_be(sound+4);
|
snd->tuning = (float)read_f32_be(sound+4);
|
||||||
// if sample_addr is 0 then the sound is null
|
// if sample_addr is 0 then the sound is null
|
||||||
if (snd->sample_addr!=0){
|
if (snd->sample_addr!=0){
|
||||||
@@ -196,8 +197,8 @@ struct CDrum* parse_drum(unsigned char* drum,unsigned char* ctl, uintptr_t* pos,
|
|||||||
drumData->pan = drum[1];
|
drumData->pan = drum[1];
|
||||||
drumData->loaded = drum[2];
|
drumData->loaded = drum[2];
|
||||||
drumData->pad = drum[3];
|
drumData->pad = drum[3];
|
||||||
drumData->snd=*parse_sound(drum+4,ctl, pos, &drumData->snd, samples);
|
drumData->snd=*parse_sound(drum+4,ctl, pos, (uintptr_t)&drumData->snd, samples);
|
||||||
drumData->env_addr=read_u32_be(drum+12);
|
drumData->env_addr=(struct CEnvelope*)read_u32_be(drum+12);
|
||||||
return drumData;
|
return drumData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,10 +227,10 @@ struct CInstrument* parse_instrument(unsigned char* instrument,unsigned char* ct
|
|||||||
inst->normal_range_lo = instrument[1];
|
inst->normal_range_lo = instrument[1];
|
||||||
inst->normal_range_hi = instrument[2];
|
inst->normal_range_hi = instrument[2];
|
||||||
inst->release_rate = instrument[3];
|
inst->release_rate = instrument[3];
|
||||||
inst->env_addr=read_u32_be(instrument+4);
|
inst->env_addr=(struct CEnvelope*)read_u32_be(instrument+4);
|
||||||
inst->sound_lo=*parse_sound(instrument+8,ctl, pos, &(inst->sound_lo), samples);
|
inst->sound_lo=*parse_sound(instrument+8,ctl, pos, (uintptr_t)&(inst->sound_lo), samples);
|
||||||
inst->sound_med=*parse_sound(instrument+16,ctl, pos, &(inst->sound_med), samples);
|
inst->sound_med=*parse_sound(instrument+16,ctl, pos, (uintptr_t)&(inst->sound_med), samples);
|
||||||
inst->sound_hi=*parse_sound(instrument+24,ctl, pos, &(inst->sound_hi), samples);
|
inst->sound_hi=*parse_sound(instrument+24,ctl, pos, (uintptr_t)&(inst->sound_hi), samples);
|
||||||
|
|
||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
@@ -371,4 +372,4 @@ struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos){
|
|||||||
//
|
//
|
||||||
|
|
||||||
return ctl;
|
return ctl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#include "load_audio_data.h"
|
#include "load_audio_data.h"
|
||||||
|
|
||||||
#include "decomp/tools/convUtils.h"
|
#include "decomp/tools/convUtils.h"
|
||||||
|
#include "decomp/audio/external.h"
|
||||||
#include "decomp/audio/load.h"
|
#include "decomp/audio/load.h"
|
||||||
#include "decomp/audio/load_dat.h"
|
#include "decomp/audio/load_dat.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
bool g_is_audio_initialized = false;
|
bool g_is_audio_initialized = false;
|
||||||
|
|
||||||
extern void load_audio_banks( const uint8_t *rom ) {
|
extern void load_audio_banks( const uint8_t *rom ) {
|
||||||
@@ -25,4 +28,4 @@ extern void load_audio_banks( const uint8_t *rom ) {
|
|||||||
sound_reset( 0 );
|
sound_reset( 0 );
|
||||||
|
|
||||||
g_is_audio_initialized = true;
|
g_is_audio_initialized = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#include "gl20_renderer.h"
|
#include "gl20_renderer.h"
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <OpenGL/gl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "../../src/libsm64.h"
|
#include "../../src/libsm64.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user