This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: .reloc section in EXE


On Sat, Oct 17, 1998 at 03:27:48PM -0000, Jose Vasconcellos wrote:
> Anyone know if it is possible to have the
> linker generate a .reloc section in an EXE?
> It does it with the -dll option, but I want
> to create a relocatable EXE.
> 
 Jose,
 hoping that can help, I enclose a file (I call it MkRules) with the rules 
 that I use with Mumit's egcs. Observe that I use mingw32.
 The rule for an executable automatically generate
 a .reloc section (and also export all the public symbols).
 As you can see the rules to build a relocable exe and a
 relocable dll are very similar.
 
 Use is very simple. For example, the Makefile
 ------------------------------------------------------------------
 include MkRules
 my.exe:a.o b.o
 ------------------------------------------------------------------
 build a relocable executable my.exe from a.c and b.c.
 Observe that it is possible to have special compiler flags
 for every  .c or .f file and special linker and library 
 flags for every executable (and, BTW, dll).  In this case
 you must use something like the following Makefile (look to
 the comments):
 ------------------------------------------------------------------
 include MkRules
 
 CFLAGS=-O2 #used for every .c file
 a-CFLAGS=-DaFlag #special flag for compiling a.c
 LINKERFLAGS=-s #used in building every .exe
 my-LINKFLAGS=-mwindows #used only for my.exe
 LIBS=-laLib #used for every .exe
 my-LIBS=-LaDir -lanotherLib #special library for my.exe
 
 my.exe: a.o b.o
 ------------------------------------------------------------------
 guido
 
 (ps) Some rules can be simplified (e.g. the .rc -> .o one). But I used
 this file  also for cross-compiling (just change MINGW32DIR and
 BINPREF to reflect your system) and in a cross-compiler setting
 I found necessary to use the full rules (don't ask me why).

---------------------- MkRules -----------------------------------
.SUFFIXES: .c .f .o .a  .def .exp .dll .exe 


MINGW32DIR=/egcs
BINPREF=
HEADER=$(MINGW32DIR)/i386-mingw32/include


RM=rm -f
SED=sed
ECHO=echo
CP=cp
MKDIR=mkdir
CAT=cat
CC=$(BINPREF)gcc 
F77=$(BINPREF)g77
FLIBS=-lg2c
AS=$(BINPREF)as
DLL=$(CC) -mdll   
DLLTOOL=$(BINPREF)dlltool -k --as $(AS)
LINKER=$(CC)
AR=$(BINPREF)ar
RANLIB=$(BINPREF)ranlib
NM=$(BINPREF)nm
CPP=$(CC) -E
RESCOMP=$(BINPREF)windres --preprocessor $(CPP) --include-dir $(HEADER) --define RC_INVOKED=1



.c.o:
	$(CC)  $(CFLAGS) $($*-CFLAGS) -o $@  -c $<
	
.f.o:
	$(F77) $(FFLAGS) $($*-FFLAGS) -o $@ -c $<

%.exe %.exp:  
	@$(ECHO) -------- Building $@ --------
	$(ECHO) EXPORTS > $*.exp
	$(NM) $^ | $(SED) -n "/^........ [DT] _/s/^........ [DT] _/ /p" >> $*.exp
	$(DLLTOOL) --dllname $@  --output-exp $*.e --def $*.exp
	$(LINKER)  $(LINKFLAGS) $($*-LINKFLAGS) -o $@ -Wl,--base-file,$*.b $*.e $^ $($*-LIBS) $(LIBS)
	$(DLLTOOL) --dllname $@  --base-file $*.b  --output-exp $*.e  --def $*.exp
	$(LINKER)  $(LINKFLAGS) $($*-LINKFLAGS) -o $@ $*.e $^ $($*-LIBS) $(LIBS)
	rm $*.e $*.b 


%.dll %.def:   
	@$(ECHO) ------- Building $@ --------
	$(ECHO) LIBRARY $* > $*.def
	$(ECHO) EXPORTS >> $*.def
	$(NM) $^ | $(SED) -n "/^........ [DT] _/s/^........ [BCDRT] _/ /p" >> $*.def
	$(DLL) -Wl,--base-file,$*.b $(DLLFLAGS) $($*-DLLFLAGS) -o $@  $^ $($*-DLLLIBS) $(DLLLIBS)
	$(DLLTOOL) $(DLLTOOLFLAGS) $($*-DLLTOOLFLAGS) --dllname $@  --base-file $*.b --output-exp $*.e --def $*.def
	$(DLL)  -Wl,--base-file,$*.b $(DLLFLAGS) $($*-DLLFLAGS) -o $@ $*.e $^ $($*-DLLLIBS) $(DLLLIBS)
	$(DLLTOOL) $(DLLTOOLFLAGS) $($*-DLLTOOLFLAGS) --dllname $@ --base-file $*.b --output-exp $*.e --def $*.def 
	$(DLL)  $(DLLFLAGS) $($*-DLLFLAGS) -o $@  $*.e $^ $($*-DLLLIBS) $(DLLLIBS)	     
	$(RM)  $*.b $*.e

lib%.a: %.def
	@$(ECHO) -------- Building $@ --------
	$(DLLTOOL) $(DLLTOOLFLAGS) $($*-DLLTOOLFLAGS) --dllname $*.dll --def $*.def --output-lib lib$*.a
	 
lib%.a: %.exp
	@$(ECHO) -------- Building $@  --------
	$(DLLTOOL) $(DLLTOOLFLAGS) $($*-DLLTOOLFLAGS) --dllname $*.exe --def $*.exp --output-lib lib$*.a	 
	 
%.a:    
	@$(ECHO) -------- Building $@ --------
	$(AR) cr $@ $^
	$(RANLIB) $@


%.o:    %.rc
	$(RESCOMP) $(RESFLAGS) $($*-RESFLAGS) -i $^ -o $@
-----------------------------end MkRules---------------------------------
	

 
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]