|
| 1 | +#--------------------------------------------------------------------------------- |
| 2 | +.SUFFIXES: |
| 3 | +#--------------------------------------------------------------------------------- |
| 4 | + |
| 5 | +ifeq ($(strip $(DEVKITPRO)),) |
| 6 | +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro") |
| 7 | +endif |
| 8 | + |
| 9 | +include $(DEVKITPRO)/libnx/switch_rules |
| 10 | + |
| 11 | +export GLAD_MAJOR := 0 |
| 12 | +export GLAD_MINOR := 1 |
| 13 | +export GLAD_PATCH := 27 |
| 14 | + |
| 15 | + |
| 16 | +VERSION := $(GLAD_MAJOR).$(GLAD_MINOR).$(GLAD_PATCH) |
| 17 | + |
| 18 | +#--------------------------------------------------------------------------------- |
| 19 | +# TARGET is the name of the output |
| 20 | +# BUILD is the directory where object files & intermediate files will be placed |
| 21 | +# SOURCES is a list of directories containing source code |
| 22 | +# DATA is a list of directories containing data files |
| 23 | +# INCLUDES is a list of directories containing header files |
| 24 | +#--------------------------------------------------------------------------------- |
| 25 | +TARGET := glad |
| 26 | +#BUILD := build |
| 27 | +SOURCES := source |
| 28 | +DATA := data |
| 29 | +INCLUDES := include |
| 30 | + |
| 31 | +#--------------------------------------------------------------------------------- |
| 32 | +# options for code generation |
| 33 | +#--------------------------------------------------------------------------------- |
| 34 | +ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec |
| 35 | + |
| 36 | +CFLAGS := -g -Wall -Werror \ |
| 37 | + -ffunction-sections \ |
| 38 | + -fdata-sections \ |
| 39 | + $(ARCH) \ |
| 40 | + $(BUILD_CFLAGS) |
| 41 | + |
| 42 | +CFLAGS += $(INCLUDE) -D__SWITCH__ |
| 43 | + |
| 44 | +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 |
| 45 | + |
| 46 | +ASFLAGS := -g $(ARCH) |
| 47 | + |
| 48 | +#--------------------------------------------------------------------------------- |
| 49 | +# list of directories containing libraries, this must be the top level containing |
| 50 | +# include and lib |
| 51 | +#--------------------------------------------------------------------------------- |
| 52 | +LIBDIRS := $(LIBNX) $(PORTLIBS) |
| 53 | + |
| 54 | +#--------------------------------------------------------------------------------- |
| 55 | +# no real need to edit anything past this point unless you need to add additional |
| 56 | +# rules for different file extensions |
| 57 | +#--------------------------------------------------------------------------------- |
| 58 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 59 | +#--------------------------------------------------------------------------------- |
| 60 | + |
| 61 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 62 | + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 63 | + |
| 64 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 65 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 66 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 67 | +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 68 | + |
| 69 | +#--------------------------------------------------------------------------------- |
| 70 | +# use CXX for linking C++ projects, CC for standard C |
| 71 | +#--------------------------------------------------------------------------------- |
| 72 | +ifeq ($(strip $(CPPFILES)),) |
| 73 | +#--------------------------------------------------------------------------------- |
| 74 | + export LD := $(CC) |
| 75 | +#--------------------------------------------------------------------------------- |
| 76 | +else |
| 77 | +#--------------------------------------------------------------------------------- |
| 78 | + export LD := $(CXX) |
| 79 | +#--------------------------------------------------------------------------------- |
| 80 | +endif |
| 81 | +#--------------------------------------------------------------------------------- |
| 82 | + |
| 83 | +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) |
| 84 | +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) |
| 85 | +export OFILES := $(OFILES_BIN) $(OFILES_SRC) |
| 86 | +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) |
| 87 | + |
| 88 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 89 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 90 | + -I. |
| 91 | + |
| 92 | +.PHONY: clean all |
| 93 | + |
| 94 | +#--------------------------------------------------------------------------------- |
| 95 | +all: lib/libglad.a lib/pkgconfig/libglad.pc |
| 96 | + |
| 97 | +dist-bin: all |
| 98 | + @tar --exclude=*~ -cjf switch-glad-$(VERSION).tar.bz2 include lib |
| 99 | + |
| 100 | +dist-src: |
| 101 | + @tar --exclude=*~ -cjf switch-glad-src-$(VERSION).tar.bz2 include source Makefile libglad.pc |
| 102 | + |
| 103 | +dist: dist-src dist-bin |
| 104 | + |
| 105 | +install: dist-bin |
| 106 | + mkdir -p $(DESTDIR)$(PORTLIBS) |
| 107 | + bzip2 -cd switch-glad-$(VERSION).tar.bz2 | tar -xf - -C $(DESTDIR)$(PORTLIBS) |
| 108 | + |
| 109 | +lib: |
| 110 | + @[ -d $@ ] || mkdir -p $@ |
| 111 | + |
| 112 | +release: |
| 113 | + @[ -d $@ ] || mkdir -p $@ |
| 114 | + |
| 115 | +lib/libglad.a : lib release $(SOURCES) $(INCLUDES) |
| 116 | + @$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \ |
| 117 | + BUILD_CFLAGS="-DNDEBUG=1 -O2" \ |
| 118 | + DEPSDIR=$(CURDIR)/release \ |
| 119 | + --no-print-directory -C release \ |
| 120 | + -f $(CURDIR)/Makefile |
| 121 | + |
| 122 | +lib/pkgconfig/libglad.pc: |
| 123 | + mkdir -p lib/pkgconfig |
| 124 | + cp libglad.pc $@ |
| 125 | + |
| 126 | +#--------------------------------------------------------------------------------- |
| 127 | +clean: |
| 128 | + @echo clean ... |
| 129 | + @rm -fr release lib |
| 130 | + |
| 131 | +#--------------------------------------------------------------------------------- |
| 132 | +else |
| 133 | + |
| 134 | +DEPENDS := $(OFILES:.o=.d) |
| 135 | + |
| 136 | +#--------------------------------------------------------------------------------- |
| 137 | +# main targets |
| 138 | +#--------------------------------------------------------------------------------- |
| 139 | +$(OUTPUT) : $(OFILES) |
| 140 | + |
| 141 | +$(OFILES_SRC) : $(HFILES) |
| 142 | + |
| 143 | +#--------------------------------------------------------------------------------- |
| 144 | +%_bin.h %.bin.o : %.bin |
| 145 | +#--------------------------------------------------------------------------------- |
| 146 | + @echo $(notdir $<) |
| 147 | + @$(bin2o) |
| 148 | + |
| 149 | + |
| 150 | +-include $(DEPENDS) |
| 151 | + |
| 152 | +#--------------------------------------------------------------------------------------- |
| 153 | +endif |
| 154 | +#--------------------------------------------------------------------------------------- |
0 commit comments