summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/Makefile
blob: 8ef5667e24ef09ff22b40c04d438389e81ee5485 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
 #******************************************************************************
 #
 #    mdk-stage1 - the program that will load second-stage install
 #
 # $Id$
 #
 # Pixel (pixel@mandriva.com) (mostly done by Guillaume Cottenceau)
 #
 # Copyright 2000-2004 Mandriva
 #
 # This software may be freely redistributed under the terms of the GNU
 # public license.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

VERSION=1.37.1
PRODUCT=drakx-installer-binaries

 #
 # Portions from Erik Troan (ewt@redhat.com) Copyright 1996 Red Hat Software 
 #
 #*****************************************************************************
 #
 # Currently:
 #
 # 	ix86
 # init with dietlibc
 # stage1 with dietlibc
 #
 # 	ppc
 # init with dietlibc
 # stage1 with glibc
 #
 # 	ia64
 # init with glibc
 # stage1 with glibc
 #
 #	x86-64
 # init with dietlibc
 # stage1 with dietlibc
 #
 #*****************************************************************************


top_dir = .

include $(top_dir)/Makefile.common
include $(top_dir)/../Makefile.config
ARCHDIR=$(ARCH)
ifeq (i386, $(ARCH))
ARCHDIR=i586
endif

DEFS = -DDISTRIB_NAME=\"$(DISTRIB_NAME)\" -DDISTRIB_VERSION=\"$(DISTRIB_VERSION)\" -DDISTRIB_TYPE=\"$(DISTRIB_TYPE)\" -DDISTRIB_DESCR=\"$(DISTRIB_DESCR)\" $(ADDITIONAL_DEFS) -D_FILE_OFFSET_BITS=64 -DARCH=\"$(ARCHDIR)\" -DCONFIG_USE_ZLIB

COMPILE = $(CC) $(DEFS) $(CFLAGS)

INIT_DEFS =
INITSRC = init.c
ifneq (DIETLIBC, $(L))
INIT_DEFS += $(GLIBC_INCLUDES)
endif

INITOBJS = $(subst .c,.o,$(INITSRC))


 #- frontends
NEWT_FRONTEND_SRC = newt-frontend.c
NEWT_FRONTEND_LIBS = newt/libnewt.a slang/libslang.a

STDIO_FRONTEND_SRC = stdio-frontend.c
STDIO_FRONTEND_LIBS =
STDIO_FRONTEND_LIBS =


FRONTEND_OBJS = $(subst .c,.o,$($(F)_FRONTEND_SRC))

FRONTEND_LINK = $(FRONTEND_OBJS) $($(F)_FRONTEND_LIBS)

STAGE1_STATIC_LIBS = libmodprobe.a
STAGE1_STATIC_USR_LIBS = libz.a libldetect.a libpci.a
STAGE1_OWN_LIBS =
ifeq (DIETLIBC, $(L))
STAGE1_OWN_LIBS = $(patsubst %,/usr/lib/dietlibc/lib-$(ARCH)/%,$(STAGE1_STATIC_USR_LIBS) $(STAGE1_STATIC_LIBS))
else
STAGE1_OWN_LIBS = $(patsubst %,/usr/$(LIB)/%,$(STAGE1_STATIC_USR_LIBS)) $(patsubst %,/$(LIB)/%,$(STAGE1_STATIC_LIBS))
endif


ifeq (DIETLIBC, $(L))
STAGE1_NETWORK_LIBS = /usr/lib/dietlibc/lib-$(ARCH)/librpc.a
else
STAGE1_NETWORK_LIBS = /usr/$(LIB)/libresolv.a
endif

 #- stage1 itself
STAGE1SRC = stage1.c log.c utils.c params.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c lomount.c thirdparty.c zlibsupport.c
CDROMSRC = cdrom.c
DISKSRC = disk.c directory.c partition.c
NETWORKSRC = network.c nfsmount.c dhcp.c url.c dns.c adsl.c directory.c wireless.c
KASRC = ka.c

# use sort to remove duplicates
STAGE1_ALLSRC = $(sort $(STAGE1SRC) $(CDROMSRC) $(DISKSRC) $(NETWORKSRC) $(KASRC))
ALLSRC = $(INITSRC) $(STAGE1_ALLSRC)



CDROM_DEFS = -DSPAWN_SHELL -DDISABLE_DISK -DDISABLE_NETWORK


STAGE1OBJS-NETWORK = $(subst .c,-NETWORK.o,$(STAGE1SRC) $(NETWORKSRC))

NETWORK_DEFS = -DSPAWN_SHELL -DDISABLE_CDROM -DDISABLE_DISK -DDISABLE_KA


STAGE1OBJS-NETWORK-STANDALONE = $(subst .c,-NETWORK-STANDALONE.o,$(STAGE1SRC) $(NETWORKSRC))

NETWORK_STANDALONE_DEFS = -DDISABLE_CDROM -DDISABLE_DISK -DENABLE_NETWORK_STANDALONE -DDISABLE_KA


STAGE1OBJS-FULL = $(subst .c,-FULL.o,$(STAGE1_ALLSRC))

BINS = init stage1 dhcp-client rescue-gui probe-modules

DIRS += pci-resource usb-resource slang newt ppp/pppd rp-pppoe/src
ifeq (i386, $(ARCH))
DIRS += pcmcia pcmcia-resource sysfs
endif
ifeq (x86_64, $(ARCH))
DIRS += pcmcia pcmcia-resource sysfs
endif


ifeq (i386,$(ARCH))
PCMCIA_LIB = pcmcia/libpcmcia.a sysfs/libsysfs.a
PCMCIA_DEFS = -DENABLE_PCMCIA
endif
ifeq (x86_64,$(ARCH))
PCMCIA_LIB = pcmcia/libpcmcia.a sysfs/libsysfs.a
PCMCIA_DEFS = -DENABLE_PCMCIA
endif


USB_DEFS_GEN = -DENABLE_USB
USB_DEFS = -DENABLE_USB -DDISABLE_PCIADAPTERS

all: dirs $(BINS)

dirs:
	@for n in . $(DIRS); do \
		[ "$$n" = "." ] || make -C $$n || exit 1 ;\
	done

init: $(INITOBJS) $(STAGE1_LIBC)
	$(DIET) $(CC) $(LDFLAGS) -o $@ $^
	$(STRIPCMD) $@

stage1: $(STAGE1OBJS-FULL) $(STAGE1_OWN_LIBS) $(STAGE1_NETWORK_LIBS) $(FRONTEND_LINK) bootsplash.o $(PCMCIA_LIB) $(STAGE1_LIBC)
	$(DIET) $(CC) $(LDFLAGS) -o $@ $^
	$(STRIPCMD) $@

dhcp-client: $(STAGE1OBJS-NETWORK-STANDALONE) $(STAGE1_OWN_LIBS) $(STAGE1_NETWORK_LIBS) $(FRONTEND_LINK) $(STAGE1_LIBC)
	$(DIET) $(CC) $(LDFLAGS) -o $@ $^
	$(STRIPCMD) $@


$(INITOBJS): %.o: %.c
	$(COMPILE) $(INIT_DEFS) -c $<

$(STAGE1OBJS-NETWORK): %-NETWORK.o: %.c
	$(DIET) $(COMPILE) $(INCLUDES) $(NETWORK_DEFS) $(PCMCIA_DEFS) $(USB_DEFS_GEN) -DENABLE_ADDITIONAL_MODULES -c $< -o $@

$(STAGE1OBJS-NETWORK-STANDALONE): %-NETWORK-STANDALONE.o: %.c
	$(DIET) $(COMPILE) $(INCLUDES) $(NETWORK_STANDALONE_DEFS) $(USB_DEFS_GEN) -c $< -o $@

$(STAGE1OBJS-FULL): %-FULL.o: %.c
	$(DIET) $(COMPILE) $(INCLUDES) -DSPAWN_SHELL $(USB_DEFS_GEN) $(PCMCIA_DEFS) -DENABLE_BOOTSPLASH -c $< -o $@

.c.o:
	$(DIET) $(COMPILE) $(INCLUDES) -DENABLE_BOOTSPLASH -c $<


clean: localclean
	@for n in $(DIRS); do \
		(cd $$n; make clean) \
	done

localclean:
	rm -f *.o .depend *.rdz *.img $(BINS)


rescue-gui: rescue-gui.o frontend-common.o params.o utils.o log.o automatic.o $(FRONTEND_LINK) $(STAGE1_LIBC)
	$(DIET) $(CC) $(LDFLAGS) -o $@ $^
	$(STRIPCMD) $@

probe-modules: probe-modules.o probing-FULL.o modules-FULL.o params-FULL.o utils-FULL.o log-FULL.o automatic-FULL.o frontend-common-FULL.o stdio-frontend.o zlibsupport-FULL.o $(STAGE1_OWN_LIBS) $(PCMCIA_LIB) $(STAGE1_LIBC)
	$(DIET) $(CC) $(LDFLAGS) -o $@ $^
	$(STRIPCMD) $@

dist: tar
tar:
	rm -rf $(PRODUCT)*.tar* $(PRODUCT)-$(VERSION)
	@if [ -e ".svn" ]; then \
	    $(MAKE) dist-svn; \
	    elif [ -e "../.git" ]; then \
	    $(MAKE) dist-git; \
	    else \
	    echo "Unknown SCM (not SVN nor GIT)";\
	    exit 1; \
	    fi;
	$(info $(NAME)-$(VERSION).tar.bz2 is ready)

dist-svn:
	mkdir -p $(PRODUCT)-$(VERSION)
	svn export -q -rBASE . $(PRODUCT)-$(VERSION)/mdk-stage1
	svn export -q -rBASE ../kernel $(PRODUCT)-$(VERSION)/kernel
	cp ../Makefile.config $(PRODUCT)-$(VERSION)/
	tar cfj $(PRODUCT)-$(VERSION).tar.bz2 $(PRODUCT)-$(VERSION)
	rm -rf $(PRODUCT)-$(VERSION)

dist-git:
	@cd ..; git archive --prefix=$(PRODUCT)-$(VERSION)/ HEAD mdk-stage1 kernel Makefile.config | bzip2 >mdk-stage1/$(PRODUCT)-$(VERSION).tar.bz2;

.depend:
	$(CPP) $(CFLAGS) -M $(ALLSRC) > .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif


*-NETWORK.o: %-NETWORK.o: %.o

*-FULL.o: %-FULL.o: %.o

, formEvent, newtFormDestroy, formPlace, newtDefaultMappedHandler, } ; static inline int componentFits(newtComponent co, int compNum) { struct form * form = co->data; struct element * el = form->elements + compNum; if ((co->top + form->vertOffset) > el->top) return 0; if ((co->top + form->vertOffset + co->height) < (el->top + el->co->height)) return 0; return 1; } newtComponent newtForm(newtComponent vertBar, void * help, int flags) { newtComponent co; struct form * form; co = malloc(sizeof(*co)); form = malloc(sizeof(*form)); co->data = form; co->width = 0; co->height = 0; co->top = -1; co->left = -1; co->isMapped = 0; co->takesFocus = 0; /* we may have 0 components */ co->ops = &formOps; form->help = help; form->flags = flags; form->numCompsAlloced = 5; form->numComps = 0; form->currComp = -1; form->vertOffset = 0; form->fixedHeight = 0; form->numRows = 0; form->numFds = 0; form->maxFd = 0; form->fds = NULL; form->beenSet = 0; form->elements = malloc(sizeof(*(form->elements)) * form->numCompsAlloced); form->background = COLORSET_WINDOW; form->hotKeys = malloc(sizeof(int)); form->numHotKeys = 0; form->timer = 0; form->lastTimeout.tv_sec = form->lastTimeout.tv_usec = 0; if (!(form->flags & NEWT_FLAG_NOF12)) { newtFormAddHotKey(co, NEWT_KEY_F12); } if (vertBar) form->vertBar = vertBar; else form->vertBar = NULL; form->helpTag = help; form->helpCb = helpCallback; return co; } newtComponent newtFormGetCurrent(newtComponent co) { struct form * form = co->data; return form->elements[form->currComp].co; } void newtFormSetCurrent(newtComponent co, newtComponent subco) { struct form * form = co->data; int i, new; for (i = 0; i < form->numComps; i++) { if (form->elements[i].co == subco) break; } if (form->elements[i].co != subco) return; new = i; if (co->isMapped && !componentFits(co, new)) { gotoComponent(form, -1); form->vertOffset = form->elements[new].top - co->top - 1; if (form->vertOffset > (form->numRows - co->height)) form->vertOffset = form->numRows - co->height; } gotoComponent(form, new); } void newtFormSetTimer(newtComponent co, int millisecs) { struct form * form = co->data; form->timer = millisecs; form->lastTimeout.tv_usec = 0; form->lastTimeout.tv_sec = 0; } void newtFormSetHeight(newtComponent co, int height) { struct form * form = co->data; form->fixedHeight = 1; co->height = height; } void newtFormSetWidth(newtComponent co, int width) { co->width = width; } void newtFormAddComponent(newtComponent co, newtComponent newco) { struct form * form = co->data; co->takesFocus = 1; if (form->numCompsAlloced == form->numComps) { form->numCompsAlloced += 5; form->elements = realloc(form->elements, sizeof(*(form->elements)) * form->numCompsAlloced); } /* we grab real values for these a bit later */ form->elements[form->numComps].left = -2; form->elements[form->numComps].top = -2; form->elements[form->numComps].co = newco; if (newco->takesFocus && form->currComp == -1) form->currComp = form->numComps; form->numComps++; } void newtFormAddComponents(newtComponent co, ...) { va_list ap; newtComponent subco; va_start(ap, co); while ((subco = va_arg(ap, newtComponent))) newtFormAddComponent(co, subco); va_end(ap); } static void formPlace(newtComponent co, int left, int top) { struct form * form = co->data; int vertDelta, horizDelta; struct element * el; int i; newtFormSetSize(co); vertDelta = top - co->top; horizDelta = left - co->left; co->top = top; co->left = left; for (i = 0, el = form->elements; i < form->numComps; i++, el++) { el->co->top += vertDelta; el->top += vertDelta; el->co->left += horizDelta; el->left += horizDelta; } } void newtDrawForm(newtComponent co) { struct form * form = co->data; struct element * el; int i; newtFormSetSize(co); SLsmg_set_color(form->background); newtClearBox(co->left, co->top, co->width, co->height); for (i = 0, el = form->elements; i < form->numComps; i++, el++) { /* the scrollbar *always* fits somewhere */ if (el->co == form->vertBar) { el->co->ops->mapped(el->co, 1); el->co->ops->draw(el->co); } else { /* only draw it if it'll fit on the screen vertically */ if (componentFits(co, i)) { el->co->top = el->top - form->vertOffset; el->co->ops->mapped(el->co, 1); el->co->ops->draw(el->co); } else { el->co->ops->mapped(el->co, 0); } } } if (form->vertBar) newtScrollbarSet(form->vertBar, form->vertOffset, form->numRows - co->height); } static struct eventResult formEvent(newtComponent co, struct event ev) { struct form * form = co->data; newtComponent subco = form->elements[form->currComp].co; int new, wrap = 0; struct eventResult er; int dir = 0, page = 0; int i, num, found; struct element * el; er.result = ER_IGNORED; if (!form->numComps) return er; subco = form->elements[form->currComp].co; switch (ev.when) { case EV_EARLY: if (ev.event == EV_KEYPRESS) { if (ev.u.key == NEWT_KEY_TAB) { er.result = ER_SWALLOWED; dir = 1; wrap = 1; } else if (ev.u.key == NEWT_KEY_UNTAB) { er.result = ER_SWALLOWED; dir = -1; wrap = 1; } } if (form->numComps) { i = form->currComp; num = 0; while (er.result == ER_IGNORED && num != form->numComps ) { er = form->elements[i].co->ops->event(form->elements[i].co, ev); num++; i++; if (i == form->numComps) i = 0; } } break; case EV_NORMAL: if (ev.event == EV_MOUSE) { found = 0; for (i = 0, el = form->elements; i < form->numComps; i++, el++) { if ((el->co->top <= ev.u.mouse.y) && (el->co->top + el->co->height > ev.u.mouse.y) && (el->co->left <= ev.u.mouse.x) && (el->co->left + el->co->width > ev.u.mouse.x)) { found = 1; if (el->co->takesFocus) { gotoComponent(form, i); subco = form->elements[form->currComp].co; } } /* If we did not find a co to send this event to, we should just swallow the event here. */ } if (!found) { er.result = ER_SWALLOWED; return er; } } er = subco->ops->event(subco, ev); switch (er.result) { case ER_NEXTCOMP: er.result = ER_SWALLOWED; dir = 1; break; case ER_EXITFORM: form->exitComp = subco; break; default: break; } break; case EV_LATE: er = subco->ops->event(subco, ev); if (er.result == ER_IGNORED) { switch (ev.u.key) { case NEWT_KEY_UP: case NEWT_KEY_LEFT: case NEWT_KEY_BKSPC: er.result = ER_SWALLOWED; dir = -1; break; case NEWT_KEY_DOWN: case NEWT_KEY_RIGHT: er.result = ER_SWALLOWED; dir = 1; break; case NEWT_KEY_PGUP: er.result = ER_SWALLOWED; dir = -1; page = 1; break; case NEWT_KEY_PGDN: er.result = ER_SWALLOWED; dir = 1; page = 1; break; } } } if (dir) { new = form->currComp; if (page) { new += dir * co->height; if (new < 0) new = 0; else if (new >= form->numComps) new = (form->numComps - 1); while (!form->elements[new].co->takesFocus) new = new - dir; } else { do { new += dir; if (wrap) { if (new < 0) new = form->numComps - 1; else if (new >= form->numComps) new = 0; } else if (new < 0 || new >= form->numComps) return er; } while (!form->elements[new].co->takesFocus); } /* make sure this component is visible */ if (!componentFits(co, new)) { gotoComponent(form, -1); if (dir < 0) { /* make the new component the first one */ form->vertOffset = form->elements[new].top - co->top; } else { /* make the new component the last one */ form->vertOffset = (form->elements[new].top + form->elements[new].co->height) - (co->top + co->height); } if (form->vertOffset < 0) form->vertOffset = 0; if (form->vertOffset > (form->numRows - co->height)) form->vertOffset = form->numRows - co->height; newtDrawForm(co); } gotoComponent(form, new); er.result = ER_SWALLOWED; } return er; } /* this also destroys all of the components on the form */ void newtFormDestroy(newtComponent co) { newtComponent subco; struct form * form = co->data; int i; /* first, destroy all of the components */ for (i = 0; i < form->numComps; i++) { subco = form->elements[i].co; if (subco->ops->destroy) { subco->ops->destroy(subco); } else { if (subco->data) free(subco->data); free(subco); } } if (form->hotKeys) free(form->hotKeys); free(form->elements); free(form); free(co); } newtComponent newtRunForm(newtComponent co) { struct newtExitStruct es; newtFormRun(co, &es); if (es.reason == NEWT_EXIT_HOTKEY) { if (es.u.key == NEWT_KEY_F12) { es.reason = NEWT_EXIT_COMPONENT; es.u.co = co; } else { return NULL; } } return es.u.co; } void newtFormAddHotKey(newtComponent co, int key) { struct form * form = co->data; form->numHotKeys++; form->hotKeys = realloc(form->hotKeys, sizeof(int) * form->numHotKeys); form->hotKeys[form->numHotKeys - 1] = key; } void newtFormSetSize(newtComponent co) { struct form * form = co->data; int delta, i; struct element * el; if (form->beenSet) return; form->beenSet = 1; if (!form->numComps) return; co->width = 0; if (!form->fixedHeight) co->height = 0; co->top = form->elements[0].co->top; co->left = form->elements[0].co->left; for (i = 0, el = form->elements; i < form->numComps; i++, el++) { if (el->co->ops == &formOps) newtFormSetSize(el->co); el->left = el->co->left; el->top = el->co->top; if (co->left > el->co->left) { delta = co->left - el->co->left; co->left -= delta; co->width += delta; } if (co->top > el->co->top) { delta = co->top - el->co->top; co->top -= delta; if (!form->fixedHeight) co->height += delta; } if ((co->left + co->width) < (el->co->left + el->co->width)) co->width = (el->co->left + el->co->width) - co->left; if (!form->fixedHeight) { if ((co->top + co->height) < (el->co->top + el->co->height)) co->height = (el->co->top + el->co->height) - co->top; } if ((el->co->top + el->co->height - co->top) > form->numRows) { form->numRows = el->co->top + el->co->height - co->top; } } } void newtFormRun(newtComponent co, struct newtExitStruct * es) { struct form * form = co->data; struct event ev; struct eventResult er; int key, i, max; int done = 0; fd_set readSet, writeSet; struct timeval nextTimeout, now, timeout; newtFormSetSize(co); /* draw all of the components */ newtDrawForm(co); if (form->currComp == -1) { gotoComponent(form, 0); } else gotoComponent(form, form->currComp); while (!done) { newtRefresh(); FD_ZERO(&readSet); FD_ZERO(&writeSet); FD_SET(0, &readSet); max = form->maxFd; for (i = 0; i < form->numFds; i++) { if (form->fds[i].flags & NEWT_FD_READ) FD_SET(form->fds[i].fd, &readSet); if (form->fds[i].flags & NEWT_FD_WRITE) FD_SET(form->fds[i].fd, &writeSet); } if (form->timer) { /* Calculate when we next need to return with a timeout. Do this inside the loop in case a callback resets the timer. */ if (!form->lastTimeout.tv_sec && !form->lastTimeout.tv_usec) gettimeofday(&form->lastTimeout, NULL); nextTimeout.tv_sec = form->lastTimeout.tv_sec + (form->timer / 1000); nextTimeout.tv_usec = form->lastTimeout.tv_usec + (form->timer % 1000) * 1000; gettimeofday(&now, 0); if (now.tv_sec > nextTimeout.tv_sec) { timeout.tv_sec = timeout.tv_usec = 0; } else if (now.tv_sec == nextTimeout.tv_sec) { timeout.tv_sec = 0; if (now.tv_usec > nextTimeout.tv_usec) timeout.tv_usec = 0; else timeout.tv_usec = nextTimeout.tv_usec - now.tv_usec; } else if (now.tv_sec < nextTimeout.tv_sec) { timeout.tv_sec = nextTimeout.tv_sec - now.tv_sec; if (now.tv_usec > nextTimeout.tv_usec) timeout.tv_sec--,