build: lib target now builds a shared library.
A new 'LIBRARY' variable also causes the libraries to be installed along the headers and a newly introduced pkg-config file.
- Makefile (DEFAULT) [LIBRARY]: Add lib to it. (CFLAGS): Add -fPIC. (PKGCONF_DIR, LIBS, PKGCONF_FILE): New variables. (lib): Express target via LIBS; add $(PKGCONF_FILE). (install) [LIBRARY]: Conditionally add lib and pkgconf targets, as well as associated recipes. ($(LIBDIR)/libsameboy.so, PKGCONF_FILE, pkgconf): New targets. (.PHONY): Register pkgconf.
- README.md: Update doc.
- sameboy.pc.in: New file.
I've used this successfully to build bsnes-jg (with a PR of its own to support that coming).
See https://gitlab.com/jgemu/bsnes/-/merge_requests/429 for an example of how this can be used.
@LIJI32 Something this would require is caring about the API stability in the future and updating versioned libraries accordingly, I'm not sure your feelings on that.
Personally I would like better handling of the sameboy library, but only if you are also committed to the idea.
I've been gradually and intentionally stabilizing the API slowly the last few years, which is why libsameboy was introduced in the last major. The upcoming major release will finalize the API stabilization.
Here's what the latest revision produces on my side:
$ make -j$(nproc) CC=gcc NATIVE_CC=gcc FREEDESKTOP=1 LIBRARY=shared install PREFIX=$PWD/install
[...]
$ find install/
install/
install/share
install/share/sameboy
install/share/sameboy/Shaders
install/share/sameboy/Shaders/AAOmniScaleLegacy.fsh
install/share/sameboy/Shaders/AAScale2x.fsh
install/share/sameboy/Shaders/AAScale4x.fsh
install/share/sameboy/Shaders/Bilinear.fsh
install/share/sameboy/Shaders/CRT.fsh
install/share/sameboy/Shaders/FlatCRT.fsh
install/share/sameboy/Shaders/HQ2x.fsh
install/share/sameboy/Shaders/LCD.fsh
install/share/sameboy/Shaders/MasterShader.fsh
install/share/sameboy/Shaders/MonoLCD.fsh
install/share/sameboy/Shaders/NearestNeighbor.fsh
install/share/sameboy/Shaders/OmniScale.fsh
install/share/sameboy/Shaders/OmniScaleLegacy.fsh
install/share/sameboy/Shaders/Scale2x.fsh
install/share/sameboy/Shaders/Scale4x.fsh
install/share/sameboy/Shaders/SmoothBilinear.fsh
install/share/sameboy/Palettes
install/share/sameboy/Palettes/Canyon.sbp
install/share/sameboy/Palettes/Desert.sbp
install/share/sameboy/Palettes/Evening.sbp
install/share/sameboy/Palettes/Fog.sbp
install/share/sameboy/Palettes/Green Slate.sbp
install/share/sameboy/Palettes/Green Tea.sbp
install/share/sameboy/Palettes/Lavender.sbp
install/share/sameboy/Palettes/Magic Eggplant.sbp
install/share/sameboy/Palettes/Mystic Blue.sbp
install/share/sameboy/Palettes/Pink Pop.sbp
install/share/sameboy/Palettes/Radioactive Pea.sbp
install/share/sameboy/Palettes/Rose.sbp
install/share/sameboy/Palettes/Seaweed.sbp
install/share/sameboy/Palettes/Twilight.sbp
install/share/sameboy/registers.sym
install/share/sameboy/background.bmp
install/share/sameboy/LICENSE
install/share/sameboy/dmg_boot.bin
install/share/sameboy/cgb_boot.bin
install/share/sameboy/sgb_boot.bin
install/share/sameboy/mgb_boot.bin
install/share/sameboy/cgb0_boot.bin
install/share/sameboy/agb_boot.bin
install/share/sameboy/sgb2_boot.bin
install/share/thumbnailers
install/share/thumbnailers/sameboy.thumbnailer
install/bin
install/bin/sameboy
install/bin/sameboy-thumbnailer
install/lib
install/lib/pkgconfig
install/lib/pkgconfig/sameboy.pc
install/lib/libsameboy.so.0.0.0
install/lib/libsameboy.so.0
install/lib/libsameboy.so
install/lib/libsameboy.la
install/include
install/include/sameboy
install/include/sameboy/apu.h
install/include/sameboy/camera.h
install/include/sameboy/cheat_search.h
install/include/sameboy/cheats.h
install/include/sameboy/debugger.h
install/include/sameboy/defs.h
install/include/sameboy/display.h
install/include/sameboy/gb.h
install/include/sameboy/joypad.h
install/include/sameboy/mbc.h
install/include/sameboy/memory.h
install/include/sameboy/model.h
install/include/sameboy/printer.h
install/include/sameboy/random.h
install/include/sameboy/rewind.h
install/include/sameboy/rumble.h
install/include/sameboy/save_state.h
install/include/sameboy/sgb.h
install/include/sameboy/sm83_cpu.h
install/include/sameboy/symbol_hash.h
install/include/sameboy/timing.h
install/include/sameboy/workboy.h
If I use LIBRARY=static, I get the .a instead of the .so, if I use LIBRARY=1, I get both.
I added so/dylib/dll output support in my last commits, since I'm not a fan of having libtool as a dependency. This enables Windows support for make lib, but only for dynamic libraries (I've been told static libraries on Windows aren't really portable because due to how libc works on Windows).
Meanwhile there's a work-in-progress wiki documenting the exported APIs.
Are there specific things from this PR that could be integrated to better support integration of SameBoy as a library?
The only things I can see that would make it better would be:
- having a lib install target
- shipping a pkg-config file for easier consumption (though this is not bound to having a dynamic library)
- abstracting prefix path
- common build systems provide extra variables to overwrite e.g. $DATADIR which would default to
$(PREFIX)/share, or others such as:LIBDIR,BINDIR - not really a big deal and 99% of people will survive without this, just very useful for those other 1% without making the the build logic any more complex
- common build systems provide extra variables to overwrite e.g. $DATADIR which would default to
Yay! I'm glad about the outcome :-). Thanks everyone!