Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Help running a Makefile from within a .sh script? Post 303005280 by Scott on Monday 16th of October 2017 01:18:44 PM
Old 10-16-2017
Arghh... really doesn't help that I had a file called makefile in my directory, which make was using instead of Makefile Smilie

Code:
populateMFiles() {
#echo '.PHONY: all clean build
echo 'clean:
        rm -rf cfile.c cfile.out
build:
        gcc -g -Wall -pedantic -Wextra cfile.c -w -o cfile.out
all: clean build'
}

This does work fine, as far as I can see, so it would help to see the actual make error, not the one your script is displaying.

Saying nothing as to the rest of your code because I haven't read it, it would be slightly cleaner using cat instead of echo to print the Makefile and C file.

e.g.
Code:
populateMFiles() {
cat << EOF
clean:
        rm -rf cfile.c cfile.out
build:
        gcc -g -Wall -pedantic -Wextra cfile.c -w -o cfile.out
all: clean build
EOF
}

Code:
$ functions
populateMFiles() {
cat << EOF
clean:
	rm -rf cfile.out
build:
	gcc -g -Wall -pedantic -Wextra cfile.c -w -o cfile.out
all: clean build
EOF
}

$ cat cfile.c
int main( void ) {
  printf( "%s", "Hello world!\n" );
  return 1;
}

$ populateMFiles > Makefile

$ cat Makefile
clean:
	rm -rf cfile.out
build:
	gcc -g -Wall -pedantic -Wextra cfile.c -w -o cfile.out
all: clean build

$ make all
rm -rf cfile.out
gcc -g -Wall -pedantic -Wextra cfile.c -w -o cfile.out

$ ls cfile.out
cfile.out

$ ./cfile.out
Hello world!

Your makefile may remove the cfile.c file, so you need to run "populateCFiles" every time before you run make (as clean is the first rule), make all or make clean.
This User Gave Thanks to Scott For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

makefile sh script

Hello World ! ! ! I need libraries to use grib files. I only know the C language at the moment and I am working at the University under Red Hat 9.0. I downloaded the g2clib library (the best that I found) but I did not success to run the makefile. Here is the original file. I modified some... (4 Replies)
Discussion started by: Akeson Chihiro
4 Replies

2. Shell Programming and Scripting

embeding shell script in makefile

Hi I am new to shell scripting and makefile. I want a command's output in makefile to process further, can anyone plz suggest me a way ? I want ls -d *.dsm output in a variable and want to process it in makefile itself. It's urgent Thanks In advance (0 Replies)
Discussion started by: madhu12345
0 Replies

3. Shell Programming and Scripting

shell script in makefile

Hi, Can we execute a shell script by makefile. I mean we will write a shell script in a make file and it will be executed when we compile the C++ program using make file. (2 Replies)
Discussion started by: surjyap
2 Replies

4. Shell Programming and Scripting

Shell script makefile

Is there a way to write a makefile for all the source files in a directory with a shell script? (2 Replies)
Discussion started by: zzhan
2 Replies

5. UNIX for Dummies Questions & Answers

error while running a makefile

any good website to know about makefiles (3 Replies)
Discussion started by: raviravula
3 Replies

6. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

7. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

8. Shell Programming and Scripting

using a Shell Script in a Makefile

Hello, I have a Makefile that converts wrl (vrml) files to html files... how can I use a shell script in that makefile which works on all html files after converting? The Shell Script have to find and replace a String in every createt html file. sorry I'm a Newbie, so I hope someone can... (0 Replies)
Discussion started by: Dan_78
0 Replies

9. Shell Programming and Scripting

Need help with a script to make makefile

How do we create a shell script that creates a makefile? what if we want to use the #include header files too? (2 Replies)
Discussion started by: sslokhan
2 Replies

10. Programming

Problem running a makefile

I have written this makefile and am getting an error saying make nfd gfortran -O -Wall -fbacktrace -fno-align-commons -c -o fd.o fd.f fd.f:49: Error: Can't open included file 'fd.par' make: *** Error 1 The directory structure is as follows . ├── library │ ├── fd │ │ ├──... (3 Replies)
Discussion started by: kristinu
3 Replies
PG_BUILDEXT(1)						 Debian PostgreSQL infrastructure					    PG_BUILDEXT(1)

NAME
pg_buildext - Build and install a PostgreSQL extension SYNOPSIS
pg_buildext action srcdir target opts DESCRIPTION
pg_buildext is a script that will build a PostgreSQL extension in a VPATH way. It supports the configure, build, install, and clean actions, and will choose to build for the intersection of versions known in debian/pgversions (versions supported by the package) and in /usr/share/postgresql-common/supported-versions (versions supported in this release). OPTIONS
action One of configure, build, install, or clean. srcdir Where to find the extension sources, including the debian subdirectory. (Usually $(CURDIR).) If not specified, defaults to the current directory. target The target directory where to build the sources, it will get created for you if it does not exist. If the target contains a %v sign, it will get replaced by the specific version of PostgreSQL being built against. (Usually build-%v.) opts %v signs in opts will get replaced as in target. configure Options to pass to the configure script. (Most PostgreSQL extensions do not have a configure script.) build Custom CFLAGS options to use for the build. install Package name to install for. Make will be called with DESTDIR="srcdir/debian/package". clean clean does not take extra options. USAGE
As pg_buildext invokes make for the build, install, and clean actions, invocations from debian/rules (which is a makefile) should be prefixed with + so the sub-makes can talk with the make jobserver. EXAMPLE
build-stamp: +pg_buildext configure $(CURDIR) build-%v "--libdir=/usr/lib/postgresql/%v/lib --datadir=/usr/share/postgresql-%v-plsh" +pg_buildext build $(CURDIR) build-%v install: build +pg_buildext install $(CURDIR) build-%v postgresql-%v-plsh clean: +pg_buildext clean $(CURDIR) build-%v AUTHOR
Dimitri Fontaine <dim@tapoueh.org>, with extensions by Christoph Berg <myon@debian.org>. Debian 2012-10-08 PG_BUILDEXT(1)
All times are GMT -4. The time now is 03:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy