My Makefile for win32-gcc for a static lib creates a dll

Discussion about everything. New games, 3d math, development tips...
Post Reply
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

My Makefile for win32-gcc for a static lib creates a dll

Post by MasterGod »

Hi.
My engine is a static lib and my Makefile for win32-gcc creates a dll (that works!). Even though it works I don't want that dll so how can I make it only a static lib?

Makefile:

Code: Select all

VERSION = 0.1

# make
# This will compile NGE, create a static lib (libNGE.a), and copy it into the subdirectory lib/Linux. That's all.

# If you want NGE to be compiled as shared lib (libNGE.so.versionnumber), then run:
# make sharedlib
# make install

#List of object files
NGEOBJ = CConfigManager.o CursorController.o FontController.o Game.o GameEntity.o GameManager.o GameState.o GridSceneNode.o CIniFileReaderIrr.o CIniFileReaderStub.o CIrrKlangDevice.o CIrrKlangPlayedSound.o CIrrKlangSoundObj.o NGEReceiver.o NUSoftwareIntroSceneNode.o StateCredits.o StateIntro.o StateMenu.o StatePlay.o StateSettings.o IAudioDevice.o IConfigManager.o IIniFileReader.o nge.o NUS.o CLevelManager.o CEmptyLevelNode.o CRegionLevelNode.o CWorldLevelNode.o CZoneGroupLevelNode.o CZoneLevelNode.o Level.o NUSoftwareIntroLevel.o CNullAudioDevice.o CNullPlayedSound.o CNullSoundObj.o ISoundEmitterSceneNode.o ISoundListenerSceneNode.o CSceneNodeControllerAnimator.o IActor.o INPC.o IPlayer.o PlayerSpaceship.o IItemEntity.o

# Next variable is for additional scene nodes etc. of customized NGE versions
EXTRAOBJ =

LINKOBJ := $(NGEOBJ) $(EXTRAOBJ)

###############
#Compiler flags
CXXINCS = -I../include -IIrrlicht -IirrKlang
CPPFLAGS = $(CXXINCS) -DIRRLICHT_EXPORTS=1
CXXFLAGS = -Wall
ifndef NDEBUG
CXXFLAGS += -g -D_DEBUG
else
CXXFLAGS += -fexpensive-optimizations -O3
endif
ifdef PROFILE
CXXFLAGS += -pg
endif
CFLAGS := -fexpensive-optimizations -O3 -DPNG_NO_MMX_CODE -DPNG_NO_MNG_FEATURES

#Linux specific options
STATIC_LIB = libNGE.a
SHARED_LIB = libNGE.so

NGE_DLL := ../bin/Win32-gcc/NGE.dll
LIB_PATH = ../lib/$(SYSTEM)
INSTALL_DIR = /usr/local/lib
staticlib sharedlib install: SYSTEM = Linux
staticlib sharedlib : LDFLAGS = --no-export-all-symbols --add-stdcall-alias
sharedlib : LDFLAGS += -L/usr/X11R6/lib -lGL -lXxf86vm -L../lib/Linux ../lib/Linux/libIrrKlang.so
staticlib sharedlib : CXXINCS += -I/usr/X11R6/include

#Windows specific options
sharedlib_win32 staticlib_win32: SYSTEM = Win32-gcc
sharedlib_win32: LDFLAGS = -lgdi32 -L../lib/Win32-gcc -lirrlicht -lirrKlang
sharedlib_win32 staticlib_win32: CPPFLAGS += -DIRR_COMPILE_WITH_DX9_DEV_PACK -D__GNUWIN32__ -D_WIN32 -DWIN32 -D_WINDOWS -D_MBCS -D_USRDLL
staticlib_win32: CPPFLAGS += -D_IRR_STATIC_LIB_

####################
# All target, builds NGE as static lib (libNGE.a) and copies it into /lib/Linux
all linux: staticlib

# Builds NGE as shared lib (libNGE.so.versionNumber) and copies it into /lib/Linux
sharedlib: $(LINKOBJ)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared -Wl,-soname,$(SHARED_LIB).1 -fPIC -o $(SHARED_LIB).$(VERSION) $^ $(LDFLAGS)
	cp $(SHARED_LIB).$(VERSION) $(LIB_PATH)

# Builds NGE as static lib (libNGE.a)
$(STATIC_LIB): $(LINKOBJ)
	$(AR) rs $@ $^

# Copies static lib into /lib/Linux
staticlib: $(STATIC_LIB)
	cp $^ $(LIB_PATH)

# Builds NGE as dll (NGE.dll) into ../bin/Win32-gcc
all_win32 win32: sharedlib_win32
sharedlib_win32: $(NGE_DLL)
../bin/Win32-gcc/NGE.dll: $(LINKOBJ)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared -o $@ $^ $(LDFLAGS) -Wl,--out-implib,../lib/Win32-gcc/$(STATIC_LIB)
# Copies static lib into /lib/Win32-gcc
staticlib_win32: $(STATIC_LIB)
	cp $^ $(LIB_PATH)

# Installs NGE if it was created as shared lib
install:
	cp $(LIB_PATH)/$(SHARED_LIB).$(VERSION) $(INSTALL_DIR)
	cd $(INSTALL_DIR) && ln -s libNGE.so.$(VERSION) $(SHARED_LIB)
	ldconfig -n $(INSTALL_DIR)

# Create dependency files for automatic recompilation
%.d:%.cpp
	$(CXX) $(CPPFLAGS) -MM -MF $@ $<

-include $(LINKOBJ:.o=.d)

help:
	@echo "Available targets for NGE"
	@echo " sharedlib: Build shared library NGE.so for Linux"
	@echo " staticlib: Build static library NGE.a for Linux"
	@echo " install: Copy shared library to /usr/lib"
	@echo ""
	@echo " sharedlib_win32: Build shared library NGE.dll for Windows"
	@echo " staticlib_win32: Build static library NGE.a for Windows"
	@echo ""
	@echo " clean: Clean up directory"

# Cleans all temporary files and compilation results.
clean:
	$(RM) $(LINKOBJ) $(SHARED_LIB).$(VERSION) $(STATIC_LIB) $(LINKOBJ:.o=.d)

.PHONY: all sharedlib staticlib sharedlib_win32 staticlib_win32 help install clean
Thanks.

P.S
randomMesh created that Makefile.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
rooly
Posts: 224
Joined: Tue Oct 25, 2005 4:32 pm
Location: Louisiana, USA, backwater country
Contact:

Post by rooly »

there's never any command to create a static lib file.

where it says NGE_DLL:= ...
add an extra variable that += on the dll path, the file extension
so instead of

Code: Select all

NGE_DLL := ../bin/Win32-gcc/NGE.dll
use

Code: Select all

NGE_DLL := ../bin/Win32-gcc/NGE.
NGE_DLL_EXT = .dll
NGE_STA_EXT = "whatever"
and add this variable to the back of the correct compile spots
i guess...i'm not to familiar with windows makefile build systems
When banks compete, you win.
When ISPs compete, you win.
When electronics retailers compete, you win.
When governments compete...you get drafted.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, since the makefile is just a rewrite of Irrlicht's, the usual 'make staticlib' should work.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

hybrid wrote:Well, since the makefile is just a rewrite of Irrlicht's, the usual 'make staticlib' should work.
I tried: mingw32-make NDEBUG=1 all_win32 staticlib
and I get:

Code: Select all

ar: creating libNGE.a
cp libNGE.a ../lib/Linux
process_begin: CreateProcess(NULL, cp libNGE.a ../lib/Linux, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make: *** [staticlib] Error 2

C:\nge\source>
And I still get a dll AND a libNGE.a file.

@rooly: "and add this variable to the back of the correct compile spots" - and where is that exactly :wink: :?:
And you mean this variable yes? NGE_STA_EXT.
And what about the `= "whatever" `?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Oh, I guess you should use staticlib_win32. Also use it as the only target after a clean. Also, your makefile environment should provide a cp command, as it is required for make.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

Just to note, to get rid of the "cannot find the file specified", save this

Code: Select all

set cppatha1=%1
set cppathb1=%2

set cppatha2=%cppatha1:/=\%
set cppathb2=%cppathb1:/=\%

copy %cppatha2% %cppathb2%
as a bat file called "cp.bat" in the windows directory, to provide an equivalent to the unix cp command.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Thanks but I did this:

clean_tmp_files.bat

Code: Select all

del *.a /Q
del *.o /Q
del *.d /Q
del *.user /Q
del *.ncb /Q
del *.suo /Q
mingw32_build_debug.bat

Code: Select all

mingw32-make all_win32
del ..\bin\Win32-gcc\NGE.dll /Q
clean_tmp_files
mingw32_build_release.bat

Code: Select all

mingw32-make NDEBUG=1 all_win32
del ..\bin\Win32-gcc\NGE.dll /Q
clean_tmp_files
And I also realize why everything happens.
when I do all_win32 it makes the staticlib config as well as dynamic lib config. Now what hybrid suggested is to compile using only the static lib config (which is right). I just don't really care about it anymore and because maybe in the future I would make it also as a DLL I don't care letting it says this way.

But thanks anyways!
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

well, it was more for the benefit of anyone else who stumbled across this problem. I guessed you would have solved it by now ;)
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Cool, Thanks anyways!
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Post Reply