0

I'm working through a coding tutorial/book called Curious Moon. One of the assignments is to normalize and load data from a CSV file put in a Postgres table. The database name is "enceladus" and the table name is "master_plan". I was told to use make to do this. I can't figure out how to run the Makefile in PowerShell.

I installed GNUWin32 with make.exe on my Windows laptop running Windows 10. I used PowerShell to run make.exe. I did this by running notepad $profile and saved New-Item alias:make -Value 'C:\Program Files (x86)\GnuWin32\bin\make.exe' in the file. I gave it a new alias because I was getting an error message. Now when I'm calling the alias like this:

PS C:\Users\Sabrina> make

I'm getting this error:

make: *** No targets specified and no makefile found. Stop.

I wrote the Makefile in sublime and saved it as a makefile extension. It's in the same folder 'C:\Program Files (x86)\GnuWin32\bin' as make.exe and named Makefile. I tried running it as

PS C:\Users\Sabrina> make -f Makefile

and then I get the error

make: Makefile: No such file or directory

I'm not sure how to get the makefile to open and run.

This is my code in the Makefile:

DB=enceladus
BUILD=${CURDIR}/build.sql
SCRIPTS=${CURDIR}/scripts
CSV='${CURDIR}/data/master_plan.csv'
MASTER=$(SCRIPTS)/import.sql
NORMALIZE = $(SCRIPTS)/normalize.sql
all: normalize
    psql $(DB) -f $(BUILD)
master: 
    @cat $(MASTER) >> $(BUILD)
import: master 
    @echo "COPY import.master_plan FROM $(CSV) WITH DELIMITER ',' HEADER CSV;" >> $(BUILD)
normalize: import
    @cat $(NORMALIZE) >> $(BUILD)
clean:
    @rm -rf $(BUILD)
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Are you absolutely sure the name of the file is just `Makefile` (or `makefile`; case doesn't matter here)? I suspect that when you say _saved it as a makefile extension_ it added an extension to the file name like `.mk` or `.mak` or something like that. In your powershell run `dir makefile*.*` and see what it prints. – MadScientist Jan 22 '19 at 18:35
  • Nothing happens when I do it. When I press enter this is what shows up: ```PS C:\Users\Sabrina>``` – tealcoding Jan 27 '19 at 14:26
  • Sounds like indeed, the Makefile you created is not in that directory. That means that it won't work. Make looks in the directory that you're in when you run make, it doesn't look in the directory that the make executable is in. – MadScientist Jan 27 '19 at 19:14

1 Answers1

1

Makefile is in C:\Program Files (x86)\GnuWin32\bin, but you're current working directory is C:\Users\Sabrina. When running make or make -f Makefile the command is looking for a Makefile in the current working directory, not in the directory where the executable resides.

Put the Makefile into your current working directory and the problem will disappear.

Move-Item 'C:\Program Files (x86)\GnuWin32\bin\Makefile' .
make
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • wouldn't it be better to copy it? Also a `.` isn't understood by all, maybe using `.\ ` or `.\Makefile` – Robert Cotterman Jan 22 '19 at 20:49
  • How do I move the Makefile? I'm not sure if I did it right, I just copied and pasted the makefile into C:\Users\Sabrina. And then I got the error ```Move-Item : Access to the path is denied. At line:1 char:1 + Move-Item 'C:\Program Files (x86)\GnuWin32\bin\Makefile' . + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (C:\Program File...32\bin\Makefile:FileInfo) [Move-Item], Unauthorized AccessException + FullyQualifiedErrorId : MoveFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.MoveItemCommand``` – tealcoding Jan 27 '19 at 14:29
  • And then ```'cat' is not recognized as an internal or external command, operable program or batch file. make: *** [master] Error 1``` – tealcoding Jan 27 '19 at 14:30
  • @tealcoding 1st error: your user doesn't have write access to either the source or destination folder. Grant the missing permissions or run the command as a user who does have sufficient privileges. 2nd error: the Makefile uses the command `cat` somewhere, but your system doesn't have that command in any of the directories listed in the PATH environment variable. Include the path to the `cat` command in the PATH or replace `cat` with `type` in the Makefile. – Ansgar Wiechers Jan 28 '19 at 09:34